Learn how to enhance the contrast of RGB color images effectively using Contrast Limited Adaptive Histogram Equalization (CLAHE) with this comprehensive guide.
This article provides a step-by-step guide on how to enhance the contrast of an image using Contrast Limited Adaptive Histogram Equalization (CLAHE) technique in Python. We will use the OpenCV library for image processing.
import cv2image = cv2.imread('image.jpg')lab_image = cv2.cvtColor(image, cv2.COLOR_BGR2LAB)l_channel, a_channel, b_channel = cv2.split(lab_image)clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))enhanced_l_channel = clahe.apply(l_channel)enhanced_lab_image = cv2.merge((enhanced_l_channel, a_channel, b_channel))enhanced_image = cv2.cvtColor(enhanced_lab_image, cv2.COLOR_LAB2BGR)cv2.imshow('Enhanced Image', enhanced_image)
cv2.waitKey(0)
cv2.destroyAllWindows()or
cv2.imwrite('enhanced_image.jpg', enhanced_image)Explanation:
clipLimit parameter limits the amplification of contrast.tileGridSize parameter defines the size of the tiles used for histogram equalization.This Python code uses the OpenCV library to enhance the contrast of an image. It reads an image, converts it to LAB color space, applies Contrast Limited Adaptive Histogram Equalization (CLAHE) to the lightness channel, merges the channels back, converts the image back to BGR color space, and finally displays or saves the enhanced image.
import cv2
# Load the image
image = cv2.imread('image.jpg')
# Convert the image from RGB to LAB color space
lab_image = cv2.cvtColor(image, cv2.COLOR_BGR2LAB)
# Split the LAB image into its channels
l_channel, a_channel, b_channel = cv2.split(lab_image)
# Create a CLAHE object
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
# Apply CLAHE to the L channel
enhanced_l_channel = clahe.apply(l_channel)
# Merge the enhanced L channel with the A and B channels
enhanced_lab_image = cv2.merge((enhanced_l_channel, a_channel, b_channel))
# Convert the enhanced LAB image back to RGB color space
enhanced_image = cv2.cvtColor(enhanced_lab_image, cv2.COLOR_LAB2BGR)
# Display the enhanced image
cv2.imshow('Enhanced Image', enhanced_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
# Alternatively, save the enhanced image
# cv2.imwrite('enhanced_image.jpg', enhanced_image)Explanation:
This code effectively enhances the contrast of an image while preserving its colors using the CLAHE algorithm.
General:
Parameters:
clipLimit:
tileGridSize:
Implementation Details:
createCLAHE() function: This function initializes the CLAHE algorithm with the specified parameters.Applications:
Further Exploration:
clipLimit and tileGridSize values to observe their effects on the enhanced image.This code snippet demonstrates how to enhance the contrast of an image using Contrast Limited Adaptive Histogram Equalization (CLAHE) technique with OpenCV in Python.
Here's a breakdown of the process:
cv2.imread().cv2.cvtColor(). This is done because CLAHE is applied only on the luminance channel (L channel) to avoid amplifying color noise.cv2.split().clipLimit (controls contrast amplification) and tileGridSize (defines tile size for histogram equalization).clahe.apply().cv2.merge() to reconstruct the image.cv2.cvtColor().cv2.imshow() or save it to a file using cv2.imwrite().Key Points:
clipLimit and tileGridSize parameters allow fine-tuning the contrast enhancement.In conclusion, this article elucidated the process of enhancing image contrast using the CLAHE algorithm in Python with the OpenCV library. By focusing on the luminance channel in the LAB color space, CLAHE effectively amplifies contrast while preserving color integrity. The article provided a step-by-step code breakdown, explained key parameters, and highlighted the advantages of CLAHE over traditional histogram equalization techniques. The insights provided equip readers with the knowledge to implement and fine-tune CLAHE for various applications, including medical imaging, microscopy, and object detection, ultimately improving image clarity and detail visibility.
Color Image Histogram CLAHE with OpenCV - FreedomVC | Contrast Limited Adaptive Histogram Equalization (CLAHE) - a color image histogram improvement method that improves over global equalization
CLAHE for color image OpenCV 3.0 - OpenCV Q&A Forum | Feb 1, 2016 ... use of clahe but it only works for grayscale image (even though I ... rgb Here but "split" doesn't work and I do not know what is theĀ ...
adapthisteq | Examples Ā· Apply Contrast-Limited Adaptive Histogram Equalization (CLAHE) Ā· Apply CLAHE to Indexed Color Image.
The output of CLAHE applied on RGB color model. | Download ... | Download scientific diagram | The output of CLAHE applied on RGB color model. from publication: Performing Contrast Limited Adaptive Histogram Equalization Technique on Combined Color Models for Underwater Image Enhancement | This paper describes method to improve the visibility of underwater images. Using Contrast Limited Adaptive Histogram Equalization (CLAHE) technique, our method derives the enhanced image from combination of outputs performed on RGB color model and HSV color model that is... | Equalization, Histogram and Image Enhancement | ResearchGate, the professional network for scientists.
Adaptive Touch to Histogramsā CLAHE | by Muhammed Nur Talha ... | A Comprehensive Look at Histogram and Its Implementationsā¦
CLAHE for Quapth - Image Analysis - Image.sc Forum | Hi Everyone, I came across this paper : Protocol for high-plex, whole-slide imaging of human formalin-fixed paraffin-embedded tissue using PhenoCycler-Fusion. Redirecting In the paragraph below they mentioned using CALHE I am familar with the CALHE method using openCv but the output is a png image which loses all the information when I open it in Quapth. Does anyone have any idea how itās been done for Quapth?
Transforms (augmentations.transforms) - Albumentations ... | Albumentations provides a comprehensive, high-performance framework for augmenting images to improve machine learning models. Ideal for computer vision applications, supporting a wide range of augmentations.