scipy.misc.imread创建一个没有大小或形状的图像 [英] scipy.misc.imread creates an image with no size or shape

查看:537
本文介绍了scipy.misc.imread创建一个没有大小或形状的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

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或im​​age.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.

我在另一台机器上的同一图像上使用完全相同的代码并得到明智的结果:

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)

(顺便提一下,当我打印图像时好的机器,它显示为一个uint8数组而不是一个对象数组。)

(And incidentally, when I print image on the good machine, it shows as an array of uint8 instead of an array of objects).

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

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). I'm running in a virtual environment using venv.

任何人都知道发生了什么?我是否严重安装了PIL?或者

Anyone know what's going on? Have I installed PIL badly, or something?

推荐答案

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

Solved! Libjpeg wasn't installed when I installed PIL. 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

这篇关于scipy.misc.imread创建一个没有大小或形状的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆