My previous experiment with the selective color transforms made me think a bit more about creating masks from colors and its applications. I wondered if it is possible to use a similiar technique to calculate green screen or blue screen masks in realtime for Flash video. And indeed - it works.
I've programmed a keying technique similar the Color Difference Key known from AfterEffects or other video editing programs. This kind of keying allows for finer control and better transitions than for example a simple chroma key.
A very important factor for successful keying is good lighting of the fore- and background and as I don't have a studio at hand for this demo I allowed myself to use the example clip from this Macromedia Video Tutorial featuring Tom Green - I hope that's okay for this purpose. I've converted the original 20MB quicktime movie to a 1 MB FLV (wow, isn't that on2 codec great?) - and there is definitely no more alpha channel in there. Alternatively you can try to use your webcam, but if you don't have good lighting and a decent background the results will be only so-so. But I can imagine that the same technique could be used for example on still images to mount peoples' heads on avatars.
Here is the demo:
The sliders have the follwing functions:
- Preblur will blur the source before the difference, thus reducing noise and smoothing the edges of the mask
- Mask In sets the black point of the mask
- Mask Out sets the white point of the mask
- Gamma changes the transition between the transparent and opaque areas of the mask
- Postblur can be used to feather the mask's edges
- Defringing is an attempt to reduce background color bleeding at the edges - depending if your new background color is dark or bright try the different settings
Download the source files here
(Released under Creative Commons Attribution-Noncommercial 3.0)
