Histogram Equalization «2026 Update»

import cv2 # Load the image in grayscale img = cv2.imread('input.jpg', 0) # Apply Histogram Equalization equ = cv2.equalizeHist(img) # Save the result cv2.imwrite('output.jpg', equ) Use code with caution. Conclusion

The represents the number of pixels for each intensity level.

If an image is "low contrast," its histogram will be bunched up in a narrow region—either all dark (underexposed), all light (overexposed), or all gray (washed out). Histogram Equalization takes that narrow "clump" and stretches it across the entire available spectrum (0–255). 2. How the Algorithm Works histogram equalization

Whether you are working in medical imaging, satellite photography, or computer vision, HE is often the first step in making hidden details visible to both the human eye and machine learning algorithms. 1. The Core Concept: What is a Histogram?

Count the occurrences of each pixel intensity. import cv2 # Load the image in grayscale img = cv2

To solve the limitations mentioned above, engineers developed more sophisticated versions:

In images where the foreground and background are both dark (like an X-ray or a night-time security feed), HE can bring out textures and shapes that were previously invisible. To solve the limitations mentioned above

Divide the count of each intensity by the total number of pixels in the image.

Instead of calculating one histogram for the whole image, it divides the image into small squares (tiles) and equalizes them individually.

It serves as a normalization tool. If you are training a neural network to recognize objects, equalizing the histograms of your training data ensures that the model isn't confused by varying lighting conditions.