gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 21:07:01 24 4
gpt4 key购买 nike

我发现 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com