Clahe:Contrast Limited Adaptive Histogram Equalization 对比度受限的自适应直方图均衡化
Clahe的理论解释:
Clahe理论详解1
Clahe理论详解2
1.函数 cv2.createCLAHE
c v 2. c r e a t e C L A H E ( c l i p L i m i t = N o n e , t i l e G r i d S i z e = N o n e ) {cv2.createCLAHE(clipLimit=None, tileGridSize=None)} cv2.createCLAHE(clipLimit=None,tileGridSize=None)
c l i p L i m i t {clipLimit} clipLimit:对比度限制阈值;
t i l e G r i d S i z e {tileGridSize} tileGridSize:用于直方图均衡化的网格大小。输入图像将被分割成大小相等的矩形块。tileGridSize定义行和列中的块数;
2.灰度图
from PIL import Imageimport matplotlib.pyplot as pltimport numpy as npimport cv2test = Image.open('./tupian/test4.png').convert('L')test = np.uint8(test)test_hist = cv2.equalizeHist(test)clahe = cv2.createCLAHE(clipLimit=4, tileGridSize=(10,5))test_clahe = clahe.apply(test)plt.figure()plt.subplot(1,3,1),plt.imshow(test, 'gray')plt.axis('off'),plt.title('原图')plt.subplot(1,3,2),plt.imshow(test_hist, 'gray')plt.axis('off'),plt.title('直方图均衡化')plt.subplot(1,3,3),plt.imshow(test_clahe, 'gray')plt.axis('off'),plt.title('Clahe')plt.show()
3.RGB图
from PIL import Imageimport matplotlib.pyplot as pltimport numpy as npimport cv2img = Image.open('./tupian/test5.jpg').convert('RGB')img = np.uint8(img)imgr = img[:,:,0]imgg = img[:,:,1]imgb = img[:,:,2]claher = cv2.createCLAHE(clipLimit=3, tileGridSize=(10,18))claheg = cv2.createCLAHE(clipLimit=2, tileGridSize=(10,18))claheb = cv2.createCLAHE(clipLimit=1, tileGridSize=(10,18))cllr = claher.apply(imgr)cllg = claheg.apply(imgg)cllb = claheb.apply(imgb)rgb_img = np.dstack((cllr,cllg,cllb))plt.subplot(1,2,1),plt.imshow(img)plt.title('原图'),plt.axis('off')plt.subplot(1,2,2),plt.imshow(rgb_img)plt.title('Clahe'),plt.axis('off')plt.show()
RGB图实验可见:Clahe具有一定的去雾效果
如果觉得《【图像增强】灰度图与RGB图Clahe的python实现》对你有帮助,请点赞、收藏,并留下你的观点哦!