To transform the gray levels of the image so that the histogram of the resulting image is equalized to become a constant:
(6) |
The purposes:
We first assume the pixel values are continuous in the range
of , and a function
maps
to
also in
the same range. We also assume all pixels within the gray
scale interval
of the input image are mapped to the
corresponding range
of the output image. As the number
of pixels being mapped remains unchanged, we have
(7) |
For the histogram of the output image to be equalized, it
needs to be constant 1, i.e., , so that
(8) |
(9) |
(10) |
(11) |
This histogram equalization mapping can be intuitively
understood by checking the following two cases while
both need to keep
:
For discrete gray levels, the gray level of the input takes
one of the
discrete values:
, and the continuous
mapping function becomes discrete:
(12) |
(13) |
The resulting function in the range
needs
to be converted to the gray levels
by either of the
two ways:
(14) |
(15) |
Example:
Assume the images have
pixels in
gray levels.
The following table shows the equalization process corresponding to the
two conversion methods above:
(16) |
In the following example, the histogram of a given image is equalized. Although the resulting histogram may not look constant due to the discrete nature of the digital image, the cumulative histogram is an exact linear ramp indicating that the density histogram is indeed equalized. The density histogram is not guaranteed to be a constant because the pixels of the same gray level cannot be separated to satisfy a constant distribution.
Build lookup table:
sum=0.0; for (i=0; i<256; i++) { sum=sum+h[i]; lookup[i]=sum*255; }
Image Mapping:
for (m=0; m<M; m++) for (n=0; n<N; n++) y[m][n]=lookup[x[m][n]];Example: