opencv-直方图均衡化

对图像进行非线性拉伸,重新分配图像像素值,使一定灰度范围内像素值的数量大致相等。输出图像的直方图是一个较平的分段直方图,从而提高图像的对比度。

def Hist():
    img = cv2.imread('./data/timg.jpg', 0)  # 直接读为灰度图像
    res = cv2.equalizeHist(img)

    clahe = cv2.createCLAHE(clipLimit=2, tileGridSize=(10, 10))
    cl1 = clahe.apply(img)

    plt.subplot(131), plt.imshow(img, 'gray')
    plt.subplot(132), plt.imshow(res, 'gray')
    plt.subplot(133), plt.imshow(cl1, 'gray')
    plt.show()

    plt.hist(img.ravel(), 256, [0, 256])
    plt.hist(res.ravel(), 256, [0, 256])
    plt.hist(cl1.ravel(), 256, [0, 256])
    plt.show()

 灰度值的统计图


 

猜你喜欢

转载自blog.csdn.net/fanzonghao/article/details/81256385