最新版1.2.0scipy.misc中的toimage, imread、imresize、imsave出错的问题

在想把numpy 数据转为图像的时候需要用到imsave(),imresize, imsave 等问题但是在import scipy.misc 之后显示该库内没有imsave()
错误如下:

scipy.misc import toimage


File "D:/Agronne/Tensorflow/...../WGAN实战/gan_train.py", line 5, in <module>
    from    scipy.misc import toimage
ImportError: cannot import name 'toimage' from 'scipy.misc' (C:\conda\lib\site-packages\scipy\misc\__init__.py)

1. toimage() 无法导入的问题

查询了一堆博客和google,大部分说是应为pillow 未装好,我重装了最新版的pillow后还是不行,后来去了scipy官网,发现人家scipy 1.2.0后删除了toimage,改用pillow中的Image.fromarray()
官网如下:
“toimage is deprecated! toimage is deprecated in SciPy 1.0.0, and will be removed in 1.2.0. Use Pillow’s Image.fromarray directly instead.
Takes a numpy array and returns a PIL image.
This function is only available if Python Imaging Library (PIL) is installed.
The mode of the PIL image depends on the array shape and the pal and mode keywords.”

所以别再傻傻的装pillow了,使用PIL
from  PIL import Image
Image.fromarray(final_image)

运行正确

2. imsave()等的问题

同样的,imread,和imsave 也在scipy中去除了,分别改用了imageio 中imread,imsave 替换了
官网介绍如下:
“imsave is deprecated! imsave is deprecated in SciPy 1.0.0, and will be removed in 1.2.0. Use imageio.imwrite instead.
imread, is deprecated! 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]) 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值