Log in

View Full Version : Black and White, color masking?


Mustachio
4th May 2005, 07:29
I need some help here. I am trying to convert a clip I have to black and white, with the exception of maybe one specific color. Something similar to the effect in schindlers list with the one girl with a red coat and some of those gatorade commercials.

I was looking into doing layering, and masking, using colorkeymask, but I am pretty much completely stumped. At current I have two clips, one in color and the other in grayscale.

I really just dont understand the masking and how it works how to select a color, then mask the image so only that part shows up over the black and white.

IanB
5th May 2005, 09:01
AviSource(...) # Whatever

# Change to pixel format with an Alpha channel
ConvertToRGB32()

# Save coloured version of clip
CV=Last

# Set alpha to all opaque
ResetMask()

# Make alpha transparent where colour is "interesting"
ColorKeyMask($456789, 5)

# Strip colour from clip (keep alpha channel)
BWa=Grayscale()

# Apply B/W image where alpha is opaque
# Let colour image show thru where alpha is transparent.
Layer(CV, BWa, "Add", 255)
The clip applied to ColorKeyMask() may need some heavy processing to make the "interesting" colour easily selectable.

The Overlay() verb should also be able to do this with better control but currently seems to have a bug that I will have to find and fix. So Layer() it will have to be.

IanB

Mustachio
5th May 2005, 12:49
Thank you! that was exactly what i was looking for, but one more question about colorkeymask. The number you specified for the color, what kind of format is that in? and how to choose which color responds to which number? for now, i will just randomly play with it.

Thanks again

IanB
5th May 2005, 13:21
ColorKeyMask(int Color, int Tolerance)

Color is an integer RGB value calculated by (R<<16 | G<<8 | B), individual values between 0 and 255.

Tolerance specifies the range for which close colours are considered the same.

For easy expression Hex format is used by prefixing a $ thus
$FF0000=red, $00FF00=Green & $0000FF=Blue. Take a look at colors_rgb.avsi installed in your avisynth plugin directory for a stack of predefined standard colours and some URLs for even more.


Also Mask() and ShowAlpha() can be used to insert and extract the alpha channel from a separate clip. You are probably going to need to do this. Usually very strong filtering is required to create a stable and reliable mask for what you are doing. Sometimes generating the mask as a clip, saving it and hand painting out the inevitable flecks of false elements that occur is required.

IanB

zettai
5th May 2005, 14:46
You can also do this with the filter tweakcolor which allows you to apply Tweak to hue ranges such as:

TweakColor(sat=0,startHue=0,endHue=90)
TweakColor(sat=0,startHue=130,endHue=359)

which should give you reds and skin tones. Operates in YV12 only.

Mustachio
5th May 2005, 17:09
Originally posted by IanB
Sometimes generating the mask as a clip, saving it and hand painting out the inevitable flecks of false elements that occur is required.

IanB

Yea, I was talking to my friend who I am working on these projects with, and he was the one that brought it up, but he didnt want to do it because he thought the masks would have to be all hand drawn. However, I think with your help, and zettai for TweakColor, I think I should be more than good to go in achieving what I need. Thanks guys