zinon zinon - 2 months ago 17
Python Question

OpenCV python: Show images in channel's color and not in grayscale

I read an rgb image

img = cv2.imread('image.jpg')


I split channels:

b,g,r = cv2.split(img)


When I'm trying to show red image I get a grayscale image. Can I see it in red?

cv2.imshow('Red image',r)

Answer

Make blue and green channels of all zeroes, and merge these with your red channel. Then you will see just the red channel displayed in red.

Or you could just set the b and g channels of the image to 0.

img[:,:,0] = 0
img[:,:,1] = 0
Comments