1. RGB model
2. HSV model
3. How to understand the relationship between RGB and HSV
4. The application of HSV in image processing
5. RGB-->HSV implementation in OPENCV
In image processing, the most common color space is the RGB model, often used for color display and image processing, three-dimensional coordinates of the model form, very easy to understand.
The HSV model, which is a color model for user perception, focuses on color representation, what color, depth, and brightness. The first contact with the HSV, the first thing in the book is a cone model, because very little use of HSV, so the impression is not profound, but to see some information, the concept of HSV occasionally out to harass some people's nerves, so, clear the relationship between the HSV and RGB, to establish an intuitive impression is very necessary.
1. RGB model.
Three-dimensional coordinates:
The middle axis of the origin to the white vertex is the gray line, the R, G, and b three components are equal, and the intensity can be represented by a vector of three components.
Use RGB to understand color, depth, and shade changes:
Color change: Three axes RGB maximum component vertex and purple green YMC color vertex connection
Depth variation: distance between RGB vertex and CMY vertex to the middle Axis of origin and white vertex
Light and shade changes: the position of the central Axis point, to the origin, is dark, to the white vertex on the bright
PS: Optical Analysis
RGB mixture of three primary colors can form other colors, is not to say that the other colors of the physical light from the three primary color, each single shade has its own unique spectrum, such as yellow is a monochromatic, but red and green mixed can form yellow, because of the human sensory system, and human physiological system.
Can only say "the three primary colors of light in different proportions of the composite, to the human eye can be formed with a variety of frequencies of visible light equivalent color." ”
2. HSV model
Inverted Cone Model:
This model is described in terms of color, depth, and shading.
H is the color
S is the depth, s = 0 o'clock, only grayscale
V is light and dark, indicating the brightness of the color, but no direct contact with the intensity (meaning there is a little connection).
3. The relationship between RGB and HSV
From the above intuitive understanding, the RGB three-dimensional coordinates of the central axis up, and flattening, you can form the HSV cone model.
However, V is not directly related to strength because it only selects one of the largest components of RGB. RGB can reflect the change of light intensity (or grayscale).
v = max (R, G, b)
Conversion from RGB to HSV:
"HSV is an intuitive color model for users. We can start with a pure color, specify the color angle h, and let V=s=1, and then we can get the color we need by adding black and white to it. Increasing the black can reduce the V and s unchanged, as well as increasing the white can reduce S and v unchanged. For example, to get deep blue, v=0.4 s=1 h=240 degrees. To get a light blue color, v=1 s=0.4 h=240 degrees. "--Baidu Encyclopedia
4. HSV in image processing applications
The HSV has a larger effect when it is used to specify color segmentation.
The H and S components represent the color information.
Split application:
The color distance is represented by the H and s components, and the color distance refers to the numeric difference between the two colors.
Androutsos and others through the experiment on the HSV color space is roughly divided, the brightness is greater than 75% and the saturation is greater than 20% for the bright color area, the brightness is less than 25% for the black area, the brightness is greater than 75% and the saturation is less than 20% for the white area, the other is the color area.
For different color regions, the combination of H and s variable, the threshold value can be simple segmentation.
HSV's de-shadowing algorithm:
Improving shadow suppression in moving object detection with HSV color information
5. RGB--and OPENCV implementations in HSV
struct rgb2hsv_f{ typedef float channel_type; rgb2hsv_f (int _srccn, int _blu Eidx, float _hrange) : SRCCN (_SRCCN), Blueidx (_BLUEIDX), Hrange (_hrange) {} void operator () (const float* SRC, float* dst, int n) const { int i, BIDX = Blueidx , SCN = srccn; Float Hscale = hrange* (1.f/360.f); n *= 3; &nbs p; for (i = 0; i < n; i + = 3, src + = SCN) { & nbsp Float B = src[bidx], G = src[1], r = src[bidx^2]; float h, s , v; float vmin, diff;   ; v = vmin = r; if (v < g) v = g; if (v < b) v = b; v = max (b, G, R) if (Vmin > g) vmin = g; if (Vmin > B) vmin = b; &NBSP ; diff = v-vmin; s = diff/(float) (Fabs (v) + Flt_epsilon); s = 1-min/max diff = (float) (60./(diff + flt_epsilon)); if (v = = r) h = (g-b) *diff; &N Bsp Else if (v = = g) h = (b-r) *diff + 120.F;&NB Sp else h = (r-g) *diff + 240.F;&N Bsp &NBSp if (H < 0) H + = 360.F; H Evaluation Dst[i] = h*hscale; & nbsp dst[i+1] = s; dst[i+2] = v; &NBSP ; } } int SRCCN, blueidx; float hrange;};
RGB-to-gray implementation algorithm:
Template<typename _tp> struct rgb2gray{ typedef _tp CHANNEL_TYPE; Rgb2gray (int _srccn, int blueidx, const float* _coeffs): SRCCN (_SRCCN) { static const float coeffs0[] = {0.299f, 0.587f, 0.114f}; The three-component coefficients are different, the human eye is most sensitive to green, so the G-component coefficients are larger memcpy (coeffs, _coeffs _coeffs:coeffs0, 3*sizeof (coeffs[0))); if (Blueidx = = 0) std::swap (Coeffs[0], coeffs[2]); } void operator () (const _tp* SRC, _tp* dst, int n) const //Operation { int scn = SRCCN; Float cb = Coeffs[0], CG = coeffs[1], CR = coeffs[2]; for (int i = 0; i < n; i++, src = SCN) dst[i] = saturate_cast<_tp> (SRC[0]*CB + SRC[1]*CG + src[2]*cr); Result } int SRCCN; float coeffs[3];};
Transferred from: http://blog.csdn.net/viewcode/article/details/8203728
Understanding from RGB to HSV color space