Histogram equalization (histogram equalization)The "central idea" of histogram equalization is to change the gray histogram of the original image from a certain gray area in the comparative concentration to the uniform distribution in the whole gray range. Histogram equalization is the non-linear stretching of the image, re-allocating the image pixel value, so that the number of pixels within a certain gray scale is roughly the same. Histogram equalization is to change the histogram distribution of a given image into a "uniform" distribution histogram distribution. The main process of histogram equalization
- Count the pixel points and percentage of each grayscale value
- Accumulate a percentage of each grayscale value
- Recalculate the change of each gray value with a percentage of the new grayscale value
- Map the new corresponding relationship to the new image
a simple example
The first thing to note is that if you are talking about a complete topic, there is no single solution to the problem, because the title does not indicate the grayscale progression of the original image (such as the original image is 16 gray level, or 32 gray level, etc.). In order to provide you with a solution to the idea, now the human hypothesis that the original image is 16 gray level, the other gray-level solution is similar.
1, the gray-scale histogram of the image to find the method:
(1) First calculate the frequency of each gray level in the image, with H (i) to indicate the frequency of the gray level I, the value is equal to the number of gray level occurrences/image pixels:
H (0) =2/16
H (1) =1/16
H (2) =3/16
H (3) =2/16
H (4) =0/16
H (5) =1/16
H (6) =4/16
H (7) =1/16
H (8) =1/16
H (9) =1/16
H (Ten) =h (one) =h (15) =h (=h) =h (=0/16)
Then, with the gray level I as the horizontal axis, the frequency h (i) can be the longitudinal axes to draw the histogram corresponding to the image.
(2) Image histogram equalization process is:
The cumulative distribution is calculated first, with R (i) representing the cumulative distribution of the gray level I:
R (0) =h (0) =2/16
R (1) =r (0) +h (1) =2/16+1/16=3/16
R (2) =r (1) +h (2) =3/16+3/16=6/16
R (3) =r (2) +h (3) =6/16+2/16=8/16
R (4) =r (3) +h (4) =8/16+0/16=8/16
R (5) =r (4) +h (5) =8/16+1/16=9/16
R (6) =r (5) +h (6) =9/16+4/16=13/16
R (7) =r (6) +h (7) =13/16+1/16=14/16
R (8) =r (7) +h (8) =14/16+1/16=15/16
R (9) =r (8) +h (9) =15/16+1/16=16/16=1
R (Ten) =r (one) =r (15) =r (=r) =r
The cumulative distribution is quantified (it is necessary to use the gray level of the original image, which is why the previous need to explain), the quantization of gray scale with RQ (i), the quantization formula is RQ (i) =round (R (i) *15), (Note: 15 of the quantization formula equals the gray scale of the original image minus 1), you can get:
RQ (0) =round (r (0) *15) =2
RQ (1) =round (r (1) *15) =3
RQ (2) =round (R (2) *15) =6
RQ (3) =round (R (3) *15) =8
RQ (4) =round (R (4) *15) =8
RQ (5) =round (R (5) *15) =8
RQ (6) =round (R (6) *15) =12
RQ (7) =round (R (7) *15) =13
RQ (8) =round (R (8) *15) =14
RQ (9) =round (R (9) *15) =15
RQ (=round) (R (10) *15) =15
RQ (one) =round (R (11) *15) =15
RQ (=round) (R (12) *15) =15
RQ (=round) (R (13) *15) =15
RQ (=round) (R (14) *15) =15
RQ (=round) (R (15) *15) =15
Therefore, the corresponding relationship between the grayscale levels in the original image and the grayscale level in the image is:
0->2
1->3
2->6
3->8
4->8
5->8
6->12
7->13
8->14
9->15
10->15
11->15
12->15
13->15
14->15
15->15
The corresponding gray value in the original image is installed to replace the corresponding relationship with the corresponding gray value, you can get the homogenization of the image, the results are as follows:
3 8 13 8
6 12 2 12
14 6 12 86 2key implementation of the Code
</pre><pre name= "code" class= "CPP" ><span style= "White-space:pre" ></span>mat src,dest;< Span style= "White-space:pre" ></span>src.copyto (SRC), if (Src.channels () > 1) {cvtcolor (src, src, cv_ Bgr2gray);} matnd hist;const int histsize = 256;float range[] = {0, 255};const float *ranges[] = {range};const int channels = 0;c V::calchist (&SRC, 1, &channels, Mat (), hist, 1, &histsize, ranges); float total = Src.size (). width* src.size () . height;float Bins[histsize] = {0};float binsacc[histsize] = {0}; Mat Lut (1, cv_8u);vector<float> vectorbins;vector<float> maxbins;float sumbins = 0.0;int CountMax = 0;FL Oat TValue = 0;//Find the mapping tablefor (int i = 0; itake advantage of the balanced code in OPENCV with just one word:Mat dest2;equalizehist (SRC, dest2); Imshow ("Equlization2", dest2);
histogram and equalization of platformthe concept of platform histogram this side t Span style= "font-size:14px" > The idea of this approach is that if some grayscale levels in the original histogram correspond to values greater than the threshold T, the value at that point is set to T. If the value in this place is not more than T , then the value at that point remains unchanged.
where Pt (k) is the platform histogram, Pr (k) is the original histogram similar to histogram equalization, the cumulative function is obtained by summing up the platform histogram.then, the gray value of the original image is changed to the new gray value by equalization. In this method the determination of T is the most important task, and its determination method is described as follows Determination of Platform threshold value
Key code implementations Mat src,dest; Src.copyto (SRC); if (Src.channels () > 1) {cvtcolor (src, src, cv_bgr2gray);} matnd hist;const int histsize = 256;float range[] = {0, 255};const float *ranges[] = {range};const int channels = 0;c V::calchist (&SRC, 1, &channels, Mat (), hist, 1, &histsize, ranges); float total = Src.size (). width* src.size () . height;float Bins[histsize] = {0};float binsacc[histsize] = {0}; Mat Lut (1, cv_8u);vector<float> vectorbins;vector<float> maxbins;float sumbins = 0.0;int CountMax = 0;FL Oat TValue = 0;//Find the mapping tablefor (int i = 0; i
Welcome reprint, please indicate the source of this article: http://blog.csdn.net/fioletfly/article/details/51011399 Thank you!
Histogram equalization and platform histogram