How to apply CLAHE to RGB color images

CLAHE Contrast Limited Adaptive Bar Graph. The equation and source in C can be found at http://tog.acm.org/resources/GraphicsGems/gemsiv/clahe.c

So far I have only seen a few examples / guides on using CLAHE on grayscale images, so is it possible to apply CLAHE on color images (e.g. RGB 3 images)? If so, how?

+6
source share
2 answers

Converting RGB to LAB (L for lightness and a and b for color opponents green-red and blue-yellow) will do the job. Apply CLAHE to the converted LAB image only to the Lightness component and convert the image to RGB. Here is a snippet.

bgr = cv2.imread(image_path) lab = cv2.cvtColor(bgr, cv2.COLOR_BGR2LAB) lab_planes = cv2.split(lab) clahe = cv2.createCLAHE(clipLimit=2.0,tileGridSize=(gridsize,gridsize)) lab_planes[0] = clahe.apply(lab_planes[0]) lab = cv2.merge(lab_planes) bgr = cv2.cvtColor(lab, cv2.COLOR_LAB2BGR) 

bgr is the final RGB image obtained after applying CLAHE.

+7
source

you can just split the RGB channels into R, G, B and apply CLAHE on each channel, here is the code:

 vector<Mat> RGB; // Use the STL's vector structure to store multiple Mat objects split(frame, RGB); // split the image into separate color planes (RGB) //// Enhance Local Contrast (CLAHE) Mat RGB_eq; //// Equalizes the histogram of a one channel image (8UC1) using Contrast Limited Adaptive Histogram Equalization. clahe->apply(RGB[0],RGB[0]); clahe->apply(RGB[1],RGB[1]); clahe->apply(RGB[2],RGB[2]); merge(RGB,RGB_eq); // now merge the results back 
-2
source

Source: https://habr.com/ru/post/973008/


All Articles