OpenCv3--Python3.6(second)通道分离与合并

ps.当三个通道的值相同时,则为灰度图

def split_and_combine(image):
  #  img = cv.copyTo(image)
    b,g,r = cv.split(image)
    cv.imshow("blue",b)
    cv.imshow("green",g)
    cv.imshow("red",r)
    z = np.zeros([image.shape[0],image.shape[1]],np.uint8)
    b_r = cv.merge([b,z,r])
    b_g = cv.merge([b,g,z])
    g_r = cv.merge([z,g,r])
    #或者 直接对通道进行操作
    image[:,:,1] = 0
    '''
    cv.imshow("blue and red",b_r)
    cv.imshow("blue and green",b_g)
    cv.imshow("green and red",g_r)
    '''
    cv.imshow("b+r",image)

这里有两种形式对通道的值进行操作,应该能看出来吧

你可能感兴趣的:(Opencv-Python)