有效地调整图像的ndarray

Resizing ndarray of images efficiently

我有一个包含 100 张彩色图像的 ndarray I,其中 I.shape 是:(100,1,3,100,200).

这会调整单个图像的大小:i=cv2.resize(i,(10,25)),但是调整 I 中所有图像大小的有效方法是什么,以便 ndarray 形状变为:(100,1,3,10,25)

这是一个使用 ndimage 中的 zoom 函数的命题。在我的电脑上调整大小大约需要 69 毫秒 :

import numpy as np
I=np.random.randint(0,255,size=(100,1,3,100,200),dtype=np.uint8)

from scipy.ndimage.interpolation import zoom
I2=zoom(I,zoom=(1,1,1,1./10,1./8),order=1)