tezvyn:

Histogram Equalization: Spreading Out Pixel Brightness

AI-drafted, machine-checkedSource: Wikipedia: Histogram equalizationbeginner
Histogram Equalization: Spreading Out Pixel Brightness

Think of histogram equalization as automatically stretching an image's contrast. It takes dark or washed-out images and spreads their pixel brightness values across the full available range, revealing hidden details. The footgun: it can amplify noise.

WHY IT EXISTS: Many images suffer from poor contrast. A photo taken in low light might have all its pixels clustered in the dark range, while a hazy photo might have them all in the mid-tones. This makes it hard for humans and algorithms to discern details. Histogram equalization was created to automatically correct this by redistributing pixel intensities.

THE MENTAL MODEL: Imagine an image's brightness levels are people crowded into a few rooms of a large house, while most rooms are empty. Histogram equalization is an usher that spreads the people out evenly across all available rooms. The goal isn't to change the people, but to make better use of the entire house, which is the full 0-255 brightness range. This reveals details previously hidden in the crowd.

HOW IT WORKS: The process works on the image's histogram, a count of how many pixels exist at each brightness level (0 for black to 255 for white). It calculates a running total, the cumulative distribution function (CDF), which tells you the number of pixels at or below a certain brightness. This CDF is then used as a lookup table to map each original pixel value to a new one. This stretches out the most populated brightness ranges and compresses the empty ones, forcing the output histogram to be as flat as possible.

WHEN TO USE IT: It is a powerful, automatic method for contrast enhancement when you have no prior knowledge of the image's content. It's widely used as a preprocessing step in applications like medical imaging to make X-rays clearer, in satellite imagery to pierce through haze, and to normalize images before feeding them to a machine learning model.

WHEN NOT TO USE IT: Its biggest weakness is that it's a global, "dumb" operation. If an image already has good contrast, equalization can ruin it by creating an unnatural, washed-out look. More importantly, it can dramatically amplify noise. A dark region with subtle sensor noise can become a distracting, grainy mess after equalization. For these cases, adaptive methods like CLAHE (Contrast Limited Adaptive Histogram Equalization) are often a better choice.

ONE CANONICAL EXAMPLE: Take a dark, underexposed portrait. The original histogram is a single large spike on the left (dark) side of the graph. After applying histogram equalization, the histogram is spread across the entire range. The resulting image is much brighter, and details in the face, hair, and background that were lost in shadow become clearly visible.

Read the original → en.wikipedia.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.