如何在opencv中使用matlab imadjust函数?

时间:2018-09-06 19:22:02

标签: python opencv

我想通过使用opencv来提高图像的对比度。但是,opencv中的对比调整功能无法提供我想要的功能。在Matlab中,不调整功能非常适合我的图像。因此,opencv中的imadjust对应什么?

1 个答案:

答案 0 :(得分:1)

我认为您正在寻找。请尝试使用此代码,并让我知道它是否无效。

    import cv2

    img = cv2.imread("Image_path", 1)

    cv2.imshow("Original image",img)

    # CLAHE (Contrast Limited Adaptive Histogram Equalization)
    clahe = cv2.createCLAHE(clipLimit=1., tileGridSize=(1,1))

    lab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)  # convert from BGR to LAB color space
    l, a, b = cv2.split(lab)  # split on 3 different channels

    l2 = clahe.apply(l)  # apply CLAHE to the L-channel

    lab = cv2.merge((l2,a,b))  # merge channels
    img2 = cv2.cvtColor(lab, cv2.COLOR_LAB2BGR)  # convert from LAB to BGR
    img3 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
    cv2.imwrite('Increased_Contrast.jpg', img3)
    cv2.imshow('Increased contrast', img3)


    cv2.waitKey(0)
    cv2.destroyAllWindows()