In the previous section, we saw how image histograms provide a summary of the intensity distribution within an image. Often, images captured in the real world might suffer from poor contrast, meaning their pixel intensities are concentrated within a narrow range. This can happen due to poor lighting conditions, limitations of the imaging sensor, or specific scene characteristics. Such images can appear washed out or overly dark, making details hard to discern.
Histogram equalization is an automatic technique designed to improve the global contrast of an image by effectively spreading out the most frequent intensity values. It aims to redistribute the pixel intensities so that they are distributed as uniformly as possible across the entire available intensity range (typically 0 to 255 for an 8-bit grayscale image).
Imagine a grayscale image where most pixels are clustered around mid-gray values. Its histogram would show a large peak in the middle and very few pixels at the dark and bright ends. The goal of histogram equalization is to stretch this narrow range of intensities to cover the full spectrum from black to white.
How does it achieve this? It does so by transforming the intensity of each pixel based on the image's overall intensity distribution. The core idea relies on the Cumulative Distribution Function (CDF) of the image's histogram.
The histogram tells us the frequency (or count) of pixels at each intensity level. The CDF, at a given intensity level k, represents the cumulative sum of frequencies for all intensity levels up to and including k. Essentially, it tells us the proportion of pixels in the image that are darker than or equal to intensity k.
For an image with L possible intensity levels (e.g., L=256 for 8-bit grayscale, levels 0,1,...,L−1), let nk be the number of pixels with intensity k, and N be the total number of pixels in the image. The normalized histogram value (probability of intensity k) is p(k)=nk/N.
The discrete CDF is calculated as: CDF(k)=∑j=0kp(j) This CDF(k) value ranges from p(0) (for k=0) up to 1 (for k=L−1).
Histogram equalization uses this CDF to map an input pixel intensity k to a new output intensity k′. The transformation function T(k) is essentially the scaled CDF value:
k′=T(k)=round((L−1)×CDF(k))
Here, L−1 is the maximum possible intensity value (e.g., 255). The round()
function ensures the output is an integer intensity level.
What this transformation does is map pixels in densely populated intensity regions (where the histogram is high, and the CDF slope is steep) to a wider range of output intensities. Conversely, pixels in sparsely populated regions (where the histogram is low, and the CDF slope is shallow) get mapped to a narrower range of output intensities. The overall effect is a histogram that is more spread out, ideally closer to a uniform distribution, leading to enhanced global contrast.
Illustration of histogram equalization. A low-contrast histogram (blue bars) with a steeply rising CDF (blue dashed line) is transformed into a more spread-out histogram (green bars) with a more linear CDF (green dashed line), covering a wider intensity range.
Histogram equalization is particularly effective for images where:
However, it's not a perfect solution for every image:
In summary, histogram equalization is a fundamental and often useful technique for automatically improving the contrast of an image by redistributing its pixel intensity values based on the cumulative distribution function. While powerful, it's important to be aware of its potential drawbacks, such as noise amplification and its global nature.
© 2025 ApX Machine Learning