21 May Histogram Equalization (CLAHE) with OpenCV
Normal Histogram Equalization works on the whole image, while CLAHE (Contrast Limited Adaptive Histogram Equalization) works on small regions for better results. It enhances image contrast by stretching the intensity range.
Contrast Limited Adaptive Histogram Equalization (CLAHE) is an advanced version of histogram equalization that improves local contrast in images while limiting noise amplification.
What is CLAHE
CLAHE differs from standard histogram equalization in two key ways:
- Adaptive: It operates on small regions of the image (tiles) rather than the entire image
- Contrast Limited: It limits contrast amplification to reduce noise in homogeneous regions
When to Use CLAHE
CLAHE is particularly useful for:
- Medical imaging (X-rays, CT scans)
- Satellite/aerial imagery
- Low-contrast images
- Images with varying illumination conditions
The method helps reveal details in both dark and bright regions of an image while preventing over-amplification of noise.
Here’s how to use CLAHE with OpenCV in Python:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import cv2 # Load image in grayscale image = cv2.imread(r'C:\Users\hp\Downloads\Astronaut.png', 0) # 0 for grayscale # Simple Histogram Equalization equalized = cv2.equalizeHist(image) # CLAHE (better for local contrast) clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8)) clahe_img = clahe.apply(image) # Display results cv2.imshow("Original", image) cv2.imshow("Equalized (Global)", equalized) cv2.imshow("CLAHE (Local)", clahe_img) cv2.waitKey(0) cv2.destroyAllWindows() |
Output
Parameters of the createCLAHE() function
- clipLimit: Threshold for contrast limiting (default 40.0)
- tileGridSize: Size of the grid for histogram equalization (default 8×8)
If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.
For Videos, Join Our YouTube Channel: Join Now
Read More:
- Apply Sepia Tone filter with OpenCV
- Generative AI Tutorial
- Machine Learning Tutorial
- Deep Learning Tutorial
- Ollama Tutorial
- Retrieval Augmented Generation (RAG) Tutorial
- Copilot Tutorial
- Gemini Tutorial
- ChatGPT Tutorial
No Comments