Log in

View Full Version : ColorSwitch - a color-based pixel 'switcher'


kemuri-_9
11th December 2008, 03:53
I've finally become satisfied with my first filter which i have dubbed 'ColorSwitch'.

It has the ability to pick and choose pixels from input clips based on their color values on per pixel values.

I developed it to be able to selectively filter a frame based on its color values.

the basic formula of how it works is
there's 3 input clips 'scan', 'base', and 'replace'.
if scan's per pixel values is in any of the ranges you specify, it takes the respective pixel from replace.
if not, it takes it from base.

in this manner, passing
last, last, last.filtered()
can net you partial filtering based on the frame's colors

another option to using in the manner of
last, BlankClip(last, color=$000000), BlankClip(last, color=$FFFFFF)
can be used for mask creation based on the colors.

it supports up to 16 sets of color ranges, so you can nail down specific color conditions fairly well.

it also features an additional function for writing the per pixel data to file as well,
to assist with your color value choosings.

natural limitations to the filter are:
all clips must have the same width, height, and color space.
and no interlaced support....

available for dl here (http://kemuri9.net/dev/avs/ColorSwitch/ColorSwitch.zip)

Adub
11th December 2008, 06:01
Mind if I ask what the reason for this plugins creation was?

kemuri-_9
11th December 2008, 06:44
the original reason was for the purpose selectively applying dftest on some of my anime encodes
generally didn't like how dftest came out on black -> near black sections
so just wanted to be able to specify to apply it on sections with sufficient color.

that was possible to be pulled off with creating some masks using levels() and similar color altering functions and then overlaying with it,
but that wasn't as friendly as i would of liked.
plus there may be some point in the future where i just want to filter on some specific color ranges that generating a mask would be too annoying normally.

if you can understand that at all... :rolleyes:

Wilbert
11th December 2008, 19:32
plus there may be some point in the future where i just want to filter on some specific color ranges that generating a mask would be too annoying normally.
You mean like in MaskHS?
http://forum.doom9.org/showthread.php?p=1078651#post1078651

Adub
11th December 2008, 20:39
if you can understand that at all...
I have no problem understanding it. I was kind of thinking about doing the same thing. I will have to mess with this filter when I have more time.

kemuri-_9
11th December 2008, 21:04
You mean like in MaskHS?
http://forum.doom9.org/showthread.php?p=1078651#post1078651

if only i could DL it to see how similar it actually is,
the link in that post is dead, which is not surprising as it's nearly a year old :<

squid_80
11th December 2008, 21:28
if only i could DL it to see how similar it actually is,
the link in that post is dead, which is not surprising as it's nearly a year old :<

Meh. Wilbert already added a new link but I fixed the original anyway. The actual documentation for it is here (http://avisynth.org/mediawiki/MaskHS).

kemuri-_9
11th December 2008, 22:09
the concept for what i did is based on specific color values, not the hue/sat value ranges like maskHS

the filter i made has the capability to create masks depending on the input clips.

the filter i have processes on raw, R,G,B,A, Y,U,V value ranges when they exist in the colorspace.
so you can select pixels based on G value ranges or A value range s, a mixture of ranges, and combinations of ranges.
ranges can also have the same min/max values, so you can nail down to a specific exact overall color (i.e. RGB24: 0x000000).
it also accepts multiple (up to 16) ranges, so if you need to have several sets of distinct colors you would like to select, it can do so

so assuming i had some RGB24 source, i could select colors in the ranges of
R=0-10, B=20-30, G=40-50
or
R=60-70, G=80-90, B=100-110
on some clip

to
1A. generate a mask
1B. generate an antimask
2A. directly selectively filter on those colors
2B. directly selectively filter on ~colors (that aren't the specified ranges)

what it generates as an end result is up to the user, as it works with clips, so you can do quite a bit with it.

tin3tin
12th December 2008, 14:38
Nice for red-eye-reduction:
Get this image (http://www.bbc.co.uk/gloucestershire/content/image_galleries/techno_phobia_gallery.shtml?1).

And run this script:
loadplugin("ColorSwitch.dll")
ImageReader("red_eye_before470_470x386.jpg",0,0)
converttorgb24()
first=last
ColorSwitch(last,last,last.greyscale(),"R:1-170,G:0-70,B:0-130")
last+first