Log in

View Full Version : How to select a color and make a mask out of it?


zee944
31st July 2010, 17:02
I'd like to select the orange credits (or subitltes) as a mask in a video clip for tweaking the movie and the credits separatedly, and then add them together again.

Here's how I use masks now:

AVISource("video.avi")
mymask = ImageReader("mask.bmp")
nonmaskedpart =last.RGBadjust(0.8,1.2,1.0)
maskedpart = last.RGBadjust(1.2,0.8,1.2)
Overlay(nonmaskedpart, maskedpart, mask=mymask)

Now I know I have to modify the mymask = ImageReader("mask.bmp") line to select the orange colors ($E6640C) from the last clip as a mask. Probably it can be done with ColorKeyMask, I just can't figure out how?

And BTW, can I somehow add a threshold or feather to the selected pixels?

Any help would be appreciated. :)

Gavino
31st July 2010, 19:40
Yes, you can use ColorKeymask like this:

mymask = BlankClip(last, pixel_type="RGB32").ResetMask().ColorKeyMask($E6640C)
...
Overlay(nonmaskedpart, maskedpart, mask=ShowAlpha(mymask))

Note that since ColorKeyMask works by setting the alpha channel (of RGB32), you need to use ShowAlpha() when applying the mask in Overlay().

For feathering, apply a slight Blur() to the mask.

zee944
31st July 2010, 20:23
After with the modifications ShowAlpha(mymask) is full white. Isn't something missing?

Gavino
31st July 2010, 20:49
Whoops, sorry. I should have said:
mymask = ConvertToRGB32().ResetMask().ColorKeyMask($E6640C)
(instead of BlankClip(...))

zee944
31st July 2010, 21:53
Whoops, sorry. I should have said:
mymask = ConvertToRGB32().ResetMask().ColorKeyMask($E6640C)
(instead of BlankClip(...))

Ah, thanks Gavino, it works fine now.

Blur() is a neat trick! But what if I want an even wider feather (3-4 or more pixels) around the selected areas?

IanB
31st July 2010, 22:51
Blur() is a neat trick! But what if I want an even wider feather (3-4 or more pixels) around the selected areas?You can stack multiple Blur() calls, the effect is cumulative.

Or for more control use a pair of GaussResize() with an appropriate P setting and resize factor. Also experiment with a sharp resizer followed by Gauss and vice versa. Start with about a 25% upsize and adjust to suit your sources detail level.

zee944
1st August 2010, 11:10
You can stack multiple Blur() calls, the effect is cumulative.

Or for more control use a pair of GaussResize() with an appropriate P setting and resize factor. Also experiment with a sharp resizer followed by Gauss and vice versa. Start with about a 25% upsize and adjust to suit your sources detail level.

Thanks for the hint. It seems to me that both Blur and the GaussResize method - while creating an indeed nice threshold - unfortunately takes away from the white pixels instead of extending them.

I was browsing the filters in Paint Shop Pro when I found the Dilate filter, which "Enhance the light areas of the image". It looks like the answer for my prays. Is there anything similar in AviSynth?

zee944
1st August 2010, 11:22
I've found something:

ColorIt plugin (http://avisynth.org/vcmohan/ColorIt/ColorItSynopsis.html)

Morpher(type="dilate")

IanB
1st August 2010, 12:09
Have a look at MaskTools, there are some operators that can expand or contract a mask.

For the Blur() style, yes the edge pixels becomes 50%. You could try Levels(0, 1.0, 127, 0, 255) to re-establish the boundaries as 100%.

zee944
15th August 2010, 17:44
Have a look at MaskTools, there are some operators that can expand or contract a mask.

The dilate function of ColorIt() plugin is working exactly the way I wanted, and I create the transition feather around the edges with GaussResize(). It was interesting to learn that the resize factor bears no importance in blurring. But it works fine for my purposes. Thanks for the help.