Open CV的图像均衡化处理

import cv2 as cv2
import matplotlib.pyplot as plt
import  numpy as np
def cv_show(name,img):
    cv2.imshow(name,img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()


if __name__ == "__main__":

    # 直方图的均衡化操作
    img = cv2.imread(r'E:\iu.png', 0)  # 读取整图,灰度图的形式
    hist = cv2.calcHist([img], [0], None, [256], [0, 256])  # 参数含义,从左至右,图像、通道数、掩码数、bin的数目,色彩范围
    equ = cv2.equalizeHist(img)
    # plt.subplot(121),plt.hist(img.ravel(),256)
    # plt.subplot(122), plt.hist(equ.ravel(), 256)
    # plt.show()
    # 直方图的自适应均衡化操作
    zishiying = cv2.createCLAHE(clipLimit=2.0,tileGridSize=(8,8))
    zishiying_jieguo = zishiying.apply(img)
    res = np.hstack((img,equ,zishiying_jieguo))
    cv_show('res',res)

与原图比对的2种结果:

Open CV的图像均衡化处理_第1张图片

 

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