略读图像简单读入返回奇怪的输出

2024-04-26 11:51:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用skimage模块的图像读取,无法理解我得到的输出。 我在读一个简单的rgb图像“列娜.png“通过以下方式:

from skimage import io
im = io.imread('lena.png')

我得到的输出具有以下属性:

^{pr2}$

现在我不明白为什么im的形状不是(512512,3)? 这段代码是我使用的一个更大程序的一部分,当一些函数试图通过访问来计算颜色通道的数量时,我得到了一个错误im.形状[2] 一。在

我添加了一个具有预期输出的引用: 见第3.2.2.2段

>>> lena = data.lena()
>>> lena.shape
(512, 512, 3)

Tags: 模块fromio图像import属性png方式
1条回答
网友
1楼 · 发布于 2024-04-26 11:51:21

这个错误(imread返回一个PIL.PngImagePlugin.PngImageFile类而不是数据数组)经常发生在您安装了旧版本的python映像库pillow或更糟的版本时。pillow是{}的更新的“友好”分支,绝对值得安装!在

尝试更新这些包;(取决于python发行版)

# to uninstall PIL (if it's there, harmless if not)
$ pip uninstall PIL
# to install (or -U update) pillow
$ pip install -U pillow

然后尝试重新启动pythonshell并再次运行命令。在

相关问题 更多 >