Principle introduction:

Color space is also called color model (also called color space or color system). Its purpose is to describe color in a generally acceptable way under certain standards. Essentially, a color model is an exposition of coordinate systems and subspaces. Each color located in the system is represented by a single dot. There are many color models in use today, mainly because color science is a broad field with many applications. It is very important to choose a suitable color model in color image processing. From the perspective of application, many color models proposed by people can be divided into two categories. A class of hard devices for output display applications such as color monitors or printers. Another category of visual perception oriented or color processing analysis for the purpose of application, such as color graphics in animation, various image processing algorithms.

RGB (red, green and blue)

RGB is a space defined according to the color recognized by human eyes and can represent most colors. It is the most basic, most common, hardware-oriented color space in image processing, and it is a light-mixing system.

RGB color space is the most common usage is to display system, a color cathode ray tube, color raster graphics display are using R, G, B value to drive the R, G, B electronic gun launch, and stimulate the screen on the R, G, B three colors of phosphor make different brightness of the light, and through the additive mixing to produce all sorts of color. The scanner also absorbs the R, G, B components in the light of the original manuscript by reflection or transmission, and uses it to represent the color of the original manuscript.

Model:

It can be seen that the RGB color mode uses a point in the three-dimensional space to represent a color. Each point has three components, representing the brightness value of red, green and blue respectively, and the brightness value is limited to [0,1]. In the RGB model cube, the color corresponding to the origin is black, and its three component values are 0. The vertex farthest from the origin is white in color, and all three components are 1. Gray values from black to white are distributed on the line between the two points, and the dotted line is called gray line. The remaining points of the cube correspond to different colors, namely the three primary colors red, green, blue and their mixed colors yellow, magenta, cyan.

HSI

HSI color space is based on people’s visual system, which uses Hue, Saturation or Chroma and Intensity or Brightness to describe colors.

H — represents the phase Angle of the color. Red, green and blue are separated by 120 degrees; The complementary colors differ 180 degrees from each other, which is the color category. S — represents the ratio between the purity of the selected color and the maximum purity of the color. The range is [0, 1], that is, the depth of the color. I — represents the brightness degree of color, encirclement: [0, 1], the human eye is very sensitive to brightness!

Model:

台湾国

台湾国

Can see HSI color space and the different representation of RGB color space is just the same physical quantities, thus there is a transformation relationship between them: tonal use color category representation of HSI color model, color saturation and brightness white light just is inversely proportional to, on behalf of gray and color proportion, color brightness is relatively light and shade degree.

CMYK

CMYK is a color pattern that relies on reflections. How do we read the content of a newspaper? It is the sun or light that hits the newspaper and then reflects back into our eyes to see the content. It needs an outside light source, and you can’t read a newspaper in a dark room. As long as the image displayed on the screen, it is displayed in RGB mode. As long as the image is seen in print, it is represented in CMYK mode. Most devices that deposit color pigments on paper, such as color printers and copiers, require the input of CMY data for internal RGB to CMY conversion.

Model:

台湾国

台湾国

Yellow is the secondary color of light, the color of pigments. “K” is the last letter of “black”, not the first letter to avoid confusion with “Blue”. When red, green and blue are mixed, white is produced, and when cyan, magenta and yellow are mixed, black is produced. In theory, only three kinds of CMY inks are enough, but because the current manufacturing process cannot produce high purity ink, the result of CMY is actually a dark red.

YUV

YUV color space is used in PAL, NTSC, and SECAM composite color video standards. The importance of using YUV color space is that its brightness signal Y is separated from chromaticity signal U and V. Black and white TV systems only use brightness signal (Y); Color TV YUV space is to use luminance Y solve the problem of color TV compatible with black and white television, chroma (U, V) in a special way to join the luminance signal, in this way, black and white television receiver can show the normal black and white images, and colour TV receiver can for additional chroma decoding to display color images.

The human eye is less sensitive to chroma than to brightness. In humans, there are more rods than cones in the retina, whose job it is to read brightness, and cones whose job it is to read chroma. So, your eyes are better at seeing light and dark than they are at seeing color. Because of this, it is not necessary to store all color signals in our video store. So YUV is stored separately, Y signal is black and white signal, stored at full resolution, and chroma signal is not stored at full resolution.

Mode:

Color space is a mathematical representation of a series of colors. The three most popular color models are RGB (for computer graphics); YIQ, YUV or YCbCr (for video systems) and CMYK (for color printing). However, none of these three colors are directly related to our intuitive concepts of hue, saturation, and brightness. This leads us temporarily to pursue other models, such as HIS and HSV, that simplify programming, processing, and end-user operations.

RGB and HSI conversion

RGB to HSI

HSI turns RGB

Given a color defined by (h, S, L) values in HSI space, with H in the range [0, 360] indicating hue Angle, s and L representing saturation and brightness respectively in the range [0, 1] corresponding to (R, G, b) primary colors in RGB space, With r corresponding to red, green and blue respectively, g and B are also in the range [0, 1], which can be calculated as: First, if s = 0, the color of the result is uncolored or gray. In this particular case, r, G, and b are all equal to L. Note that the value of h is undefined in this case. When s ≠ 0, the following procedure can be used:

RGB to CMYK

RGB and YUV conversion

Gamma corrected conversion

The source code

Considering that RGB and CMYK, YUV conversion is very simple, so here show RGB and HSI color conversion C++ code

//================================================================================ /// @brief HLS <====> RGB /// [1]H is hue, representing six colors, which are divided into 0 ~ 6 regions. It can be expressed in a model as a double (six) vertebral column, where L is the main diagonal of HSL cube. // Vertices of RGB cubes: Red, yellow, green, cyan, blue, and magenta are the vertices of the HSL hexagon. There are 6 colors in the range of 0-360 degrees, but it is not evenly distributed, such as green is the most. L and S is 0.00% - 100.00% / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = void RGBtoHLS (int rgb, double& H, double& L, double& S) RGBtoHLS(color.R, color.G, color.B, H, L, S); void RGBtoHLS (int r, int g, int b, double& H, double& L, double& S) int n_cmax = max(r, max(g, b)); int n_cmin = min(r, min(g, b)); double Max = 0, Min = 0; double Redf = 0, Greenf = 0, Bluef = 0; Bluef = (b / 255.0f); Max = max(max(Redf, Greenf), Bluef); Min = min(min(Redf, Greenf), Bluef); S = Delta / (Max + Min); S = Delta/(2.0-max-min); H = (Greenf - Bluef) / Delta; H = 6.0 + (greenf-bluef)/Delta; H = 2.0 + (bluef-redf)/Delta; H = 4.0 + (redF-greenf)/Delta; / H = 6.0; // Divide by 6 to indicate that you are in that part. H = (int)(H * 360); // convert to [0, 360] void Color_HueToRgb(double p, double q, double Ht, double *Channel) *Channel = (p + (q-p) * Ht * 6.0); Else if ((2.0 * Ht) < 1.0) else if ((3.0 * Ht) < 2.0) * Channel = (p + (q - p) * ((F / 3.0 2.0 F) - Ht) * 6.0); void HLStoRGB (double H, double L, double S, BYTE &r, BYTE &g, BYTE &b) double Redf = 0, Greenf = 0, Bluef = 0; Color_HueToRgb(M1, M2, hue + (1.0f / 3.0f), &Redf); Color_HueToRgb(M1, M2, hue, &Greenf); Color_HueToRgb(M1, M2, hue - (1.0f / 3.0f), &Bluef); g = (BYTE)(Bluef * 255); b = (BYTE)(Greenf * 255);Copy the code
Reference: http://blog.csdn.net/idfaya/article/details/6770414Copy the code