![]() |
OpenCV
Open Source Computer Vision
|
See cv::cvtColor and cv::ColorConversionCodes
Transformations within RGB space like adding/removing the alpha channel, reversing the channel order, conversion to/from 16-bit RGB color (R5:G6:B5 or R5:G5:B5), as well as conversion to/from grayscale using:
and
The conversion from a RGB image to gray is done with:
More advanced channel reordering can also be done with cv::mixChannels.
where
Y, Cr, and Cb cover the whole value range.
Only 8-bit values are supported. The coefficients correspond to BT.601 standard with resulting values Y [16, 235], U and V [16, 240] centered at 128.
Two subsampling schemes are supported: 4:2:0 (Fourcc codes NV12, NV21, YV12, I420 and synonimic) and 4:2:2 (Fourcc codes UYVY, YUY2, YVYU and synonimic).
In both subsampling schemes Y values are written for each pixel so that Y plane is in fact a scaled and biased gray version of a source image.
In 4:2:0 scheme U and V values are averaged over 2x2 squares, i.e. only 1 U and 1 V value is saved per each 4 pixels. U and V values are saved interleaved into a separate plane (NV12, NV21) or into two separate semi-planes (YV12, I420).
In 4:2:2 scheme U and V values are averaged horizontally over each pair of pixels, i.e. only 1 U and 1 V value is saved per each 2 pixels. U and V values are saved interleaved with Y values for both pixels according to its Fourcc code.
Note that different conversions are perfomed with different precision for speed or compatibility purposes. For example, RGB to YUV 4:2:2 is converted using 14-bit fixed-point arithmetics while other conversions use 20 bits.
In case of 8-bit and 16-bit images, R, G, and B are converted to the floating-point format and scaled to fit the 0 to 1 range.
If
The values are then converted to the destination data type:
In case of 8-bit and 16-bit images, R, G, and B are converted to the floating-point format and scaled to fit the 0 to 1 range.
If
The values are then converted to the destination data type:
In case of 8-bit and 16-bit images, R, G, and B are converted to the floating-point format and scaled to fit the 0 to 1 range.
where
and
This outputs
In case of 8-bit and 16-bit images, R, G, and B are converted to the floating-point format and scaled to fit 0 to 1 range.
This outputs
The values are then converted to the destination data type:
Note that when converting integer Luv images to RGB the intermediate X, Y and Z values are truncated to
The above formulae for converting RGB to/from various color spaces have been taken from multiple sources on the web, primarily from the Charles Poynton site http://www.poynton.com/ColorFAQ.html
The Bayer pattern is widely used in CCD and CMOS cameras. It enables you to get color pictures from a single plane where R, G, and B pixels (sensors of a particular component) are interleaved as follows:
The output RGB components of a pixel are interpolated from 1, 2, or 4 neighbors of the pixel having the same color.
There are several modifications of the above pattern that can be achieved by shifting the pattern one pixel left and/or one pixel up. The two letters