OPENCV – PYTHON | Adaptive Histogram Equalization | AHE & CLAHE | Coding + Demo | AHE drawbacks
Enhancing image contrast is a critical step in image processing, especially when dealing with uneven lighting conditions or images with varying intensities. Adaptive Histogram Equalization (AHE) and Contrast Limited Adaptive Histogram Equalization (CLAHE) are powerful techniques that dynamically adjust the contrast of an image, improving visibility and feature extraction. In this article, we explore the implementation of AHE and CLAHE using OpenCV in Python, accompanied by detailed explanations and mathematical insights.
Flow of Article:
- Understanding Adaptive Histogram Equalization
- Understanding Contrast Limited – AHE
- Coding both the AHE and CLAHE
- Understanding their uses and drawbacks
Video Explanation:
Adaptive Histogram Equalization (AHE):
AHE is an extension of the traditional histogram equalization method, designed to adaptively enhance local contrast in an image. Unlike global histogram equalization, which applies a single transformation to the entire image, AHE divides the image into smaller regions and independently equalizes the histogram of each region. This adaptive approach is particularly beneficial for images with varying lighting conditions or complex textures.
Mathematical Explanation:
The transformation function TT for AHE can be expressed as follows:
import cv2
# Load image in grayscale
img = cv2.imread(‘image.jpg’, 0)
# Apply Adaptive Histogram Equalization (AHE)
ahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
ahe_result = ahe.apply(img)
# Display the results
cv2.imshow(‘Original Image’, img)
cv2.imshow(‘AHE Result’, ahe_result)
cv2.waitKey(0)
cv2.destroyAllWindows()
Contrast Limited Adaptive Histogram Equalization (CLAHE):
While AHE significantly improves local contrast, it may lead to undesirable amplification of noise in some cases. CLAHE addresses this issue by limiting the contrast enhancement. It introduces a clip limit, beyond which pixel intensities are redistributed to prevent excessive amplification of local contrast. CLAHE is particularly useful for ensuring controlled enhancement without sacrificing image quality.
Mathematical Explanation:
The transformation function TT for CLAHE is similar to AHE but incorporates a clip limit (LL) to prevent overly aggressive contrast enhancement:
import cv2
# Load image in grayscale
img = cv2.imread(‘image.jpg’, 0)
# Apply Contrast Limited Adaptive Histogram Equalization (CLAHE)
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
clahe_result = clahe.apply(img)
# Display the results
cv2.imshow(‘Original Image’, img)
cv2.imshow(‘CLAHE Result’, clahe_result)
cv2.waitKey(0)
cv2.destroyAllWindows()
AHE Drawbacks:
While AHE and CLAHE significantly improve contrast, they come with certain drawbacks:
Noise Amplification:
- AHE, especially in regions with low contrast, may amplify noise, leading to undesirable artifacts.
Over-enhancement:
- In some cases, AHE may over-enhance local contrast, resulting in unnatural-looking images.
Computational Complexity:
- AHE involves processing each local region independently, leading to increased computational complexity, especially for large images.
Artifacting at Tile Boundaries:
- CLAHE, due to its local processing, may introduce visible artifacts at the boundaries of tiles.
Uses of AHE and CLAHE in practical Sense:
Applications and Use Cases of Adaptive Histogram Equalization (AHE) and Contrast Limited Adaptive Histogram Equalization (CLAHE)
1. Medical Imaging:
AHE and CLAHE: In medical imaging, where subtle details are crucial, AHE and CLAHE find applications in enhancing the visibility of structures such as tumors, blood vessels, and tissue boundaries. The adaptive nature of these techniques is particularly beneficial in handling variations in image intensity across different medical imaging modalities.
[Learn more about AHE in medical imaging]
2. Satellite Image Processing:
Processing satellite imagery often involves dealing with variations in lighting conditions and terrain. AHE and CLAHE help improve the contrast of these images, making it easier to identify and analyze specific features such as land cover, water bodies, and urban areas.
[Explore AHE and CLAHE in satellite image processing]()
3. Retinal Image Analysis:
CLAHE: In ophthalmology, CLAHE has shown promise in enhancing the contrast of retinal images. This is especially valuable for detecting subtle changes in the retina, aiding in the diagnosis of conditions like diabetic retinopathy and glaucoma.
[Read about CLAHE in retinal image enhancement]
4. Remote Sensing and Geospatial Analysis:
AHE and CLAHE: Remote sensing applications, including geospatial analysis, benefit from the improved contrast offered by AHE and CLAHE. These techniques enhance the visual interpretation of satellite and aerial imagery, aiding in land cover classification, environmental monitoring, and disaster assessment.
[Learn about AHE in remote sensing]
Incorporating AHE and CLAHE in various domains enhances the interpretability and analysis of digital images, making them indispensable tools in fields where image quality and feature visibility are paramount.
Aryan Verma blog, infoaryan, infoaryan.com, image processing tutorials, opencv, Clahe, Ahe, histogram equalization, opencv, computer vision projects, computer vision tutorials, image processing, aryan verma, python projects, python opencv full explained hindi, easy opencv, aryan verma