import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
img = cv.imread("../SampleImages/cat.jpg", cv.IMREAD_GRAYSCALE)
print(img.shape)
#整幅图像做普通的直方图均衡化
img_hist_equalized = cv.equalizeHist(img)
#图像直方图自适应均衡化
#1. 创建CLAHE对象
#cv.createCLAHE( clipLimit=40,tileGridSize=(8,8))
#参考资料:https://blog.csdn.net/juzicode00/article/details/121663922
clahe = cv.createCLAHE(2,(10,10))
#2. 应用直方图自适应均衡化
#clahe.apply(img)
img_clahe = clahe.apply(img)
#显示图像
fig,axes = plt.subplots(nrows=1, ncols=3, figsize=(10,10), dpi=100)
axes[0].set_title("Original")
axes[0].imshow(img, cmap=plt.cm.gray)
axes[1].set_title("Equalized")
axes[1].imshow(img_hist_equalized, cmap=plt.cm.gray)
axes[2].set_title("CLAHE")
axes[2].imshow(img_clahe, cmap=plt.cm.gray)