scipy.misc模块没有属性读取?

问题:scipy.misc模块没有属性读取?

我正在尝试读取图像。但是,它不接受该scipy.misc.imread零件。这可能是什么原因?

>>> import scipy
>>> scipy.misc
<module 'scipy.misc' from 'C:\Python27\lib\site-packages\scipy\misc\__init__.pyc'>
>>> scipy.misc.imread('test.tif')
Traceback (most recent call last):
  File "<pyshell#11>", line 1, in <module>
    scipy.misc.imread('test.tif')
AttributeError: 'module' object has no attribute 'imread'

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
<module 'scipy.misc' from 'C:\Python27\lib\site-packages\scipy\misc\__init__.pyc'>
>>> scipy.misc.imread('test.tif')
Traceback (most recent call last):
  File "<pyshell#11>", line 1, in <module>
    scipy.misc.imread('test.tif')
AttributeError: 'module' object has no attribute 'imread'

回答 0

您需要安装Pillow(以前称为PIL)。从在文档scipy.misc

请注意,Pillow不是SciPy的依赖项,但是如果没有它,下面列表中指示的图像处理功能将不可用:

imread

安装Pillow后,我可以imread如下访问:

In [1]: import scipy.misc

In [2]: scipy.misc.imread
Out[2]: <function scipy.misc.pilutil.imread>

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]: <function scipy.misc.pilutil.imread>

回答 1

imread在SciPy 1.0.0中已弃用,在1.2.0中将被删除。使用imageio.imread代替。

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])

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])

回答 2

版本1.2.0之后,imread贬值!因此,要解决此问题,我必须安装版本1.1.0。

pip install scipy==1.1.0

imread is depreciated after version 1.2.0! So to solve this issue I had to install version 1.1.0.

pip install scipy==1.1.0

回答 3

对于Python 3,最好是使用imreadmatplotlib.pyplot

from matplotlib.pyplot import imread

For Python 3, it is best to use imread in matplotlib.pyplot:

from matplotlib.pyplot import imread

回答 4

如果有人遇到相同的问题,请卸载scipy并安装scipy == 1.1.0

$ pip uninstall scipy

$ pip install scipy==1.1.0

In case anyone encountering the same issue, please uninstall scipy and install scipy==1.1.0

$ pip uninstall scipy

$ pip install scipy==1.1.0

回答 5

您需要Python Imaging Library(PIL),但是but!PIL项目似乎已被放弃。特别是,它尚未移植到Python3。因此,如果要在Python 3中使用PIL功能,则最好使用Pillow,它是PIL的半官方分支,并且正在积极开发中。实际上,如果您完全需要现代的PIL实现,我建议您选择Pillow。就像一样简单pip install pillow。由于它使用与PIL相同的命名空间,因此实质上是直接替代。

这个叉子有多“半官方”?你可能会问。“ 枕头”文档的“ 关于”页面说:

自上次发布PIL之后,随着时间的流逝,新发布PIL的可能性降低。但是,我们尚未听到官方的“ PIL已死”声明。因此,如果您仍然希望支持PIL,请先在此处报告问题,然后在此处打开相应的枕头票。

请提供第一张票证的链接,以便我们可以跟踪上游问题。

但是,PIL 官方站点上的最新PIL版本发布于2009年11月15日。我认为,在将近八年没有新版本发布之时,我们可以肯定地说Pillow是PIL的继承者。因此,即使您不需要Python 3支持,我也建议您避免使用PyPI中可用的古老PIL 1.1.6发行版,而只需安装新的,最新的,兼容的Pillow。

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.


回答 6

通过以下命令安装枕头库:

pip install pillow

请注意,所选答案已过时。查看SciPy的文档

请注意,Pillow(https://python-pillow.org/)不是SciPy的依赖项,但如果没有它,则下面列表中指示的图像处理功能将不可用。

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

答案是:misc.imread在SciPy 1.0.0中已弃用,在1.2.0中将被删除。imageio是一个选项,它将返回类型为object的对象:

<class 'imageio.core.util.Image'>

但要使用image2,而不要使用imageio

import cv2
im = cv2.imread('astronaut.png')

我将是类型: <class 'numpy.ndarray'>

由于numpy数组的计算速度更快。

As answered misc.imread is deprecated in SciPy 1.0.0, and will be removed in 1.2.0. imageio is one option,it will return object of type :

<class 'imageio.core.util.Image'>

but instead of imageio, use cv2

import cv2
im = cv2.imread('astronaut.png')

im will be of type : <class 'numpy.ndarray'>

As numpy arrays are faster to compute.


回答 8

Imread使用PIL库,如果已安装该库,则使用:“ from scipy.ndimage import imread”

资料来源:http : //docs.scipy.org/doc/scipy-0.17.0/reference/generated/scipy.ndimage.imread.html

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


回答 9

python -m pip install pillow

这对我有用。

python -m pip install pillow

This worked for me.


回答 10

您需要一个python图像库(PIL),但是现在仅PIL还不够,您最好安装Pillow。这很好。

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


回答 11

在Jupyter Notebook中运行以下命令,我收到了类似的错误消息:

from skimage import data
photo_data = misc.imread('C:/Users/ers.jpg')
type(photo_data)

“错误”消息:

D:\ Program Files(x86)\ Microsoft Visual Studio \ Shared \ Anaconda3_64 \ lib \ site-packages \ ipykernel_launcher.py:3:DeprecationWarning:已imread弃用!imread在SciPy 1.0.0中已弃用,在1.2.0中将被删除。使用imageio.imread 代替。这与ipykernel软件包分开,因此我们可以避免导入,直到

并使用以下我解决了:

import matplotlib.pyplot
photo_data = matplotlib.pyplot.imread('C:/Users/ers.jpg')
type(photo_data)

Running the following in a Jupyter Notebook, I had a similar error message:

from skimage import data
photo_data = misc.imread('C:/Users/ers.jpg')
type(photo_data)

‘error’ msg:

D:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\ipykernel_launcher.py:3: DeprecationWarning: imread is deprecated! imread is deprecated in SciPy 1.0.0, and will be removed in 1.2.0. Use imageio.imread instead. This is separate from the ipykernel package so we can avoid doing imports until

And using the following I got it solved:

import matplotlib.pyplot
photo_data = matplotlib.pyplot.imread('C:/Users/ers.jpg')
type(photo_data)

回答 12

我在jupyter笔记本上具有图像提取所需的所有软件包,但即使如此,它仍然显示相同的错误。

Jupyter Notebook上的错误

阅读以上评论,我已经安装了必需的软件包。请告诉我是否错过了一些包裹。

pip3 freeze | grep -i -E "pillow|scipy|scikit-image"
Pillow==5.4.1
scikit-image==0.14.2

scipy==1.2.1

I have all the packages required for the image extraction on jupyter notebook, but even then it shows me the same error.

Error on Jupyter Notebook

Reading the above comments, I have installed the required packages. Please do tell if I have missed some packages.

pip3 freeze | grep -i -E "pillow|scipy|scikit-image"
Pillow==5.4.1
scikit-image==0.14.2

scipy==1.2.1

回答 13

在python 3.6中为我工作的解决方案如下

py -m pip安装枕头

The solution that work for me in python 3.6 is the following

py -m pip install Pillow