有没有更好的方法来调整 numpy 数组形式的图像的大小?

Is there a better way to resize an image that is in the form of a numpy array?

我是神经网络新手,一直在练习图像预处理。我正在尝试调整 numpy 数组形式的图像大小,这是我当前的方法:

# using tensorflow, resize the image
im = tf.image.resize(img_as_array, [299, 299])

# then use .eval() which returns a numpy array in the size I want
im_arr = im.eval(session=tf.compat.v1.Session())

有更好的方法吗?

为了避免在 tf.tensornp.ndarray 张量数据类型之间进行转换,您可以使用 skimage (scikit-image) 直接在 np.ndarray 上调整图像大小使用以下代码段的对象:

import skimage.transform

kwargs = dict(output_shape=self._size, mode='edge', order=1, preserve_range=True)
im = skimage.transform.resize(im, **kwargs).astype(im.dtype)

要安装 skimage,请按照此处的安装说明进行操作:https://pypi.org/project/scikit-image/。希望这对您有所帮助!