📜  CLAHE 直方图均衡 - OpenCV

📅  最后修改于: 2022-05-13 01:54:23.696000             🧑  作者: Mango

CLAHE 直方图均衡 - OpenCV

在本教程中,我们将了解如何应用对比度受限自适应直方图均衡 (CLAHE)来均衡图像。 CLAHE 是自适应直方图均衡 (AHE)的一种变体,它负责对比度的过度放大。 CLAHE 对图像中的小区域(称为图块)而不是整个图像进行操作。然后使用双线性插值组合相邻的瓦片以去除人为边界。
该算法可用于提高图像的对比度。

我们还可以将CLAHE应用于彩色图像,通常应用于亮度通道,仅均衡HSV图像的亮度通道后的结果比均衡BGR图像的所有通道要好得多。
在本教程中,我们将学习如何应用 CLAHE 并处理给定的输入图像以进行直方图均衡化。

以上代码:

Python3
import cv2
import numpy as np
 
# Reading the image from the present directory
image = cv2.imread("image.jpg")
# Resizing the image for compatibility
image = cv2.resize(image, (500, 600))
 
# The initial processing of the image
# image = cv2.medianBlur(image, 3)
image_bw = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
 
# The declaration of CLAHE
# clipLimit -> Threshold for contrast limiting
clahe = cv2.createCLAHE(clipLimit = 5)
final_img = clahe.apply(image_bw) + 30
 
# Ordinary thresholding the same image
_, ordinary_img = cv2.threshold(image_bw, 155, 255, cv2.THRESH_BINARY)
 
# Showing all the three images
cv2.imshow("ordinary threshold", ordinary_img)
cv2.imshow("CLAHE image", final_img)


输入图像:

输入图像

输出:

普通门槛

CLAHE应用