不推荐使用scipy imresize()函数的替代方法?

时间:2019-08-16 10:52:53

标签: python image resize

我曾经使用scipy调整大小功能来缩小图像。但是由于最新版本的scipy中不推荐使用此功能,因此我正在寻找替代方法。 PIL似乎很有前途,但是如何将其用于3D图像? (600,800,3)至(300,400,3)

我查看了skpy的numpy.resize,但是特别是对于skimage,我不确定它是否像scipy的imresize()一样工作。

2 个答案:

答案 0 :(得分:1)

Here是使用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)

答案 1 :(得分:1)

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.