python - 如何从 RGB 图像中提取单个 channel

标签 python image opencv image-processing signal-processing

我发现 opencv 文档使用 cv2.split (img) 命令从 RGB 图像中提取单个 channel ,但它并没有真正返回所选 channel 的图像。它们看起来都像灰度。有人能帮我吗?我附上照片。

b = img[:,:,0]
g = img[:,:,1]
r = img[:,:,2]

or

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

起始图片 = enter image description here 提取的红色 channel = enter image description here

提取正确吗? 全红 channel -img在哪?

最佳答案

提取的红色 channel 可能看起来像灰度图像,但它是正确的。它只是一个二维数组,其值在 [0,255] 范围内。要可视化特定 channel ,您需要将其他 channel 设置为零。所以要显示红色 channel ,需要将蓝色和绿色 channel 设置为零。

import cv2

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

# Set blue and green channels to 0
img[:,:,0] = 0
img[:,:,1] = 0

cv2.imshow('red_img', img)
cv2.waitKey()

enter image description here

关于python - 如何从 RGB 图像中提取单个 channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57398643/

相关文章:

Python:读取文件并将其转换为字典,其中第一行+第二行是关键

android - 检查花园要求后,Buildozer 无法编译平台

html - 在 Bootstrap 网格系统中居中图像

android - 在android上强制覆盖相机图像

python - 如何使用python返回mysql查询结果

python - os.system() 使用 python 执行的 Ruby 脚本

javascript - 需要 Jquery 幻灯片中的图像作为链接

opencv - OpenCV cv::resize()可以更改图像的最小值和最大值吗? (使用INTER_LINEAR方法)

c++ - 将新的 cv::Mat 送入 vx_graph

python - 多进程视频处理