Image Processing & Filtering

histogram equalization

Histogram equalization is a contrast-enhancement trick that redistributes pixel intensities so that the histogram spreads out to fill the whole tonal range as evenly as possible. Intuitively, if all your pixels are crammed into a narrow band of mid-greys, the image looks flat and washed out; equalization stretches and reshapes that band so dark areas get darker, bright areas get brighter, and crowded intensity levels are pulled apart, revealing hidden detail.

The remarkable insight is that the transform you need is the image's own cumulative distribution function. You map each old intensity i to a new intensity T(i) = round((L-1) * CDF(i)), where CDF(i) is the fraction of pixels at or below i and L is the number of levels. This works because applying a random variable's own CDF as a function produces an (approximately) uniform distribution: levels where many pixels are clustered have a steeply rising CDF, so they get spread across a wide output range, while empty levels are compressed. The mapping is monotonic, so brighter pixels stay brighter, preserving rank order. Because intensities are discrete, the result is only approximately flat, not perfectly uniform.

Plain global equalization has two failure modes: it amplifies noise in nearly flat regions, and it ignores local context so a region that is dark relative to its surroundings may be left untouched. Adaptive histogram equalization fixes this by equalizing within small tiles, but that over-amplifies noise even more. The standard cure is CLAHE (contrast-limited adaptive histogram equalization): it clips each tile's histogram at a chosen height before equalizing (redistributing the clipped mass), which caps contrast amplification, then bilinearly interpolates between tiles to remove block boundaries. CLAHE is a workhorse in medical and low-light imaging.

On a foggy low-contrast X-ray whose intensities cluster in levels 100-150, equalization remaps that narrow band across 0-255, so a faint hairline fracture invisible before becomes clearly separated from surrounding bone.

Pitfall: global equalization can produce harsh, unnatural results and amplify sensor noise into visible grain, because stretching empty histogram regions also stretches the noise living there. Reach for CLAHE when local contrast matters or noise is a concern.

Also called
HECLAHE (contrast-limited adaptive histogram equalization)