Common color models and conversion formulas

different color models

Common image color models: RGB model, YUV model, HSV model, Lab model, GRAY model.

RGB model : red (Red), green (Green) and blue (Blue). In the RGB color model, all colors are obtained by mixing these three colors in different proportions. If the three color components are all 0, it is represented as black. If the three color components are the same and are the maximum value, is represented as white. Adding a fourth channel on the basis of this model is the RGBA model. The fourth channel represents the transparency of the color. When the transparency is 1, the RGBA model will degenerate into an RGB model.

YUV model : brightness (Y), signal difference between red component and brightness (U), difference between blue and brightness (V). The YUV model is the color coding method adopted by the TV signal system, and is mainly used for the transmission of video and images. The conversion relationship between the RGB model and the YUV model is as follows, where the value range of RGB is 0-255.

HSV model : Hue, Saturation, Value. It can also be seen from the name that the model describes the color through these three characteristics. Compared with the shortcomings of the unintuitive connection between the three color components of the RGB model and the final color, the HSV model is more in line with the way humans perceive colors: color, depth, and brightness.

Hue (0-180), Saturation (0-255), Brightness (0-255)

Lab model : It makes up for the deficiency of the RGB model and is a device-independent color model. In the model, L represents Luminosity, and a and b are two color channels, both of which range from -128 to +127, where the value of channel a changes from small to large, and the corresponding color changes from green to Red, b channel value from small to large corresponds to the color from blue to yellow. The color space it constitutes is a sphere.

GRAY model : It is not a color model, but a grayscale image model, whose name uses the uppercase letters of the English word gray. The grayscale image has only one channel, and the grayscale value represents from black to white in sequence from 0 to maximum according to the number of image bits. Commonly used RGB models are converted into grayscale images:

 OpenCV convert call

Function prototype:

void cv::cvtColor(InputArray src,
                        OutputArray dst,
                        int code,
                        int dstCn = 0
                        )
  • src: The original image of the color model to be converted.
  • dst: the destination image after converting the color model.
  • code: the flag of color space conversion, such as from RGB space to HSV space. Commonly used symbols and their meanings are shown in the table below.
  • dstCn: the number of channels in the target image, if the parameter is 0, the number of channels is automatically derived from src and code

cvtColor() function color model conversion commonly used flag parameters: 

 Code example:

cvtColor(img32, dstHSV, COLOR_BGR2HSV);
cvtColor(img32, dstYUV, COLOR_BGR2YUV);
cvtColor(img32, dstLab, COLOR_BGR2Lab);
cvtColor(img32, dstgray, COLOR_BGR2GRAY);

[Learn OpenCV 4 from zero] Color model and conversion-Knowledge

OpenCV: Color conversions

Guess you like

Origin blog.csdn.net/u010420283/article/details/128438469