码迷,mamicode.com
首页 > 其他好文 > 详细

scipy1.3.0开始被弃用的imread,imresize,如何代替

时间:2020-02-24 14:49:09      阅读:371      评论:0      收藏:0      [点我收藏+]

标签:use   fun   开始   logs   nbsp   import   error:   array   factorial   

scipy1.3.0开始被弃用的imread,imresize,如何代替

SciPy最新官方文档的说明(20190730):

Functions from scipy.interpolate (spleval, spline, splmake, and spltopp) and functions from scipy.misc (bytescale, fromimage, imfilter, imread, imresize, imrotate, imsave, imshow, toimage) have been removed. The former set has been deprecated since v0.19.0 and the latter has been deprecated since v1.0.0. Similarly, aliases from scipy.misc (comb, factorial, factorial2, factorialk, logsumexp, pade, info, source, who) which have been deprecated since v1.0.0 are removed. SciPy documentation for v1.1.0 can be used to track the new import locations for the relocated functions.

文档中说明了在scipy的0.19.0版本和1.0.0版本中可以用到的imread,imresize函数在scipy的1.3.0版本中全部被遗弃。

如果在最新版scipy中继续使用这两个函数,会出现如下报错:

AttributeError: module ‘scipy.misc‘ has no attribute ‘imread‘

AttributeError: module ‘scipy.misc‘ has no attribute ‘imresize‘

然而网上大多数对这个问题的解决办法都是pip安装PIL或者pillow,

这并不能解决到实际问题(因为scipy已经不支持这两个函数,pillow依赖库的安装与否不是根本问题)

下面给出这个两个函数的代替方案:

1. imread

先前版本

img = scipy.misc.imread(myImage)

新版本

import imageio

img = imageio.imread(myImage)

 

 

2. imresize

先前版本

img = scipy.misc.imresize(myImage, size=(num_px,num_px))

新版本:

from PIL import Image

img = np.array(Image.fromarray(myImage).resize((num_px,num_px)))

scipy1.3.0开始被弃用的imread,imresize,如何代替

标签:use   fun   开始   logs   nbsp   import   error:   array   factorial   

原文地址:https://www.cnblogs.com/Timeouting-Study/p/12356833.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!