ColorScreenMask
Abstract | |
---|---|
Author | Grandpa Oddball |
Version | v1.0 |
Download | ColorScreenMask.zip |
Category | Masking |
License | GPLv2 |
Discussion | Doom9 Thread |
Contents |
Description
ColorScreenMask is a complement to the default ColorKeyMask filter for use in Chroma Key processing (e.g., the green screen or blue screen effect). In common with the ColorKeyMask filter, ColorScreenMask only sets the alpha channel pixels to transparent when the specified criteria are met and leaves the rest of the alpha channel pixels unchanged. It does NOT set the alpha channel to opaque (e.g., it is not set to white, that's why you might need to use ResetMask before applying this filter). This allows an aggregate mask to be constructed with multiple calls and allows you to intersperse both filters if necessary.
ColorScreenMask only operates in an RGB32 (aRGB) color space so you may need to use one of the ConvertTo and ConvertBackTo filters in order to use this plugin.
I needed a filter that allowed me to do a green screen effect in my living room without resorting to special techniques and which alleviated the need for complex and expensive lighting. ColorScreenMask does not obviate the need for good lighting but it becomes less critical especially in confined quarters.
The intent of this filter plugin is to compensate for halos, shadows, background imperfections such as wrinkles, folds or pits, and other effects of uneven lighting such as not using a tripod when using recording Chroma Key transparency backgrounds (e.g.,a green, red, or blue screen background transparency mask) that the standard ColorKeyMask filter is unable to handle effectively.
ColorScreenMask uses absolute and relative thresholds rather than absolute values as the criteria for determining whether the alpha channel should be set to transparent. It has three modes of operation: global, contiguous, and mixed.
Requirements
- [x86] AviSynth+ or AviSynth 2.5.8 or greater
- Supported color formats: RGB32
Syntax and Parameters
ColorKeyMask (clip, string "keymode", string "keycolor", int "gth", int "grm", int "ggm", int "gbm", int "contx", int "conty", int "cth", int "crm", int "cgm", int "cbm", int "pixv")
All of the input parameters are optional except clip. The usage is as follows:
keymode: keymode is a string that can have one of the following three values,
keymode=”global”
This is the fastest of the processing modes. It uses the parameters keycolor, gth, grm, ggm, gbm, and pixv. keycolor determines the screen color which will be made transparent. This mode examines each pixel and if the keycolor of that pixel is above the global color threshold (gth) and the non-keycolors are below the global relative color thresholds (grm, ggm, gbm) then the pixel become a candidate for setting the alpha channel to transparent.
In addition the adjacent pixels are examined and the number of adjacent pixels which also pass the threshold criteria are counted. If this number is greater than or equal to pixv then the pixel's alpha channel is set to transparent.
keymode=”cont”
This is the basic contiguous processing mode. The parameters contx and conty are used to find the start of the contiguous region. If the pixel at (contx,conty) satisfies the global criteria assuming pixv is zero then all pixels which are contiguous to the start pixel and which satisfies the contiguous threshold criteria have their alpha channel set to transparent.
If the start pixel (contx,conty) does not satisfy the global threshold criteria then an expanding square about the start pixel is sequentially examined until one or more pixels satisfies the global threshold criteria. These pixels are then used to find the contiguous region.
The parameter pixv is not used in this mode.
This mode is also very fast and compensates for shadows and halos very well but has one major drawback. If there are disconnected regions which are, by definition, not contiguous that should be made transparent then the contiguous mode will only detect one of these regions. A simple example is a person facing the camera with their hands on their hips. The region between the arms and the body are disconnected from each other and from any other background regions that should be made transparent.
keymode=”mixed”
This is the most useful but also the slowest mode. First the global criteria is applied to each pixel assuming pixv to be zero. The global thresholds can be quite stringent in this mode. Then the all pixels which satisfy the contiguous criteria and which are contiguous to one or more of the globally detected transparent pixels will have their alpha channels set to transparent.
The default value of keymode is ”global”.
keycolor:
This is a string which determines the Chroma Key color. It must be either ”red”,”green”, or ”blue”. No mixed colors are allowed (you have to struggle with the ColorKeyMask filter in that case). Most people use a blue or green screen background but it was trival to add red background processing so I added it.
The default of keycolor is ”green” corresponding to a green screen effect!
gth:
This is an integer which determines the global keycolor threshold value. The keycolor pixel value must be above this threshold. It must be an integer in the 0-255 range.
The default of gth is 150.
grm, ggm, gbm:
These are the global relative thresholds for the red (grm), green (ggm), and blue (gbm) channels. This threshold is ignored for the keycolor selected. The thresholds are percent values (specified as integers) which must be in the range 0-100. The individual absolute pixel threshold is computed by multiplying the percentage value (converted to a fraction) times the value of the keycolor pixel value. The non-keycolor pixel values must be below this threshold.
The default value for these parameters is 80.
contx and conty:
This is the initial starting pixel for the contiguous mode processing. The default value is (0,0).
cth:
This is the contiguous keycolor threshold value. The keycolor pixel value must be above this threshold. It must be an integer in the 0-255 range.
The default of cth is 50.
crm, cgm, cbm:
These are the contiguous relative thresholds for the red (crm), green (cgm), and blue (cbm) channels. This threshold is ignored for the keycolor selected. The thresholds are percent values must be in the range 0-100. The individual absolute pixel threshold is computed by multiplying the percentage value (converted to a fraction) times the value of the keycolor pixel value. The non-keycolor pixel values must be below this threshold.
The default value for these parameters is 80.
pixv:
This determines the number of adjacent pixels that must also satisfy the global criteria before a pixel is made transparent. This parameter is only used when keymode=”global”. pixv must be an integer in the range of greater than or equal to 0 and less than or equal to 8.
The intent of this parameter was to compensate for noise but as a practical matter I've not had a noise problem even using my inexpensive compact camera (a nikon coolpix). However I had already implemented and tested the parameter before I realized that it wasn't very useful so I left the tested code in the filter. I have never had an occasion to use anything other than the default value.
The default of pixv is 0.
Examples
For a blue screen effect using the contiguous mode you would use something like
ColorScreenMask(clip, keymode=”cont”, keycolor=”blue”)
If you wanted to have a stringent global detection criteria for a green screen but a loose contiguous criteria in mixed mode you would use something like
ColorScreenMask(clip, gth=200, cth=25, crm=90, cbm=90)
If you wanted to process a clip fast using the global criteria then you would use something like:
ColorScreenMask(clip, keymode="global")
Note: The fast global keymode is sufficient for well lit backgrounds and is still more forgiving than using the ColorKeyMask filter especially when it comes to removing shadows
Changelog
Version Date(Y/M/D) Changes
v1.0 2011/01/20 - Initial release
Archived Downloads
Version | Download | Mirror |
---|---|---|
v1.0 | ColorScreenMask.zip | ColorScreenMask.zip |
External Links
- getoddnews.com - archived homepage
Back to External Filters ←