Histogram equalization (histogram equalization), also known as histogram flattening, is essentially a non-linear stretching of the image, re-allocation of image values, so that the number of pixels in a certain grayscale range is roughly equal. Thus, the original histogram in the middle of the peak part of the contrast is enhanced, and the bottom of the two sides of the lower contrast, the output image histogram is a flat segmented histogram: If the output data segmentation value is small, it will produce a rough classification of visual effects.
Histograms are statistical relationships that represent the frequency of each grayscale occurrence in a digital image. The histogram can give the image Gray range , the frequency of each gray scale and the distribution of gray, the average brightness and contrast of the whole image and other general description of the picture. Gray-scale histogram is a function of gray level, reflecting the image has the number of gray-level pixels, its horizontal axis is the gray level of R, ordinate is the gray level of the frequency (that is, the number of pixels) PR (R), the whole coordinate system describes the image gray level distribution, so you can see the image of gray distribution characteristics, Even if most of the pixels are concentrated in the low gray area, the image is dark; If the pixels are concentrated in a high gray area, the image is illuminated.
Figure 1 shows the histogram equalization, which will change the randomly distributed histogram of the image to a uniformly distributed histogram. The basic idea is to make some kind of mapping transformation to the pixel gray level of the original image, so that the probability density of the image gray is evenly distributed. This means that the dynamic range of the image grayscale is increased, and the contrast of the image is improved.
Figure 1 Histogram equalization
This technique allows you to clearly see the distribution of the image brightness on the histogram and adjust the brightness of the image as needed. In addition, this method is reversible, and if the equalization function is known, the original histogram can be restored.
Set Variable R to represent the pixel grayscale level in the image. The grayscale level is normalized, then 0≤r≤1, where r= 0 means black, r= 1 is white. For a given image, each pixel value is random in the gray level of [0,1]. The probability density function is used to represent the distribution of the image gray level.
In order to facilitate digital image processing, the introduction of discrete forms. In discrete form, it is represented by discrete gray level, represented by, and the following formula is established:
Among them, 0≤≤1, k=0, 1, 2, ..., n-1. This is the number of pixels in the image that appear in this grayscale, and n is the frequency in the probability theory. The function expression of image histogram equalization is:.
Reference: http://www.cnblogs.com/hustlx/p/5245461.html
algorithm implementation (many implemented under OPENCV)
#defineHdim 256#defineSRC 0#defineDST 1intMainintargcChar**argv) {Iplimage*SRC =0, *DST =0; intN[] ={Hdim,hdim,hdim}; intr[ the] = {0}, g[ the] = {0}, b[ the] = {0}; if(argc!=2|| (src = cvloadimage (argv[1],3)) = = NULL)return-1; Cvnamedwindow ("Source",1); Cvnamedwindow ("result",1); intwidth = src->width; intHeight = src->height; intsum = width * height;//pixel-point synthesis in images inti,j; //the RGB distribution of statistical histogram separately for(i=0; i) for(j=0; j<width; J + +) {b[(Uchar*) (Src->imagedata+i*src->width)) [j*src->nchannels+0]]++; g[((Uchar*) (Src->imagedata+i*src->width)) [j*src->nchannels+1]]++; r[((Uchar*) (Src->imagedata+i*src->width)) [j*src->nchannels+2]]++; } ////Build the cumulative distribution equation of the histogram to equalize the histogram Doubleval[3] = {0}; for(i=0; i) {val[0] +=B[i]; val[1] +=G[i]; val[2] +=R[i]; B[i]= val[0]*255/sum; G[i]= val[1]*255/sum; R[i]= val[2]*255/sum; } DST= Cvcreateimage (Cvsize (width,height),8,3); //normalized histogram for(i=0; i) for(j=0; j<width; J + +) {(Uchar*) (Dst->imagedata+i*dst->widthstep)) [j*dst->nchannels+0]=b[((uchar*) (Src->imagedata+i*src->widthstep)) [j*src->nchannels+0]]; ((Uchar*) (Dst->imagedata+i*dst->widthstep)) [j*dst->nchannels+1]=g[((uchar*) (Src->imagedata+i*src->widthstep)) [j*src->nchannels+1]]; ((Uchar*) (Dst->imagedata+i*dst->widthstep)) [j*dst->nchannels+2]=r[((uchar*) (Src->imagedata+i*src->widthstep)) [j*src->nchannels+2]]; } cvshowimage ("Source", SRC); Cvshowimage ("result", DST); Cvsaveimage ("out.jpg", DST); Cvwaitkey (0); Cvdestroywindow ("Source"); Cvdestroywindow ("result"); Cvreleaseimage (&src); Cvreleaseimage (&DST); Cvreleasehist (&hist); return 0;}
Later add ...
Reference: http://jingyan.baidu.com/article/9c69d48fbf456113c9024ed3.html (MATLAB implementation)
Histogram equalization of Digital image processing-----