如何使用python查看给定图像的RGB通道?

如何使用python查看给定图像的RGB通道?,python,image,image-processing,rgb,Python,Image,Image Processing,Rgb,想象一下,我有一个图像,我想分割它,看看RGB通道。如何使用python实现这一点?我最喜欢的方法是使用。它构建在numpy/scipy之上,图像内部存储在numpy阵列中 你的问题有点模糊,所以很难回答。我不知道你到底想做什么,但我会给你看一些代码 测试图像: 我会用 代码: 输出: 评论 输出看起来不错:例如黄色的花,它有很多绿色和红色,但没有多少蓝色,这与维基百科的方案兼容: 到目前为止,你做过什么研究吗?哇,谢谢,这不完全是我需要的,但这真的很有趣。很抱歉说得含糊不清,我的意思是

想象一下,我有一个图像,我想分割它,看看RGB通道。如何使用python实现这一点?

我最喜欢的方法是使用。它构建在numpy/scipy之上,图像内部存储在numpy阵列中

你的问题有点模糊,所以很难回答。我不知道你到底想做什么,但我会给你看一些代码

测试图像: 我会用

代码: 输出:

评论
  • 输出看起来不错:例如黄色的花,它有很多绿色和红色,但没有多少蓝色,这与维基百科的方案兼容:

到目前为止,你做过什么研究吗?哇,谢谢,这不完全是我需要的,但这真的很有趣。很抱歉说得含糊不清,我的意思是我想为每一个项目做一个柱状图channels@JuanTelo你本可以提到这个。。。好。。。我把它添加到代码中了。我有一个类似的问题。你能调查一下吗?
import skimage.io as io
import matplotlib.pyplot as plt

# Read
img = io.imread('Photodisc.png')

# Split
red = img[:, :, 0]
green = img[:, :, 1]
blue = img[:, :, 2]

# Plot
fig, axs = plt.subplots(2,2)

cax_00 = axs[0,0].imshow(img)
axs[0,0].xaxis.set_major_formatter(plt.NullFormatter())  # kill xlabels
axs[0,0].yaxis.set_major_formatter(plt.NullFormatter())  # kill ylabels

cax_01 = axs[0,1].imshow(red, cmap='Reds')
fig.colorbar(cax_01, ax=axs[0,1])
axs[0,1].xaxis.set_major_formatter(plt.NullFormatter())
axs[0,1].yaxis.set_major_formatter(plt.NullFormatter())

cax_10 = axs[1,0].imshow(green, cmap='Greens')
fig.colorbar(cax_10, ax=axs[1,0])
axs[1,0].xaxis.set_major_formatter(plt.NullFormatter())
axs[1,0].yaxis.set_major_formatter(plt.NullFormatter())

cax_11 = axs[1,1].imshow(blue, cmap='Blues')
fig.colorbar(cax_11, ax=axs[1,1])
axs[1,1].xaxis.set_major_formatter(plt.NullFormatter())
axs[1,1].yaxis.set_major_formatter(plt.NullFormatter())
plt.show()

# Plot histograms
fig, axs = plt.subplots(3, sharex=True, sharey=True)

axs[0].hist(red.ravel(), bins=10)
axs[0].set_title('Red')
axs[1].hist(green.ravel(), bins=10)
axs[1].set_title('Green')
axs[2].hist(blue.ravel(), bins=10)
axs[2].set_title('Blue')

plt.show()