简体   繁体   English

scipy.misc.imread创建一个没有大小或形状的图像

[英]scipy.misc.imread creates an image with no size or shape

I'm trying to get scipy.misc.imread to just read in an image and tell me it size, which I've been able to do fine on other computers but it's failing for me on a new Mac: 我试图让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
()

So the image is loaded, and the size (870x1110) seems to be present, but when I do image.size or image.shape I get garbage. 所以图像被加载,大小(870x1110)似乎存在,但是当我做image.size或im​​age.shape时,我得到了垃圾。

I use the exact same code on the same image on another machine and get sensible results: 我在另一台机器上的相同图像上使用完全相同的代码并获得合理的结果:

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

(And incidentally, when I print image on the good machine, it shows as an array of uint8 instead of an array of objects). (顺便说一句,当我在好机器上打印图像时,它显示为uint8的数组而不是对象数组)。

The bad machine is a Mac, running Mountain Lion, with python 2.7.4 and scipy version 0.11 (I downgraded from 0.12 in case that was the problem). 糟糕的机器是Mac,运行Mountain Lion,python 2.7.4和scipy版本0.11(如果问题,我从0.12降级)。 I'm running in a virtual environment using venv. 我正在使用venv在虚拟环境中运行。

Anyone know what's going on? 有谁知道发生了什么? Have I installed PIL badly, or something? 我是否严重安装了PIL,或者其他什么?

Solved! 解决了! Libjpeg wasn't installed when I installed PIL. 安装PIL时没有安装Libjpeg。 So I did this: 所以我这样做了:

pip uninstall PIL
brew install libjpeg
pip install PIL

and it works. 它的工作原理。 I got the hint from here: 我从这里得到了提示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM