[英]How to split colour channels in openCV without returning a gray scale image? I have tried the following it returns a gray scale image
How to split colour channels in openCV without returning a gray scale image? 如何在openCV中拆分颜色通道而不返回灰度图像? I have tried the following it returns a gray scale image? 我已经尝试了以下它返回灰度图像?
import cv2
import numpy as np
img = cv2.imread("1.jpeg")
(channel_b, channel_g, channel_r) = (img[:,:,0], img[:,:,1], img[:,:,2])
cv2.imshow('red',channel_b)
cv2.waitKey(0)
cv2.destroyAllWindows()
The thing is, that the seperate channels do not really have a color assigned to them. 事实是,单独的通道实际上没有分配颜色。
If you use imshow
to display an image of dimensions (m, n, 3)
the method assumes that the 3 channels are representing R, G and B. However if it gets an image of dimensions (m, n, 1)
or (m, n)
it assumes that there is no color in the image and it is displayed as gray scale. 如果使用imshow
显示尺寸为(m, n, 3)
的图像,则该方法假定3个通道代表R,G和B。但是,如果获得的图像尺寸为(m, n, 1)
或(m, n)
假定图像中没有颜色,并以灰度显示。
In conclusion this means that there is nothing wrong with your seperation of the channels, imshow
just doesn't know, that the values in channel_r
are the red part of an image. 总之,这意味着通道分离没有什么问题, imshow
只是不知道, channel_r
中的值是图像的红色部分。
If you really want to display only the red part, you can do the following: 如果您确实只想显示红色部分,则可以执行以下操作:
red = np.zeros(img.shape)
red[:,:,2] = img[:,:,2]
cv2.imshow('red', red)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.