首页 > 解决方案 > scipy.misc 模块没有属性 imresize

问题描述

我想使用部分代码来更改我的输入图像大小,但 imresize 在 scipy 上已弃用,并且无法在 google colab 上运行。代码的一部分是:

height = 256
width  = 256
channels = 3 
.....   
img = sc.imread(Tr_list[idx])
img = np.double(sc.imresize(img, [height, width, channels], interp='bilinear', mode = 'RGB'))

所以,我正在寻找 numpy.array(Image.fromarray(arr).resize()) 上的等效代码。我应该如何更改我的代码?

确切的错误文本是:

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

标签: pythonnumpyimage-processingscipy

解决方案


如您所说,您应该使用以下Image模块PIL

from PIL import Image
height = 256
width  = 256
...
img = ...
img = np.array(Image.fromarray(img).resize((height, width), Image.BILINEAR)).astype(np.double)

推荐阅读