ImageEn, unit imageenproc




procedure RemoveChromaKey(KeyColorRGB: TRGB; Tolerance: double; Saturation: integer; FeatherEdges: Integer;
                          HueReduction : Integer = 0; RemoveNoise: boolean = False); overload;
procedure RemoveChromaKey(KeyPixelX, KeyPixelY: integer; Tolerance: double; Saturation: integer; FeatherEdges: Integer;
                          HueReduction : Integer = 0; RemoveNoise: boolean = False); overload;


ChromaKey is the removal of a background for a source image so it can be replaced by an alternative image.

ChromaKey Source Image

ChromaKey Image on Background

RemoveChromaKey removes the KeyColor of an image and sets it to transparent. Although KeyColor is a single color, RemoveChromaKey will remove a range of colors that are similar to cope with light variance in photography.

Parameter Description
KeyColorRGB (Overload 1) A typical color within the Chromakey background, e.g. as returned by GuessChromaKeyColor or CalcAverageRGB
KeyPixelX, KeyPixelY (Overload 2) A pixel within the Chromakey background to be used as the key color. If both are set to -1 then GuessChromaKeyColor is used to guess the key color
Tolerance The level of tolerance when seeking similar colors to our key color. Range: 0.0 to 1.0. Typical value: 0.21
Saturation If a pixel is of a hue within our keycolor range, limit removal to the specified saturation. Range: 0 to 100. Typical value: 30
FeatherEdges Blurs the edge of the image to smooth the result and remove trace ChromaKey pixels (uses FeatherAlphaEdges). Typical value: 2
HueReduction Pixels of a similar hue to our key color but outside the level of tolerance will be reduced in saturation (color intensity). 0 is no hue reduction, 1 is minimal, 5 is maximum. Settings of 0, 2 or 3 are best
RemoveNoise Removes stray pixels missed by the removal

For more information on ChromaKey:

Typically ChromaKey removal is performed as follows:

1. Select a region of the background and use CalcAverageRGB to determine the Key color
2. Adjust Tolerance until foreground subject is fully visible
3. Adjust Saturation to remove any remaining background
4. If necessary, adjust FeatherEdges, HueReduction or RemoveNoise

Note: If the image PixelFormat is not one ie24RGB or ie1g, it will be converted


Demo  Demos\ImageEditing\ChromaKey\ChromaKey.dpr


// Load background
ImageEnView1.IO.LoadFromFile( sBackgroundFile );

// Load our ChromaKey (foreground) image as a foreground layer
ImageEnView1.LayersAdd( sChromaKeyFile );

// Get the average color of the selection (if the user has selected a background region) or guess the background color
if ImageEnView1.Selected then
  KeyColorRGB := ImageEnView1.Proc.CalcAverageRGB( 100 );
  KeyColorRGB := ImageEnView1.Proc.GuessChromaKeyColor();

// Remove Chromakey from foreground layer (will become transparent)
ImageEnView1.Proc.RemoveChromaKey( KeyColorRGB, 0.21, 30, 2, 0 );

// Refresh our view

See Also

- GuessChromaKeyColor
- SelectChromaKey
- CreateRGB
- TRGB2TColor
- TColor2TRGB