Histogram
Equalization
The histogram indicates the number of times each grayscale value occurs. The normalized histogram is given by the histogram divided by the total number of pixels in the image, and it is an approximation to the Probability Mass Function.
The goal in histogram equalization is to approximate the grayscale-value distribution of an image to the uniform distribution. Histogram equalization is useful because it helps in spreading the grayscale values and allows us to see a larger range of grayscale values.
First, lets assume that the pixel values are continuous. Assume that the pixel values in the original image are given by the variable r and in the equalized image by the variable s. In order to simplify the analysis, assume that the pixels take values between 0 and 1. Then, we are interested in a transformation of the form s = T(r) with s having a uniform histogram. It is important to mention that this transformation should have two properties:
(a) It has to be single valued (so we can use the inverse operation T-1) and monotonically increasing (otherwise some of the gray-levels will be inverted).
(b) It has to be between 0 and 1 if r is between 0 and 1.
From probability theory we know that if r and s are two random variables with corresponding probability distribution functions pr(r) and ps(s), then
ps(s) = pr(r) |dr/ds| (1)
If we consider the following transformation:
![]()
then, it is easy to show that ds/dr = pr(r) since the derivative will eliminate the integral in the equation (2). Therefore, since pr(r) is always positive, equation (1) reduces to ps(s) = 1, which is the probability density function of a uniform distribution.
In the case of an image the pixel values are discrete. Therefore, equation (2) can be approximated by:
![]()
Example:
Assume a 10 x 10 image (100 pixels) with the following normalized histogram:

r1 r2 r3 r4 r5 r6 r7 r8 r9 r10
For example, the value 0.1 appears 19 times in the histogram so the number is 19/100 = 0.19 in the normalized histogram. Using equation (3), we get:
s1 s2 s3 s4 s5 s6 s7 s8 s9 s10
0.19 0.37 0.55 0.70 0.83 0.89 0.93 0.95 0.96 1.00
For example, in the histogram equalized image, s5 = 0.83 will have a corresponding histogram value of (the same as r5) 0.13. Therefore, we get the new normalized histogram:
We notice that the histogram
is spread out, but it is not perfectly uniform (the continuous version would
be). On the other hand, we see that there is higher value density (more peaks) around
0.9 to compensate for the peak shortness around this range of values.