Histogram Equalization – Step-by-Step Explanation
Histogram equalization is a contrast enhancement technique in image processing. It works by redistributing the intensity values of an image so that the histogram of the output image becomes more uniform. This improves the visual quality and highlights details, especially in low-contrast images.
Step 1: Compute the Histogram of the Image
Count the number of pixels for each possible intensity level (e.g., 0–255 for an 8-bit image):
h(I) = number of pixels with intensity I
Step 2: Normalize the Histogram to a Probability Distribution
Let N be the total number of pixels. Compute the normalized histogram:
p(I) = h(I) / N
Step 3: Compute the Cumulative Distribution Function (CDF)
Calculate the cumulative sum of the probabilities:
c(I) = c(I - 1) + p(I)
This gives the percentile rank of each pixel intensity.
Step 4: Create the Mapping Function
Map each original intensity I to a new value based on the CDF:
f(I) = round(c(I) × (L - 1))
- L = total number of possible intensity values (e.g., 256)
- f(I) = new intensity value for each pixel
Step 5: Apply the Mapping to All Pixels
For every pixel in the image with intensity I, replace it with:
g(x, y) = f(f(x, y))
This results in the histogram-equalized image.
Step 6: Optional – Partial Histogram Equalization
To avoid over-enhancement or unnatural appearance, blend the original and equalized values:
f(I) = α × c(I) + (1 - α) × I
- α = 1: full equalization
- α = 0: no equalization
- 0 < α < 1: partial equalization
Step 7: Output the Equalized Image
Use the mapping to transform the entire image. The resulting image will have improved contrast, with a histogram closer to uniform.