Next: Histogram Specification Up: contrast_transform Previous: Gray level mapping

## Histogram Equalization

To transform the gray levels of the image so that the histogram of the resulting image is equalized to become a constant:

The purposes:

• to equally make use of all available gray levels in the dynamic range;
• for further histogram specification.

We first assume the pixel values are continuous in the range of , and the mapping 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

For the histogram of the output image to be equalized, it needs to be constant 1, i.e., , so that

We therefore have:

Integrating both sides, we get the mapping function for the histogram equalization:

where is the cumulative distribution of the gray levels of the input image:

This histogram equalization mapping can be intuitively interpreted by the following:

• If is low, has a shallow slope, will be narrow, causing to be high, to keep ;
• If is high, has a steep slope, will be wide, causing to be low, 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:

where and are respectively the density and cumulative histogram of the input image :

and is the number of pixels with gray level , and is the total number of pixels.

The resulting function in the range needs to be converted to the gray levels by either of the two ways:

where is the floor of a real number (the largest integer smaller than ), and adding is for proper rounding. Note that both conversions map to the highest gray level , but the second conversion also maps to 0 to stretch the gray levels of the output image to occupy the entire dynamic range ; i.e., the second method does gray scale stretch as well as histogram equalization.

Example:

Assume the images have pixels in gray levels. The following table shows the equalization process corresponding to the two conversion methods above:

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.

Example:

Next: Histogram Specification Up: contrast_transform Previous: Gray level mapping
Ruye Wang 2016-09-29