Histogram equalization


Histogram equalization is a method in image processing of contrast adjustment using the image's histogram.
Histogram equalization is a specific case of the more general class of histogram remapping methods. These methods seek to adjust the image to make it easier to analyze or improve visual quality.

Overview

This method usually increases the global contrast of many images, especially when the image is represented by a narrow range of intensity values. Through this adjustment, the intensities can be better distributed on the histogram, utilizing the full range of intensities evenly. This allows for areas of lower local contrast to gain a higher contrast. Histogram equalization accomplishes this by effectively spreading out the highly populated intensity values, which tend to degrade image contrast.
The method is useful in images with backgrounds and foregrounds that are both bright or both dark. In particular, the method can lead to better views of bone structure in x-ray images and to better detail in photographs that are either over- or under-exposed. A key advantage of the method is that it is a fairly straightforward technique, adaptive to the input image and an invertible operation. So, in theory, if the histogram equalization function is known, then the original histogram can be recovered. The calculation is not computationally intensive. A disadvantage of the method is that it is indiscriminate. It may increase the contrast of background noise, while decreasing the usable signal. In scientific imaging, where spatial correlation is more important than intensity of signal, the small signal-to-noise ratio usually hampers visual detections.
Histogram equalization often produces unrealistic effects in photographs; however, it is very useful for scientific images like thermal, satellite or x-ray images, often the same class of images to which one would apply false-color. Also histogram equalization can produce undesirable effects when applied to images with low color depth. For example, if applied to an 8-bit image displayed with 8-bit gray-scale palette it will further reduce color depth of the image. Histogram equalization will work the best when applied to images with much higher color depth than palette size, like continuous data or 16-bit gray-scale images.
There are two ways to think about and implement histogram equalization, either as an image change or as a palette change. The operation can be expressed as where is the original image, is the histogram equalization mapping operation, and is a palette. If we define a new palette as and leave image unchanged, then histogram equalization is implemented as palette change or mapping change. On the other hand, if palette remains unchanged and image is modified to then the implementation is accomplished by image change. In most cases, palette change is preferred as it preserves the original data.
Modifications of this method use multiple histograms, called subhistograms, to emphasize local contrast rather than overall global contrast. Examples of such methods include adaptive histogram equalization and variations including contrast-limited adaptive histogram equalization, multipeak histogram equalization, and multipurpose beta-optimized bihistogram equalization. The goal of these methods, especially MBOBHE, is to modify the algorithm to improve the contrast without producing brightness mean-shift and detail loss artifacts.
A signal transform equivalent to histogram equalization also seems to happen in biological neural networks so as to maximize the output firing rate of the neuron as a function of the input statistics. This has been proved in particular in the fly retina.

Back projection

The back projection of a histogrammed image is the re-application of the modified histogram to the original image, functioning as a look-up table for pixel brightness values.
For each group of pixels taken from the same position from all input single-channel images, the function puts the histogram bin value to the destination image, where the coordinates of the bin are determined by the values of pixels in this input group. In terms of statistics, the value of each output image pixel characterizes the probability that the corresponding input pixel group belongs to the object whose histogram is used.

Implementation

Consider a discrete grayscale image and let be the number of occurrences of gray level. The probability of a pixel value chosen uniformly randomly from image being ', is
being the total number of gray levels in the image, '
being the number of pixels in the image with value ', and being the total number of pixels in the image. Then is the image's histogram value for ', with the histogram normalized to have a total area of 1.
Let us then define the cumulative distribution function of pixels in image '. For value ' it is
which is also the image's accumulated normalized histogram.
We would like to create a transformation to produce a new image, with a flat histogram. Such an image would have a linearized cumulative distribution function across the value range, i.e.
for some constant. The properties of the CDF allow us to perform such a transform. It is defined as
where is in the range. Notice that maps the levels into the range, since we used a normalized histogram of. In order to map the values back into their original range, the following simple transformation needs to be applied to each transformed image value :
is a real value while has to be an integer. An intuitive and popular method is applying the round operation:
However, detailed analysis results in a slightly different formulation. The mapped value should be 0 for the range of. And for, for,...., and finally for. Then the quantization formula from to should be

On color images

The above-described histogram equalization works on a grayscale image. It can also be used on color images. One option is applying the method separately to the red, green and blue components of the RGB color values of the image, which likely produces dramatic changes in the image's color balance since the relative distributions of the color channels change as a result of applying the algorithm. However, if the image is first converted to another color space, Lab, or HSL/HSV in particular, then the algorithm can be applied to the luminance or value channel without resulting in changes to color properties of the image.
There are several histogram equalization methods in 3D space which result in whitening, i.e., the probability of bright pixels is higher than that of dark ones. Han et al. proposed to use a new CDF defined by the ISO-luminance plane, which results in uniform gray distribution.

Examples

The operation equalization process is best demonstrated with a small image. A full-sized image demonstrates the overall results achievable using the process.

Small image

The 8-bit grayscale image shown has the following values:
5255615979617661
62595510494855971
6365661131441046372
6470701261541097169
677368106122886868
6879607077665875
6985645855616583
7087696865737890

The histogram for this image is shown in the following table. Pixel values that have a zero count are excluded for the sake of brevity.
The cumulative distribution function is shown below. Again, pixel values that do not contribute to an increase in the function are excluded for brevity.
This CDF shows that the minimum value in the subimage is 52 and the maximum value is 154. The CDF of 64 for value 154 coincides with the number of pixels in the image. The CDF must be normalized to. The general histogram equalization formula is:
where is the minimum non-zero value of the cumulative distribution function, gives the image's number of pixels and is the number of grey levels used.
Note that to scale values in the original data that are above 0 to the range 1 to '', inclusive, the above equation would instead be:
where cdf > 0. Scaling from 1 to 255 preserves the non-zero-ness of the minimum value.''
The equalization formula for the example scaling data from 0 to 255, inclusive, is:
For example, the CDF of 78 is 46. The normalized value becomes:
Once this is done, then the values of the equalized image are directly taken from the normalized CDF to yield the equalized values:
01253321905317453
57321222721920232154
65859323925122765158
73146146247255235154130
97166117231243210117117
117190361461789320170
1302027320125385194
14620613011785166182215

Notice that the minimum value 52 is now 0 and the maximum value 154 is now 255.