Friday, July 25, 2008

Color Keying in Software

Chroma keying is a technique that is used to remove a color from an image and show a different image in place of that color. In this article different quality and speed optimized techniques will be shown regarding how one can make color keying in software.


This method uses solely the hue of a color, so that its saturation and value, such as in a shadow, are not relevant. This is a method that can be both used for RGB and HSV color spaces. The basic idea is that one defines an angle in the hue circle within the HSV color space; this angle is your chromakey. For every pixel being drawn one looks up its hue value, compares it to the defined angle to determine its alpha channel value. In the case of an RGB color space, the RGB value has to be converted to HSV to do the lookup (see Transformation from RGB to HSV). It is also advised to check if the value V within the HSV color space exceeds at least 50% in order to eliminate all kinds of white, gray and black shades.


The human visual system is less sensitive to the position and motion of color than luminance; bandwidth can be optimized by storing more luminance detail than color detail. At normal viewing distances, there is no perceptible loss incurred by sampling the color detail at a lower rate. In video systems, this is achieved through the use of color difference components. The signal is divided into a luma (Y') component and two color difference components (chroma).


Chroma subsampling deviates from color science in that the luma and chroma components are formed as a weighted sum of gamma-corrected (tristimulus) R'G'B' components instead of linear (tristimulus) RGB components. As a result, luminance and color detail are not completely independent of one another. There is some "bleeding" of luminance and color information between the luma and chroma components. The error is greatest for highly-saturated colors and can be somewhat noticeable in between the magenta and green bars of a color bars test pattern (that has chroma subsampling applied). This engineering approximation (by reversing the order of operations between gamma corrections and forming the weighted sum) allows color sub sampling to be more easily implemented.

No comments: