栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

scipy.misc.imresize改为Image.resize方法

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

scipy.misc.imresize改为Image.resize方法

scipy.misc.imresize源码
@numpy.deprecate(message="`imresize` is deprecated in SciPy 1.0.0, "
                        "and will be removed in 1.3.0.n"
                        "Use Pillow instead: ``numpy.array(Image.fromarray(arr).resize())``.")
def imresize(arr, size, interp='bilinear', mode=None):
   im = toimage(arr, mode=mode) # im为PIL.Image.Image对象
   ts = type(size)
   if issubdtype(ts, numpy.signedinteger):
       percent = size / 100.0
       size = tuple((array(im.size)*percent).astype(int))
   elif issubdtype(type(size), numpy.floating):
       size = tuple((array(im.size)*size).astype(int))
   else:
       size = (size[1], size[0])
   func = {'nearest': 0, 'lanczos': 1, 'bilinear': 2, 'bicubic': 3, 'cubic': 3}
   imnew = im.resize(size, resample=func[interp]) # 调用PIL库中的resize函数
   return fromimage(imnew)



解决方式就在提示错误的下面,照着更改,就可以了
参考链接

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


总结:

  1. 导入模块from PIL import Image和import numpy as np
  2. 将图片打开
  3. 转换成asarray格式
  4. 设置需要转换的高度和宽度即可 np.array(Image.fromarray(a).resize((resize_h,resize_w)))
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/987631.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号