07.OpenCV- image processing - the color space conversion

This paper describes several common color model and color space conversion using opencv.

1.RGB model

I.e. the three primary colors, Red, Green, Blue, each containing 256 gray levels.

2.CMY model

CMY is a subtractive primary color which is complementary to the additive mixture of RGB space, i.e. the space is complementary with white subtracted, i.e. subtracting a color value in the RGB space is equal to the same white color in CMY space value

3.HSI model

HSI model is from the human visual system, a hue (Hue), saturation (Saturation, or by Chroma) and luminance (or the Brightness Intensity) used to describe the color
 I: represents light intensity or luminance is called, it determines the overall pixel brightness, no matter what their color Yes. Its brightest value: represents the light intensity or luminance is called, it determines the overall brightness of the pixel, regardless of its color and Yes. Its brightest value 1, 0 is the darkest.

H: represents the chromaticity, expressed by the angle (0 ~ 360º). This reflects the color closest to what kind of spectral wavelengths (colors of the rainbow in both kind of). The reflected color spectrum closest to what wavelengths (rainbow colors that both) as a red 0 degrees, 120 degrees for the green, blue 240 degrees.

 S: represents the color saturation, color saturation degree is the origin point to the color color circle radius length. In the outer circumference of the ring, said saturated or pure color, which is a saturation value: represents color saturation, color saturation degree is the origin point to the color color circle radius length. In the outer circumference of the ring, said saturated or pure color, which is a saturation value. In the center is the neutral (gray) tone, i.e., 0 to saturation.

Conversion between models

Conversion between color models

Color space conversion

There are more than 150 kinds of color space conversion method is carried out in the OpenCV. But later you will find two kinds of it we often use: BGR↔Gray and BGR↔HSV.
We use to functions are: cv2.cvtColor (input_image, flag), in which the flag is the type of conversion.
For BGR↔Gray conversion, we want to use the flag is cv2.COLOR_BGR2GRAY.
Also for BGR↔HSV conversion, we use the flag is cv2.COLOR_BGR2HSV.

Note: In the HSV format OpenCV, H (color / chromaticity) is in the range [0,179], S (saturation) in the range [0,255], V (brightness) ranges [0,255]. But the software uses different values ​​may be different. So when you need to get OpenCV HSV values ​​were compared with other software HSV values, we must remember normalized.

 

Guess you like

Origin blog.csdn.net/weixin_42572978/article/details/92801307