Personal understanding of color space

A color space, as the name suggests, is a space composed of colors. Write down my personal basic views on color space here.

The first time I came into contact with color space was during the period of self-study PS, in order to make the goddess P beautiful~ Then I saw this: PS
when I used a brush to further beautify the face, I saw this again:
usually

Shock! How can I choose the TAT I want from so many colors


How to find exactly the color we want? People put different colors together in different ways to form different color spaces. Each color can have a fixed analog and digital representation in the color space. Different color spaces are defined in different ways.

How to represent color? For example, the RGB color shown above. It consists of red (Red, R), green (Green, G), and blue (Blue, B). Red, green and blue are the three primary colors of light, and these three colors are regarded as the X, Y, and Z axes of the coordinate system, which constitutes the color space of RGB notation. In addition, there are HSB color spaces composed of hue, saturation, and lightness, CMYK color spaces for printing, and so on. Several common color space interpretations are listed below.


1. RGB color space
Junior high school science tells us that the three primary colors of light are red, green and blue. What RGB uses is additive color mixing, which defines the color by describing the proportion of light. Common color spaces, such as srgb, Adobe rgb, etc., are developed on this basis. And RGBA is to add Alpha transparency channel on the basis of RGB.


2. CYMK color space
is relatively common in a series of printing product design software, and it adopts a color mixing method similar to RGB, but the difference is that this space is used for ink color mixing. Its four primary colors are cyan, magenta, yellow, and black. Printed products rely on reflected light to reflect color, so subtractive color mixing, which is different from RGB, is used. Its comparison chart is as follows
Write picture description here
Write picture description here


3. HSV color space
HSV space does not use the method of primary color aliasing, but expresses colors through unique definitions. It records color information through hue, saturation, and lightness, and its color space looks like this
Write picture description here
Write picture description here


4. HSL color space
Similar to HSV, the brightness is replaced by brightness. In HSL, the brightness of pure color is equal to the brightness of white, while in HSV, the brightness of pure color is equivalent to gray brightness. The specific difference can be seen from the figure below.
Write picture description here


Finally, let's talk about the concept of color gamut in particular. We can often see this kind of picture on the website of buying computers:
Write picture description here
(taken from a fruit factory)
The color gamut is the correspondence between the color model and the color space, it is a coding method, and it also reflects the colors that the display device can produce sum. The pictures given by various factories are nothing more than to prove "how wide" their color gamut is. The color gamut shows the color space and the color range of the output device, as shown in the figure below corresponding to the color gamut of different color coding methods.
Write picture description here

Each device has its own color interpretation system and presentation range, so sometimes the visual color may be abnormal when the image is transferred, and color correction is required at this time.


To sum up, different color spaces give colors different codes, and each color space can be converted to each other. But what kind of color space to use needs to be adapted to the actual situation. Each color space has its own advantages and disadvantages. For example, when it is necessary to obtain the saturation of the image, it should be converted to the HSL color space. Reasonable use of different spaces can achieve the desired effect.

Mengxin doesn't know anything. It's the first time I post a post. If there are any mistakes, please correct me. Don't spray~


References:
Color Gamut Baidu Encyclopedia
Mac Color Gamut Test
HSL and HSV Wiki
About Color - Adobe


Should be required to add a little knowledge related to the Mat class in OpenCV.
The Mat class is often used to store image information in OpenCV. The essence of Mat is a matrix. When storing image information, Mat is divided into two parts: data header and data block.
The matrix header records the length, width, channel, data type and other information of the picture.
The data block of the matrix records the information of the picture, and the data of each pixel is represented by a numerical value.
One of the steps to newly initialize the Mat type is

Mat image(rows,cols,type);

rows: row cols: column type: data type
As far as I know, there are several basic types of CV_8UC1, CV_8UC2, and CV_8UC3. The numbers at the end represent the number of channels respectively. Because of this, sometimes the initialization can be followed by the Scalar attribute to initialize the data of each channel.
In OpenCV, the cvtColor function can be used to convert the color space.

cvtColor(src,dst,type);

src: image input Mat
dst: target Mat
type: conversion method COLOR_BGR2GRAY converts grayscale image COLOR_BGR2HSV converts to HSV format COLOR_BGR2Lab converts to Lab format.
Use imwrite to output after conversion.
It is worth noting that the order of Scalar attribute access in Mat is not R\G\B, but B\G\R, that is, Scalar(0,255,0) outputs pure green graphics.
So how to access the value of each channel in Mat? You can use the at method.

 //image.at<Vec3b>(rows,cols)[tunnel]
 image.at<Vec3b>(1,2)[0] //访问image中(1,2)像素在0通道的B分量

Vec3b is a representation of RGB, which means that the input image is of RGB type (doubtful?)


Guess you like

Origin blog.csdn.net/weixin_43192572/article/details/82684088