The COLOR_CONVERT procedure converts colors to and from the RGB (Red Green Blue) and a number of other color spaces.
RGB values are bytes in the range 0 to 255. YCbCr values are bytes with the range indicated below. Other values are in floating point.
These color spaces and their ranges are:
HLS
|
Hue Lightness Saturation (double cone). Also known as HSL. Hue is measured in degrees between 0 and 360, with 0 corresponding to red, 120 to green, and 240 to blue. Lightness and Saturation are floating-point values between 0 and 1.
|
HSV
|
Hue Saturation Value (single cone). Hue is measured in degrees between 0 and 360, with 0 corresponding to red, 120 to green, and 240 to blue. Saturation and Value are floating-point values between 0 and 1.
|
YUV
|
Luminance and two Chrominance. Y is a floating-point value between 0 and 1, U is a floating-point value between -0.436 and 0.436, V is a floating-point value between -0.615 and 0.615.
|
YIQ
|
Luminance In-phase Quadrature. Y is a floating-point value between 0 and 1, I is a floating-point value between -0.596 and 0.596, Q is a floating-point value between -0.523 and 0.523.
|
YPbPr
|
Luma ChromaBlue ChromaRed (analog). Y is a floating-point value between 0 and 1, Pb and Pr are floating-point values between -0.5 to 0.5.
|
YCbCr
|
Luma ChromaBlue ChromaRed (digital). Y is a floating-point value between 16 and 235, Cb and Cr are floating-point values between 16 and 240.
|
The input parameters may be of one of the following forms:
- Three input parameters containing the input color triple(s) which may be scalars or arrays of same size. These are followed by three output parameters for returning the result.
- One image array of the form (3 x m x n, m x 3 x n, or m x n x 3), followed by a single output parameter for the result.
A reference containing a discussion of the various color systems is: Foley and Van Dam, Fundamentals of Interactive Computer Graphics, Addison-Wesley Publishing Co., 1982.
Examples
The command:
COLOR_CONVERT, 255, 255, 0, h, s, v, /RGB_HSV
converts the RGB color triple (255, 255, 0), which is the color yellow at full intensity and saturation, to the HSV system. The resulting hue in the variable h is 60.0 degrees. The saturation and value in the variables s and v, are set to 1.0.
The command:
COLOR_CONVERT, rgb_image, yuv_image, /RGB_YUV
converts the RGB_IMAGE image array of the form [3,m,n] to YUV_IMAGE, an image array of the same form.
Syntax
COLOR_CONVERT, I0, I1, I2, O0, O1, O2 [, /HLS_RGB | , /HSV_RGB | , /RGB_HLS | , /RGB_HSV | , /RGB_YCBCR | , /RGB_YIQ | , /RGB_YPBPR | , /RGB_YUV | , /YCBCR_RGB | , /YIQ_RGB | , /YPBPR_RGB | , /YUV_RGB ] [, INTERLEAVE=value]
or
COLOR_CONVERT, I0, O0 [, /HLS_RGB | , /HSV_RGB | , /RGB_HLS | , /RGB_HSV | , /RGB_YCBCR | , /RGB_YIQ | , /RGB_YPBPR | , /RGB_YUV | , /YCBCR_RGB | , /YIQ_RGB | , /YPBPR_RGB | , /YUV_RGB ] [, INTERLEAVE=value]
Arguments
I0, I1, I2
The input color triple(s). These arguments may be either scalars or arrays of same length.
O0, O1, O2
The variables to receive the result. Their structure is copied from the input parameters.
I0
An input image array of the form 3 x m x n, m x 3 x n, or m x n x 3.
O0
A variable to receive the result. Its structure is copied from the input parameter, I0.
Keywords
HLS_RGB
Set this keyword to convert from HLS to RGB.
HSV_RGB
Set this keyword to convert from HSV to RGB.
INTERLEAVE
This keyword is useful only when calling this procedure with two arguments. It is ignored when using six arguments. Set the keyword to the value that corresponds to the image array's interleave format. The second output argument uses the same interleave format when returning the result. The valid values for 2D arrays (3 x n or n x 3) are:
value |
array type |
0 |
Pixel Interleave (3 x n) (default)
|
1 |
Row Interleave (n x 3)
|
The valid values for 3D arrays (3xmxn, mx3xn, or mxnx3) are:
value |
array type |
0 |
Pixel Interleave (3 x m x n) (default)
|
1 |
Row Interleave (m x 3 x n)
|
2 |
Planar Interleave (m x n x 3)
|
RGB_HLS
Set this keyword to convert from RGB to HLS.
RGB_HSV
Set this keyword to convert from RGB to HSV.
RGB_YCBCR
Set this keyword to convert from RGB to YCbCr.
RGB_YIQ
Set this keyword to convert from RGB to YIQ.
RGB_YPBPR
Set this keyword to convert from RGB to YPbPr.
RGB_YUV
Set this keyword to convert from RGB to YUV.
YCBCR_RGB
Set this keyword to convert from YCbCr to RGB.
YIQ_RGB
Set this keyword to convert from YIQ to RGB.
YPBPR_RGB
Set this keyword to convert from YPbPr to RGB.
YUV_RGB
Set this keyword to convert from YUV to RGB.
Version History
Pre 4.0 |
Introduced |
6.4 |
Added image array conversion and YUV, YIQ, YPbPr, and YCbCr color spaces
|
See Also
CMYK_CONVERT, HLS, HSV