A total of 256 grayscale levels, each grayscale level it will have a probability, and there will be a cumulative probability.
For example, 100 this grayscale level, its cumulative probability is 0.5, this new value we can make a 100 to this new value between the mapping. All subsequent pixels with a grayscale level of 100 are replaced with 255*0.5, the new pixel. After the substitution, the whole process is called histogram equalization.
The content of Count is recorded in 0-255 total of 256 grayscale levels. The number of pixels that appear in each grayscale level is then divided by the number of total pixels, which is the percentage of their pixels that each grayscale level occupies, which is their probability.
We calculate the cumulative probability after the probability is obtained.
#Nature: Statistical probability of the occurrence of grayscale in each pixel 0-255 p#Cumulative probability#1 0.2 0.2 first grayscale level it appears that the probability is 0.2#2 0.3 0.5 The second gray level it appears in the probability of 0.3#3 0.1 0.6 The third gray level, the probability that it appears is 0.1.# the#0.5 255*0.5 = newImportCv2ImportNumPy as NPImportMatplotlib.pyplot as Pltimg= Cv2.imread ('image0.jpg', 1) Imginfo=Img.shapeheight=Imginfo[0]width= Imginfo[1]gray=Cv2.cvtcolor (Img,cv2. Color_bgr2gray) Count= Np.zeros (256, Np.float) forIinchRange (0,height): forJinchRange (0,width): Pixel=Gray[i,j] Index=int (pixel) Count[index]= Count[index]+1 forIinchRange (0,255): Count[i]= count[i]/(height*width)#Calculate cumulative probabilitySUM1 =Float (0) forIinchRange (0,256): Sum1= sum1+Count[i] Count[i]=sum1Print(count) cv2.waitkey (0)
This is the probability that every pixel point appears.
5-7 Grayscale Histogram equalization