python: want to display red channel only in opencv

后端 未结 2 442
北恋
北恋 2020-12-25 13:15

I am beginner in image processing. I am showing image in many color space the below code show the image in the 3 channels R G B however the image displayed in the gray layou

2条回答
  •  感动是毒
    2020-12-25 13:43

    You can just make a copy of the original image and set some channels to 0.

    import cv2
    
    image = cv2.imread('download.jpg')
    
    b = image.copy()
    # set green and red channels to 0
    b[:, :, 1] = 0
    b[:, :, 2] = 0
    
    
    g = image.copy()
    # set blue and red channels to 0
    g[:, :, 0] = 0
    g[:, :, 2] = 0
    
    r = image.copy()
    # set blue and green channels to 0
    r[:, :, 0] = 0
    r[:, :, 1] = 0
    
    
    # RGB - Blue
    cv2.imshow('B-RGB', b)
    
    # RGB - Green
    cv2.imshow('G-RGB', g)
    
    # RGB - Red
    cv2.imshow('R-RGB', r)
    
    cv2.waitKey(0)
    

提交回复
热议问题