美文网首页
(二)OpenCV通道分离与合并

(二)OpenCV通道分离与合并

作者: zqyadam | 来源:发表于2020-02-25 13:05 被阅读0次

通道分离

方法1:

使用cv2.split函数分离B、G、R三个通道,分离的顺序就是B、G、R

    img = cv2.imread('lena.jpg')
    b,g,r = cv2.split(img)
    # 创建几个空白图
    img_blue = np.zeros(img.shape, dtype=np.uint8)
    img_green = np.zeros(img.shape, dtype=np.uint8)
    img_red = np.zeros(img.shape, dtype=np.uint8)
    # 分别赋值b,g,r
    img_blue[:,:,0] = b
    img_green[:,:,1] = g
    img_red[:,:,2] = r
    
    cv2.imshow('channel split', np.hstack((img_blue, img_green, img_red)))
        
    cv2.waitKey(0)
    cv2.destroyAllWindows()

方法2

b = img[:, :, 0]
g = img[:, :, 1]
r = img[:, :, 2]
cv2.split

通道合并

合并通道可以直接使用函数cv2.merge

merged = cv2.merge((b, g, r))
cv2.imshow('Merged', merged)
cv2.merge

相关文章

网友评论

      本文标题:(二)OpenCV通道分离与合并

      本文链接:https://www.haomeiwen.com/subject/oeozqhtx.html