【问题标题】:scipy.misc module has no attribute imresizescipy.misc 模块没有属性 imresize
【发布时间】:2020-07-22 00:49:13
【问题描述】:

我想使用部分代码来更改我的输入图像大小,但 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'

【问题讨论】:

  • 请使用准确且完整的错误跟踪更新您的帖子。另外,既然您询问numpy,您应该包括标签(已编辑)。

标签: python numpy image-processing scipy


【解决方案1】:

如你所说,你应该使用PILImage模块:

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

【讨论】:

  • 它带来了一个新的错误:ValueError: Unknown resampling filter (256)。使用 Image.NEAREST (0)、Image.LANCZOS (1)、Image.BILINEAR (2)、Image.BICUBIC (3)、Image.BOX (4) 或 Image.HAMMING (5)
  • 尝试使用回溯建议的整数位,而不是 PIL.Image.BILINEAR
  • 由于您仅从PIL 导入了Image,而不是实际的PIL,因此您不能执行PIL.Image.BILINEAR。相反,请Image.BILINEAR
猜你喜欢
  • 2019-10-05
  • 2013-02-27
  • 2019-12-23
  • 2019-12-06
  • 1970-01-01
  • 1970-01-01
  • 2020-06-04
  • 2021-12-24
相关资源
最近更新 更多