python: want to display red channel only in opencv

后端 未结 2 439
北恋
北恋 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:32

    import cv2
    import numpy as np
    
    channel_initials = list('BGR')
    
    image = cv2.imread('download.jpg')
    
    for channel_index in range(3):
        channel = np.zeros(shape=image.shape, dtype=np.uint8)
        channel[:,:,channel_index] = image[:,:,channel_index]
        cv2.imshow(f'{channel_initials[channel_index]}-RGB', channel)
    cv2.waitKey(0)
    

提交回复
热议问题