【发布时间】:2017-11-28 21:28:34
【问题描述】:
我有一个小项目,所以一周前我开始在 Python 上做一些测试。我必须显示 rgb 图像的 3 个通道,但 pyplot.imshow() 函数显示以下内容:
我想显示红色、绿色和蓝色通道,如下所示:
这是我的代码,到目前为止:
from matplotlib import pyplot as plt
from PIL import Image
import numpy as np
img1 = np.array(Image.open('img1.png'))
figure, plots = plt.subplots(ncols=3, nrows=1)
for i, subplot in zip(range(3), plots):
temp = np.zeros(img1.shape, dtype='uint8')
temp = img1[:,:,i]
subplot.imshow(temp)
subplot.set_axis_off()
plt.show()
我不在任何笔记本上工作。相反,我在 PyCharm 工作。我读了这篇文章:24739769。我检查了img1.dtype 是uint8,所以我不知道如何展示我想要的东西。
【问题讨论】:
-
嗨@Abraham Gutierrez,欢迎来到SO。我了解您没有足够的声誉在帖子中发布图片,但是,在未来,请这样做。如果人们不必去外部页面,他们更有可能查看您的问题。
img1.shape、temp.min()和temp.max()是什么?另外,您能否发布原始图像以便我们重现您的错误? -
对不起。我使用了图像按钮,但编辑器将它们作为链接。 img1.shape 是加载图像的尺寸,据我所知(x,y,rgb 通道)。 min() 和 max() 函数分别返回任何数组/矩阵的最小值和最大值。
标签: python image numpy matplotlib rgb