CLAHE Histogram Equalization – OpenCV
Last Updated :
19 May, 2023
In this tutorial, we are going to learn how to apply CLAHE and process a given input image for histogram equalization. In this tutorial, we are going to see how to apply Contrast Limited Adaptive Histogram Equalization (CLAHE) to equalize images. CLAHE is a variant of Adaptive histogram equalization (AHE) which takes care of over-amplification of the contrast. CLAHE operates on small regions in the image, called tiles, rather than the entire image. The neighboring tiles are then combined using bilinear interpolation to remove the artificial boundaries.
This algorithm can be applied to improve the contrast of images. We can also apply CLAHE to color images, where usually it is applied on the luminance channel and the results after equalizing only the luminance channel of an HSV image are much better than equalizing all the channels of the BGR image.
Parameters:
When applying CLAHE, there are two parameters to be remembered:
- clipLimit – This parameter sets the threshold for contrast limiting. The default value is 40.
- tileGridSize – This sets the number of tiles in the row and column. By default this is 8×8. It is used while the image is divided into tiles for applying CLAHE.
Example:
Python3
import cv2
import numpy as np
image = cv2.imread( "image.jpg" )
image = cv2.resize(image, ( 500 , 600 ))
image_bw = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
clahe = cv2.createCLAHE(clipLimit = 5 )
final_img = clahe. apply (image_bw) + 30
_, ordinary_img = cv2.threshold(image_bw, 155 , 255 , cv2.THRESH_BINARY)
cv2.imshow( "ordinary threshold" , ordinary_img)
cv2.imshow( "CLAHE image" , final_img)
|
Input image:
input image
Output:
Ordinary Threshold
CLAHE Applied
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...