📜 ⬆️ ⬇️

About color spaces

I am a programmer by education, but for work I had to deal with image processing. And then an amazing and unexplored world of color spaces opened up for me. I don’t think that designers and photographers will learn something new for themselves, but perhaps this knowledge will be useful to someone, at least useful, and interesting at best.

The main task of color models is to make it possible to set colors in a unified way. In fact, color models define certain coordinate systems that allow you to uniquely determine the color.

The most popular today are the following color models: RGB (used mainly in monitors and cameras), CMY (K) (used in printing), HSI (widely used in computer vision and design). There are many other models. For example, CIE XYZ (standard models), YCbCr, etc. The following is a brief overview of these color models.

RGB color cube


The idea of ​​an additive (ie, based on the mixing of colors from directly emitting objects) color reproduction model arises from the Grassmann law. For the first time a similar model was proposed by James Maxwell in 1861, but it became most common much later.
')
In the RGB model (from the English. Red - red, green - green, blue - blue) all colors are obtained by mixing the three basic (red, green and blue) colors in various proportions. The share of each base color in the final can be perceived as a coordinate in the corresponding three-dimensional space, so this model is often called a color cube. In Fig. Figure 1 shows the color cube model.



Most often, the model is built so that the cube is single. The points corresponding to the base colors are located at the vertices of the cube lying on the axes: red - (1; 0; 0), green - (0; 1; 0), blue - (0; 0; 1). At the same time, secondary colors (obtained by mixing two basic colors) are located at other vertices of the cube: cyan - (0; 1; 1), magenta - (1; 0; 1) and yellow - (1; 1; 0). Black and white colors are located at the origin (0; 0; 0) and the point (1; 1; 1) furthest from the origin. Fig. shows only the vertices of the cube.



Color images in the RGB model are built from three separate channel images. Tab. Shows the decomposition of the original image into color channels.



In the RGB model, a certain number of bits are allocated for each color component, for example, if 1 byte is allocated for encoding each component, then using this model, 2 ^ (3 * 8) ≈16 million colors can be encoded. In practice, such encoding is redundant, since most people are not able to distinguish so many colors. Often limited to the so-called. mode "High Color" in which the coding of each component is given 5 bits. In some applications, a 16-bit mode is used in which 5 bits are allocated for encoding the R and B components, and 6 bits for encoding the G component. This mode, firstly, takes into account a higher human sensitivity to green color, and secondly, allows more efficient use of computer architecture features. The number of bits set aside for encoding one pixel is called the color depth. Tab. Examples of coding the same image with different color depths are given.



Subtractive CMY and CMYK models


The subtractive CMY model (from the English. Cyan - cyan, magenta - magenta, yellow - yellow) is used to obtain hard copies (printing) of images, and in some ways is the antipode of the RGB color cube. If in the RGB model, the base colors are the colors of the light sources, then the CMY model is the color absorption model.

For example, paper coated with yellow dye does not reflect blue light, i.e. we can say that the yellow dye subtracts blue from the reflected white light. Similarly, the blue dye subtracts red from the reflected light, and the purple dye subtracts green. That is why this model is called subtractive. The translation algorithm from the RGB model to the CMY model is very simple:



It is assumed that the RGB colors are in the interval [0; 1]. It is easy to see that to get black in the CMY model, you need to mix cyan, magenta and yellow in equal proportions. This method has two serious drawbacks: firstly, the black color obtained as a result of mixing will look brighter than the “real” black, and secondly, this leads to significant dye costs. Therefore, in practice, the CMY model is extended to the CMYK model by adding black (eng. Black) to the three colors.

Color space hue, saturation, intensity (HSI)


The RGB and CMY (K) color models discussed earlier are quite simple in terms of hardware implementation, but they have one major drawback. It is very difficult for a person to operate with colors specified in these models, since when describing colors, a person does not use the content in the described color of the basic components, but in somewhat different categories.

Most often, people use the following concepts: color tone, saturation and lightness. At the same time, speaking of the color tone, they usually mean color. Saturation indicates how much the described color is diluted with white (pink, for example, is a mixture of red and white). The concept of lightness is most difficult to describe, and with some assumptions, lightness can be understood as the intensity of light.

If we consider the projection of the RGB-cube in the direction of the diagonal white-black, we get a hexagon:



All gray colors (lying on the diagonal of the cube) are projected at the center point. To use this model to encode all the colors available in the RGB model, you need to add a vertical axis of lightness (or intensity) (I). The result is a hex cone:



In this case, the tone (H) is set by the angle relative to the red axis, the saturation (S) characterizes the purity of the color (1 means a completely pure color, and 0 corresponds to a shade of gray). It is important to understand that tone and saturation are not defined at zero intensity.



The algorithm for converting from RGB to HSI can be performed using the following formulas:



The color model HSI is very popular among designers and artists, because this system provides direct control of tone, saturation and brightness. These properties make this model very popular in computer vision systems. Tab. The image changes with increasing and decreasing intensity, tone (± 50 ° rotation is performed) and saturation are shown.



CIE XYZ model


For the purpose of unification, an international standard color model was developed. As a result of a series of experiments, the International Commission on Illumination (CIE) determined the addition curves of the main (red, green and blue) colors. In this system, each visible color corresponds to a certain ratio of primary colors. At the same time, in order for the developed model to reflect all the colors visible by a person, it was necessary to introduce a negative amount of base colors. To get away from the negative values ​​of CIE, entered the so-called. unreal or imaginary primary colors: X (imaginary red), Y (imaginary green), Z (imaginary blue).

When describing a color, the values ​​X, Y, Z are called standard main excitations, and the coordinates obtained on their basis are called standard color coordinates. The standard addition curves X (λ), Y (λ), Z (λ) (see Fig.) Describe the sensitivity of the average observer to standard excitations:



In addition to standard color coordinates, the concept of relative color coordinates is often used, which can be calculated using the following formulas:



It is easy to see that x + y + z = 1, which means that for a unique assignment of relative coordinates, any pair of values ​​is sufficient, and the corresponding color space can be represented as a two-dimensional graph:



The set of colors defined in this way is called the CIE triangle.
It is easy to see that the CIE triangle describes only the color tone, but does not describe the brightness. To describe the brightness, an additional axis is introduced that passes through a point with coordinates (1/3; 1/3) (the so-called white point). The result is a CIE color body (see Fig.):



This body contains all the colors visible to the average observer. The main disadvantage of this system is that, using it, we can only ascertain the coincidence or difference of two colors, but the distance between two points of this color space does not correspond to the visual perception of the difference of colors.

CIELAB model


The main goal in the development of CIELAB was to eliminate the non-linearity of the CIE XYZ system from the point of view of human perception. The abbreviation LAB is usually understood as the CIE L * a * b * color space, which is currently an international standard.

In the CIE L * a * b system, the coordinate L means lightness (in the range from 0 to 100), and the coordinates a, b indicate the position between the green-purple and blue-yellow colors. The formulas for converting coordinates from CIE XYZ to CIE L * a * b * are listed below:


where (Xn, Yn, Zn) are the coordinates of the white point in the CIE XYZ space, and


In Fig. CIE L * a * b * color body sections are presented for two lightness values:



Compared to the CIE XYZ system, the Euclidean distance (√ ((L1-L2) ^ 2 + (a1 ^ * - a2 ^ *) ^ 2 + (b1 ^ * - b2 ^ *) ^ 2)) in the CIE L * a system * b * corresponds much better to the color difference perceived by a person, however, the standard formula for color difference is the extremely complex CIEDE2000.

TV color difference color systems


In the YIQ and YUV color systems, color information is represented as a luminance signal (Y) and two color difference signals (IQ and UV, respectively).

The popularity of these color systems is due primarily to the emergence of color television. Since The Y component essentially contains the original image in grayscale, the signal in the YIQ system could be received and correctly displayed on both old black and white TVs and on new color TVs.

The second, perhaps more important advantage of these spaces is the separation of information about the color and brightness of the image. The fact is that the human eye is very sensitive to changes in brightness, and much less sensitive to changes in color. This allows you to transfer and store information about chromaticity with reduced depth. It is on this feature of the human eye that the most popular today image compression algorithms (including jpeg) are built. To translate from RGB space to YIQ, you can use the following formulas:

Source: https://habr.com/ru/post/181580/


All Articles