简体   繁体   English

如何在openCV中拆分颜色通道而不返回灰度图像? 我尝试了以下返回灰度图像的方法

[英]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.

相关问题 Python绘制灰度值与图像像素的关系 - Python plot gray scale value vs pixel of an image 如何在django中使用opencv将彩色图像转换为灰色图像 - How to convert color image to gray image using opencv in django 在python中使用用户定义的转换功能将灰度图像转换回rgb图像时出现问题 - Problem in converting a gray scale image back to an rgb image with user defined transformation function in python 无法在opencv python中将图像转换为灰色 - Cannot convert an image to gray in opencv python 如何使用多个子目录中的系列的灰度图像创建4维ndarray - How to create a 4 dimentional ndarray with the gray scale images of the series in the multiple subdirectories Opencv Mog2 背景减法器:Output 是灰度图像 - Opencv Mog2 Background subtractor: Output is a gray image 从 1 个通道到 3 个通道的灰度图像,2 个额外的通道仅由零构成 - Gray scaled image from 1 channel to 3 channels, with the 2 extra channels made only by zeros Python 将 3 通道 rgb 彩色图像更改为 1 通道灰色的速度有多快? - How fast in Python change 3 channel rgb color image to 1 channel gray? 如何从 my.png 图像中删除灰色背景 - How remove the gray background from my .png image 如何缩小喀拉拉邦图像金字塔的图像? - How to down scale image in keras for an image pyramid?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM