【问题标题】:Skimage simple imread of image return strange output图像的 Skimage 简单读取返回奇怪的输出
【发布时间】:2014-07-28 04:00:27
【问题描述】:

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

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

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

In [49]: im
Out[49]: array(<PIL.PngImagePlugin.PngImageFile image mode=RGB size=512x512 at 0
x35FBD00>, dtype=object)

In [50]: im.shape
Out[50]: ()

In [51]: im.size
Out[51]: 1

现在我无法理解 - 为什么 im 的形状不是 (512,512,3) ? 这段代码是我使用的一个更大程序的一部分,当某些函数试图通过访问 im.shape[2] 来计算颜色通道的数量时出现错误。

我正在添加一个具有预期输出的参考: 请参阅http://scipy-lectures.github.io/packages/scikit-image/ 第 3.2.2.2 段

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

【问题讨论】:

    标签: python image numpy multidimensional-array


    【解决方案1】:

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

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

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

    然后尝试重新启动您的 python shell 并再次运行命令。

    【讨论】:

      猜你喜欢
      • 2016-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-23
      • 2023-03-02
      相关资源
      最近更新 更多