License YOLO
Back to Ultralytics Glossary

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.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Turn drone and aerial imagery into real-time insights for agriculture, aquaculture, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Apply computer vision in aerospace with Ultralytics YOLO for aircraft inspection, runway FOD detection, airport ground operations, and composite defect detection.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning