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)))
总结:
- 导入模块
from PIL import Image
和import numpy as np
- 将图片打开
- 转换成
asarray
格式 - 设置需要转换的高度和宽度即可
np.array(Image.fromarray(a).resize((resize_h,resize_w)))