合并渠道会导致opencv中的伪造

时间:2018-12-25 15:16:15

标签: python opencv

我先分离出RGB图片,然后在每个通道上进行阈值处理,然后合并3个通道时,就会出现如下图所示的假象。 enter image description here

 b, g, r = cv2.split(image)
    r = cv2.threshold(r, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
    g = cv2.threshold(g, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
    b = cv2.threshold(b, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
    rgb_image = cv2.merge([b, g, r])

    k = cv2.getStructuringElement(cv2.MORPH_RECT, (15, 15))
    blackhat = cv2.morphologyEx(rgb_image, cv2.MORPH_BLACKHAT, k)

    mask = cv2.inRange(rgb_image, (225, 225, 225), (255, 255, 255))

    # dst = np.dstack((frame, 255-mask))
    dst = np.dstack((rgb_image, mask))


    cv2.imshow('lo', dst)
    cv2.waitKey()

0 个答案:

没有答案