已弃用 scipy imresize() 函数的替代方案?

Alternatives of deprecated scipy imresize() function?

我曾经使用 scipy 调整大小功能来缩小图像。但是由于这个函数在 scipy 的最新版本中被弃用了,我正在寻找一个替代方法。 PIL 似乎很有前途,但我如何将其用于 3d 图像? (600,800,3) 到 (300,400,3)

我研究了 numpy.resize、skimage,但尤其是 skimage,我不确定它是否像 scipy 的 imresize() 那样工作。

是使用 OpenCV 调整彩色图像大小的一种方法。

import numpy as np
import cv2

image = cv2.imread('image.png')
cv2.imshow("Original", image)
"""
The ratio is r. The new image will
have a height of 50 pixels. To determine the ratio of the new
height to the old height, we divide 50 by the old height.
"""
r = 50.0 / image.shape[0]
dim = (int(image.shape[1] * r), 50)

resized = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)
cv2.imshow("Resized (Height) ", resized)
cv2.waitKey(0)

official docs 中所述,您可以改用 numpy.array(Image.fromarray(arr).resize())

P.S:scipy.misc 模块中还弃用了许多其他图像函数。您可以查看它们 here。如果网站发生变化,我也会在下面引用它们:

Deprecated functions:
bytescale(*args, **kwds)  bytescale is deprecated! bytescale is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.
fromimage(*args, **kwds)  fromimage is deprecated! fromimage is deprecated in SciPy 1.0.0.
imfilter(*args, **kwds)   imfilter is deprecated! imfilter is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.
imread(*args, **kwds)     imread is deprecated! imread is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.
imresize(*args, **kwds)   imresize is deprecated! imresize is deprecated in SciPy 1.0.0, and will be removed in 1.3.0.
imrotate(*args, **kwds)   imrotate is deprecated! imrotate is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.
imsave(*args, **kwds)     imsave is deprecated! imsave is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.
imshow(*args, **kwds)     imshow is deprecated! imshow is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.
toimage(*args, **kwds)    toimage is deprecated! toimage is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.