Histogram Equalization
Histogram equalization remaps pixel intensities to improve image contrast. Global and adaptive methods, including CLAHE, use different mappings.
Histogram equalization is an image processing technique that improves contrast by remapping pixel intensities based on how often they occur. In a low-contrast grayscale image, many pixels occupy a narrow range of gray levels. Equalization gives frequently occupied intensity ranges more room, making subtle differences easier to see. It changes pixel values while leaving the image dimensions and pixel positions intact.
How Histogram Equalization Works#
An intensity histogram counts how many pixels fall into each bin. For an 8-bit grayscale image, a standard histogram has 256 equal-width bins, one for each intensity from 0 to 255. Global equalization adds up those counts from darkest to brightest and divides each running total by the number of pixels. The result is the cumulative distribution function (CDF): the fraction of pixels at or below each intensity. The equalizer uses the CDF to build a lookup table of output intensities. Where the CDF rises quickly, neighboring levels spread apart. Where it rises slowly, they stay close together.
An equalized histogram counts the remapped pixels. It can still have gaps and peaks because every pixel with the same input value moves to the same output level under a global mapping. This also explains why equalization cannot recover detail where a camera clipped several distinct shades to pure white. In 1974, Ernest L. Hall analyzed why the method, already in use at the time, yields an approximately uniform distribution on digital images.
The mapping depends on pixel frequencies. Linear contrast stretching instead scales a chosen intensity interval uniformly, and histogram matching remaps intensities to follow a reference distribution.
Global Equalization, AHE, and CLAHE#
Global equalization uses a single mapping for the whole image. In the OpenCV statue example, that improves background contrast while washing out detail on the statue's face. Adaptive histogram equalization (AHE) computes mappings from local neighborhoods, so bright and dark regions can receive different adjustments. In smooth areas, that local adjustment can make sensor noise more visible.
Contrast-limited adaptive histogram equalization (CLAHE) curbs noise amplification by clipping large histogram counts and redistributing the excess before computing each local mapping. Tile-based implementations blend neighboring mappings to avoid visible seams. Stephen Pizer and colleagues described clipped AHE in 1987, and Karel Zuiderveld published a CLAHE implementation in 1994. For color images, applying equalization to the lightness channel of a color space such as Lab helps avoid the color shifts that can result from remapping red, green, and blue independently.
Histogram Equalization in Python#
With opencv-python, scikit-image, and matplotlib installed, this example compares both methods on scikit-image's bundled Moon photograph. OpenCV's equalizeHist takes an 8-bit grayscale image, subtracts the first nonzero CDF value before scaling to 0–255, and leaves a constant image unchanged. For CLAHE, tileGridSize=(8, 8) means eight tiles across and eight down, while clipLimit controls how strongly local contrast amplification is limited.
import cv2
import matplotlib.pyplot as plt
from skimage import data
image = data.moon()
global_eq = cv2.equalizeHist(image)
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
local_eq = clahe.apply(image)
# Use the same display range for all three images.
_, axes = plt.subplots(1, 3)
panels = [(image, "Original"), (global_eq, "Global"), (local_eq, "CLAHE")]
for ax, (pixels, title) in zip(axes, panels):
ax.imshow(pixels, cmap="gray", vmin=0, vmax=255)
ax.set_title(title)
ax.axis("off")
plt.show()The global result spreads the dominant gray tones across the photo. The CLAHE result brings out differences in the lunar surface by adjusting contrast separately in different regions.
How Vision Models Use Equalization#
As fixed preprocessing, equalization uses the same method and settings during training, validation, and inference. As data augmentation, it is applied randomly during training to expose the model to contrast variation without moving bounding boxes or masks. Ultralytics YOLO's Albumentations integration applies CLAHE with a default probability of 1% in supported training pipelines such as object detection when Albumentations is installed.
An ablation study can isolate the effect of equalization by comparing it with an unprocessed baseline on the same held-out images. In a retinal vessel segmentation study, James Owler and Peter Rockett used the unprocessed green channel of retinal photographs as the baseline. In the CLAHE condition, they equalized only that channel before feeding it into a modified U-Net.










