To transferm the gray levels of the image so that the histogram of the
resulting image is equalized to become a constant:
The purposes:
Assume a given function
maps all pixels within the gray scale
range
of the input image to the corresponding range
of the output
image. As the number of pixels being mapped remains unchanged, we have
For the histogram of the output image to be equalized,
needs to be
a constant. For convenience, we assume the gray levels of the output image
to be in the range
, then
, and we have:
This histogram equalization mapping can be intuitively interpreted by the following:
For discrete gray levels, the gray level of the input
takes one of
the
discrete values:
, and the continuous mapping function
becomes discrete:
The resulting function
in the range
needs to be
converted to the gray levels
by either of the two ways:
Example:
Assume the images have
pixels in
gray levels.
The following table shows the equalization process corresponding to the
two conversion methods above:
| 0 | 790 | 0.19 | 0.19 | 1 | 0.19 | 0.19 | 0 | 0.19 | 0.19 |
| 1 | 1023 | 0.25 | 0.44 | 3 | 0.25 | 0.44 | 2 | 0.25 | 0.44 |
| 2 | 850 | 0.21 | 0.65 | 5 | 0.21 | 0.65 | 4 | 0.21 | 0.65 |
| 3 | 656 | 0.16 | 0.81 | 6 | 5 | 0.16 | 0.81 | ||
| 4 | 329 | 0.08 | 0.89 | 6 | 0.24 | 0.89 | 6 | 0.08 | 0.89 |
| 5 | 245 | 0.06 | 0.95 | 7 | 7 | ||||
| 6 | 122 | 0.03 | 0.98 | 7 | 7 | ||||
| 7 | 81 | 0.02 | 1.00 | 7 | 0.11 | 1.00 | 7 | 0.11 | 1.00 |
In the following example, the histogram of a given image is equalized. Although the resulting histogram may not look constant, but the cumulative histogram is a 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.
Programming issues:
Example: