opencv color space conversion

RGB

Insert picture description here
Insert picture description here

RGB is designed based on the principle of color luminescence. In layman's terms, its color mixing method is like three lights of red, green and blue. When their lights are superimposed on each other, the colors are mixed, but the brightness is equal to The sum of the brightness of the two, the more mixed the higher the brightness, that is, additive mixing.

Each of the three color channels of red, green and blue is divided into 256 levels of brightness. At 0, the "light" is the weakest-it is turned off, and at 255, the "light" is the brightest. When the three-color gray values ​​are the same, the gray tones with different gray values ​​are produced, that is, when the three-color grays are all 0, it is the darkest black tone; when the three-color grays are all 255, it is the brightest white tone .

In computers, the so-called "how much" of RGB refers to the brightness, and it is represented by integers. Under normal circumstances, RGB each has 256 levels of brightness, which are represented by numbers from 0, 1, 2... until 255. Note that although the highest number is 255, 0 is also one of the numbers, so there are 256 levels in total.
256 x 256 x 256 = 16,777,216

  • Separate RGB three-channel image display
image = imread('image.jpg')
(R, G, B) = cv2.split(image)
zeros = np.zeros(image.shape[:2],dtype='uint8')
show(cv2.merge([R,zeros,zeros]))
show(cv2.merge([zeros,G,zeros]))
show(cv2.merge([zeros,zeros,B]))

Insert picture description here

HSV

HSV is a relatively intuitive color model, and the HSV color space can better digitally process colors. The color parameters in this model are: hue (H, Hue), saturation (S, Saturation), and lightness (V, Value).

Hue H:

Measured by angle, the value range is 0°~360°, starting from red and counting in a counterclockwise direction, red is 0°, green is 120°, and blue is 240°. Their complementary colors are: 60° for yellow, 180° for cyan, and 300° for magenta

Saturation S:

Saturation S indicates how close the color is to the spectral color. A color can be seen as the result of mixing a certain spectral color with white. Among them, the greater the proportion of the spectral color, the higher the degree of color close to the spectral color, and the higher the saturation of the color. The saturation is high, and the color is deep and bright. The white light component of the spectral color is 0, and the saturation is the highest. Usually the value ranges from 0% to 100%. The larger the value, the more saturated the color.

Brightness V:

Brightness indicates the brightness of the color. For the color of the light source, the value is related to the brightness of the luminous body; for the color of an object, this value is related to the transmittance or reflectance of the object. Usually the value ranges from 0% (black) to 100% (white).
Insert picture description here

  • Separate HSV three-channel display image
image = imread('image.jpg')
hsv = cv2.cvtColor(image, cv2.COLOR_RGB2HSV)
zeros = np.zeros(image.shape[:2],dtype='uint8')
for (name,chan) in zip(('H','S','V'), cv2.split(hsv)):
    cv2.imshow(name,chan)
cv2.waitKey(0)
cv2.destroyAllWindows()

Insert picture description here
Insert picture description here

L*a*b*

CIE1976L a b color space (CIE LAB color space) is a uniform color space recommended by the International Institute of Illumination (CIE) in 1976. The L a b color space is used for computer tone adjustment and color correction. This space is a three-dimensional rectangular coordinate system. It is currently the most widely used color measurement system. The lightness L and chromaticity coordinates a*, b are used to indicate the position of the color in the color space. l indicates the brightness of the color, a positive value indicates reddish, negative value indicates greenish; b positive value indicates yellowish, negative value indicates blue

L* represents the lightness of the color;

a* Positive value means red, negative value means green;

b* A positive value means yellow, and a negative value means blue;

Insert picture description here

  • Separate LAB three-channel display image
image = imread('image.jpg')
lab = cv2.cvtColor(image, cv2.COLOR_RGB2LAB)
zeros = np.zeros(image.shape[:2],dtype='uint8')
for (name,chan) in zip(('L','A','B'), cv2.split(lab)):
    cv2.imshow(name,chan)
cv2.waitKey(0)
cv2.destroyAllWindows()

Insert picture description here
Insert picture description here

  • Grayscale image conversion
image = cv2.imread('image.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imshow('original',image)
cv2.imshow('gray',gray)
cv2.waitKey(0)
cv2.destroyAllWindows()

Insert picture description here

Guess you like

Origin blog.csdn.net/cyj5201314/article/details/114992401