1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#均衡化处理
# equalizeHist()
import cv2
import matplotlib.pyplot as plt
import numpy as np
img = cv2.imread("dm.png",0)
plt.hist(img.ravel(),256)
plt.show()

#均衡化(全部,会丢失局部自己的特征)
equ = cv2.equalizeHist(img)
plt.hist(equ.ravel(),256)
plt.show()


res = np.hstack((img,equ))
cv2.imshow('res',res)
cv2.waitKey(0)


#自适应直方图均衡化(分成好几块做,最后在整合到一块)
clahe = cv2.createCLAHE(clipLimit=2.0,tileGridSize=(8,8))

res_clahe = clahe.apply(img)
res2 = np.vstack((img,equ,res_clahe))
cv2.imshow('res_img_equ_clahe',res2)
#cv2.imwrite('res_img_equ_clahe.png',res2)
cv2.waitKey(0)

均衡化前:左 均衡化后:右

image-20230304174526524

均衡化前:

image-20230304174656444

均衡化后:

image-20230304174711720

全局均衡化:左 自适应直方图均衡化:右

image-20230304174946166