5-7 Grayscale Histogram equalization

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.