代码之家  ›  专栏  ›  技术社区  ›  Atinesh

使用OpenCV直方图均衡时出现问题

  •  1
  • Atinesh  · 技术社区  · 6 年前

    我想用 Contrast Limited Adaptive Histogram Equalisation (CLAHE)在 OpenCV

    错误 enter image description here

    代码

    import cv2 as cv
    from matplotlib import pyplot as plt
    
    imgG = cv.imread('sample.png')
    
    clahe = cv.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
    imgC  = clahe.apply(imgG)
    
    fig = plt.figure(figsize = (20,20))
    ax  = fig.add_subplot(111)
    ax.imshow(imgC, cmap='gray')
    plt.show()
    

    猜猜为什么会这样

    1 回复  |  直到 6 年前
        1
  •  1
  •   ZdaR    6 年前

    错误表明: (-215) _src.type() == CV_8UC1 || _src.type() == 16UC1 ,这基本上意味着 clahe.apply() 可以是一个 单通道 8位矩阵或 16位矩阵。这个 1 cv.imread('sample.png') ,因此默认情况下,它读取3通道BGR图像。你可以用 cv.imread('sample.png', 0) img = cv.cvtColor(img, cv.COLOR_BGR2GRAY) 看完图像后。