scipy.misc module has no attribute imread?

匿名 (未验证) 提交于 2019-12-03 02:30:02

问题:

I am trying to read an image with scipy. However it does not accept the scipy.misc.imread part. What could be the cause of this?

>>> import scipy >>> scipy.misc  >>> scipy.misc.imread('test.tif') Traceback (most recent call last):   File "", line 1, in      scipy.misc.imread('test.tif') AttributeError: 'module' object has no attribute 'imread' 

回答1:

You need to install Pillow (formerly PIL). From the docs on scipy.misc:

Note that Pillow is not a dependency of SciPy but the image manipulation functions indicated in the list below are not available without it:

...

imread

...

After installing Pillow, I was able to access imread as follows:

In [1]: import scipy.misc  In [2]: scipy.misc.imread Out[2]: 


回答2:

You need the Python Imaging Library (PIL) but alas! the PIL project seems to have been abandoned. In particular, it hasn't been ported to Python 3. So if you want PIL functionality in Python 3, you'll do well do use Pillow, which is the semi-official fork of PIL and appears to be actively developed. Actually, if you need a modern PIL implementation at all I'd recommend Pillow. It's as simple as pip install pillow. As it uses the same namespace as PIL it's essentially a drop-in replacement.

How "semi-official" is this fork? you may ask. The About page of the Pillow docs say this:

As more time passes since the last PIL release, the likelihood of a new PIL release decreases. However, we’ve yet to hear an official “PIL is dead” announcement. So if you still want to support PIL, please report issues here first, then open corresponding Pillow tickets here.

Please provide a link to the first ticket so we can track the issue(s) upstream.

However, the most recent PIL release on the official PIL site is dated November 15, 2009. I think we can safely proclaim Pillow as the successor of PIL after (as of this writing) nearly eight years of no new releases. So even if you don't need Python 3 support, I suggest you eschew the ancient PIL 1.1.6 distribution available in PyPI and just install fresh, up-to-date, compatible Pillow.



回答3:

Imread uses PIL library, if the library is installed use : "from scipy.ndimage import imread"

Source: http://docs.scipy.org/doc/scipy-0.17.0/reference/generated/scipy.ndimage.imread.html



回答4:

imread is deprecated in SciPy 1.0.0, and will be removed in 1.2.0. Use imageio.imread instead.

import imageio im = imageio.imread('astronaut.png') im.shape  # im is a numpy array (512, 512, 3) imageio.imwrite('imageio:astronaut-gray.jpg', im[:, :, 0]) 


回答5:

python -m pip install pillow 

This worked for me.



回答6:

Install the Pillow library by following commands:

pip install pillow 

Note, the selected answer has been outdated. See the docs of SciPy

Note that Pillow (https://python-pillow.org/) is not a dependency of SciPy, but the image manipulation functions indicated in the list below are not available without it.



回答7:

You need a python image library (PIL), but now PIL only is not enough, you'd better install Pillow. This works well.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!