Illumination Enhancement using CLAHE
Theory
CLAHE (Contrast Limited Adaptive Histogram Equalization) is a technique for enhancing image contrast, especially useful for low-light images. Unlike global histogram equalization, CLAHE prevents over-amplification of noise by working on small regions of the image and limiting contrast.
Key Concepts
- Local Enhancement: Works on small tiles instead of the whole image, enhancing details locally.
- Clip Limit: Prevents noise amplification by limiting the maximum contrast.
- Tile Grid Size: Determines the size of small regions (tiles) for localized enhancement.
- Luminance Channel Only: CLAHE is applied to the Y channel in
YCrCbcolor space to maintain natural colors.
Python Code
import cv2
# Step 1: Load low-light image
img = cv2.imread('assets/lowlight.jpg', cv2.IMREAD_COLOR)
# Step 2: Convert to YCrCb (luminance + chrominance)
ycrcb = cv2.cvtColor(img, cv2.COLOR_BGR2YCrCb)
# Step 3: Create CLAHE object
clahe = cv2.createCLAHE(clipLimit=5.0, tileGridSize=(8, 8))
# Step 4: Apply CLAHE only to Y channel
ycrcb[:, :, 0] = clahe.apply(ycrcb[:, :, 0])
# Step 5: Convert back to BGR color space
result = cv2.cvtColor(ycrcb, cv2.COLOR_YCrCb2BGR)
# Display images
cv2.imshow('Original', img)
cv2.imshow('Enhanced', result)
cv2.waitKey(0)
cv2.destroyAllWindows()
Input Image
Output Image