我有一个Numpy数组类型的矩阵.我如何将其作为图像写入磁盘?任何格式都有效(png,jpeg,bmp ......).一个重要的限制是PIL不存在.
我之前和其他人见过这个问题,但还没有找到解决办法.
我所要做的就是:
from scipy.misc import imread
我明白了
/home1/users/joe.borg/<ipython-input-2-f9d3d927b58f> in <module>()
----> 1 from scipy.misc import imread
/software/Python/272/lib/python2.7/site-packages/scipy/misc/__init__.py in <module>()
16 try:
17 from pilutil import *
---> 18 __all__ += pilutil.__all__
19 except ImportError:
20 pass
NameError: name 'pilutil' is not defined
Run Code Online (Sandbox Code Playgroud)
但是当我from pilutil import *自己做的时候没有问题(没有导入错误).甚至....../site-packages/scipy/misc/pilutil.py存在,所以我不知道为什么会失败.
我是python的新手,我想导入图像。
import numpy as np
from scipy.misc import imread, imsave, imresize
# Read an JPEG image into a numpy array
img = imread('Cover.jpg')
print(img.dtype, img.shape)
Run Code Online (Sandbox Code Playgroud)
但是我遇到以下错误:cannot import name 'imread'
我已经成功安装了numpy和scipy。
在执行以下代码时:
scipy.misc.toimage(output * 255, high=255, low=0, cmin=0, cmax=255).save(
params.result_dir + 'final/%5d_00_%d_out.png' % (test_id, ratio))
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
AttributeError: 模块 'scipy.misc' 没有属性 'toimage'
我尝试按照此处所述安装 Pillow:scipy.misc module has no attribute imread? 但同样的错误仍然存在。请帮忙。谢谢。
我已安装(实际重新安装)scipy:
10_x86_64.whl (19.8MB): 19.8MB downloaded
Installing collected packages: scipy
Successfully installed scipy
Run Code Online (Sandbox Code Playgroud)
但misc子包显然不包括在内?
16:03:28/shared $ipython
In [1]: from scipy.misc import imread
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-f9d3d927b58f> in <module>()
----> 1 from scipy.misc import imread
ImportError: cannot import name imread
Run Code Online (Sandbox Code Playgroud)
安装scipy.misc包的方法是什么?
我想使用一个仍旧使用的旧脚本,该脚本scipy.misc.imresize()不仅已弃用,而且已从scipy中完全删除。相反,开发人员建议使用numpy.array(Image.fromarray(arr).resize())或skimage.transform.resize()。
不再起作用的确切代码行是这样的:
new_image = scipy.misc.imresize(old_image, 0.99999, interp = 'cubic')
Run Code Online (Sandbox Code Playgroud)
不幸的是,我不确定现在到底能做什么。恐怕如果我开始使用旧的scipy版本,我的新脚本将停止工作。我一直在使用它作为模糊滤镜的一部分。如何执行numpy.array(Image.fromarray(arr).resize())或skimage.transform.resize()执行与上述代码行相同的操作?很抱歉,我提供的信息不足。
编辑
我已经能够确定这条线的作用。它从此转换图像数组:
[[[0.38332759 0.38332759 0.38332759]
[0.38770704 0.38770704 0.38770704]
[0.38491378 0.38491378 0.38491378]
...
Run Code Online (Sandbox Code Playgroud)
对此:
[[[57 57 57]
[59 59 59]
[58 58 58]
...
Run Code Online (Sandbox Code Playgroud)
编辑2
当我使用jhansens方法时,输出为:
[[[ 97 97 97]
[ 98 98 98]
[ 98 98 98]
...
Run Code Online (Sandbox Code Playgroud)
我不知道该怎么办scipy.misc.imresize。
我正在尝试一些代码段,
from scipy import misc
im = misc.imread(file_image, True)
Run Code Online (Sandbox Code Playgroud)
但是,我收到了错误消息,例如
AttributeError: module 'scipy.misc' has no attribute 'imread'
Run Code Online (Sandbox Code Playgroud)
这可能是什么原因?
我正在尝试从Web上获取JPEG图像资源,将其转换为NumPy数组图像表示形式,类似于由返回的数组scipy.misc.imread。而不是将映像保存到磁盘,如以下示例所示:
import requests
from scipy import misc
def load_image(url):
res = requests.get(url)
if res == 200 and 'jpeg' in res.headers['content-type']:
with open('image.jpg', 'wb') as fp:
for chunk in res:
fp.write(chunk)
img_arr = misc.imread('image.jpg')
return img_arr
else:
return None
Run Code Online (Sandbox Code Playgroud)
我想将图像直接加载到内存中。有办法吗?
我正在尝试从 scipy 读取图像。但它给出错误“没有属性'imread'”。可能是什么原因造成的?
AttributeError Traceback (most recent call last)
<ipython-input-29-311aa4fc2e10> in <module>
5
6 fname = "images/" + my_image
----> 7 image = np.array(ndimage.imread(fname, flatten=False))
8 my_image = scipy.misc.imresize(image, size=(num_px,num_px)).reshape((num_px*num_px*3,1))
9 my_image = my_image/255.
AttributeError: module 'scipy.ndimage' has no attribute 'imread'
Run Code Online (Sandbox Code Playgroud) 当我尝试使用 Scipy.misc.imsave('path',image) 保存图像时。
我收到此错误:模块 'scipy.misc' 没有属性。
我正在 Ubuntu 17.10 上工作,并且安装了枕头和 scipy。你能帮我吗。
python ×9
scipy ×8
numpy ×5
image ×1
imread ×1
optimization ×1
python-3.x ×1
rawimage ×1
scikit-image ×1