COLOR_EXCHANGE
Syntax | Return Value | Arguments | Keywords | Examples | Version History
The COLOR_EXCHANGE procedure replaces image pixels of a given color with pixels of a new color. For multi-channel images, every image color channel must match the specified color in order for replacement to occur. Specify a threshold value to replace colors close to the specified color.
Syntax
Result = COLOR_EXCHANGE(Image, Color, ReplaceColor [, THRESHOLD=vector])
Return Value
Result is an array of the same dimensions and type as Image.
Arguments
Image
A 2D or 3D array of any basic type containing the input image. 2D arrays are treated as one-channel images. 3D arrays must be of the form [N x n x m] where N is the number of image channels.
Color
An N-element vector that specifies the color in the image that is to be replaced, where N is the number of image channels.
ReplaceColor
An N-element vector that specifies the color to be placed in the image where the image color matches the Color argument, and where N is the number of image channels.
Keywords
THRESHOLD
An N-element vector that specifies the threshold of the color in the array to be replaced, where N is the number of image channels. Colors are replaced if every channel is in the range Color +/- Threshold, inclusive. The default value is a vector of zeroes, specifying that an exact match is needed for replacement.
If a threshold is specified, THRESHOLD promotes the datatype of the threshold value to ensure the comparisons do not overflow.
Examples
This example reads a TrueColor image file and displays the original and two versions to which a color exchange operation has been applied.
The resulting images appear as follows:
Note
In the first replacement (the center image), there were no exact matches for the pixel value [255,0,0], so no pixels were replaced.
Version History
