Data Standardization——直方图均衡化与自适应直方图均衡化python实现

直方图均衡化

img = cv2.imread('图片路径')
b,g,r = cv2.split(img)
b_equ = cv2.equalizeHist(b)
g_equ = cv2.equalizeHist(g)
r_equ = cv2.equalizeHist(r)
img = cv2.merge([b_equ,g_equ,r_equ]).astype(np.uint8)
cv2.imwrite('保存路径',img,[cv2.IMWRITE_PNG_COMPRESSION, 0])

自适应直方图均衡化

img = cv2.imread('图片路径')
b,g,r = cv2.split(img)
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
b_clahe = clahe.apply(b)
g_clahe = clahe.apply(g)
r_clahe = clahe.apply(r)
img = cv2.merge([b_clahe,g_clahe,r_clahe]).astype(np.uint8)

cv2.imwrite('保存路径',img,[cv2.IMWRITE_PNG_COMPRESSION, 0])

实验

找了几张遥感影像做实验,第一行为原图,第二行为直方图均衡化,第三行为自适应直方图均衡化

你可能感兴趣的:(图像处理,python,opencv,计算机视觉,图像处理)