【问题标题】:scipy.misc.imread creates an image with no size or shapescipy.misc.imread 创建一个没有大小或形状的图像
【发布时间】:2013-05-12 19:31:42
【问题描述】:

我正在尝试让 scipy.misc.imread 读取图像并告诉我它的大小,我已经能够在其他计算机上做得很好,但在新 Mac 上对我来说却失败了:

Python 2.7.4 (default, May 16 2013, 16:40:58) 
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.65))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy.misc
>>> scipy.__version__
'0.11.0'
>>> image = scipy.misc.imread('test.jpg')
>>> image
array(<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=870x1110 at 0x10BEC3F80>, dtype=object)
>>> image.size
1
>>> image.shape
()

所以图像已加载,尺寸 (870x1110) 似乎存在,但是当我执行 image.size 或 image.shape 时,我得到了垃圾。

我在另一台机器上的同一张图片上使用完全相同的代码并获得了合理的结果:

>>> image.size
237456
>>> image.shape
(318,249,3)

(顺便说一句,当我在好机器上打印图像时,它显示为 uint8 数组而不是对象数组)。

坏机器是 Mac,运行 Mountain Lion,带有 python 2.7.4 和 scipy 版本 0.11(我从 0.12 降级,以防出现问题)。我正在使用 venv 在虚拟环境中运行。

有人知道发生了什么吗?我是不是把 PIL 安装得不好,还是怎么回事?

【问题讨论】:

    标签: python image scipy python-imaging-library


    【解决方案1】:

    解决了!我安装 PIL 时没有安装 Libjpeg。所以我这样做了:

    pip uninstall PIL
    brew install libjpeg
    pip install PIL
    

    它有效。我从这里得到了提示:

    https://stackoverflow.com/a/12194881/11522

    【讨论】:

    • 我遇到了同样的问题,但是使用 PNG,我需要安装 libpng 吗?我在 Windows 上使用 PIL。
    猜你喜欢
    • 1970-01-01
    • 2013-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多