如何调整 Nd numpy 图像的大小?
我不只是想对它进行二次采样,而是对像素进行插值/平均。
例如,如果我从
array([[[3, 1, 3, 1],
[3, 1, 3, 1],
[3, 1, 3, 1],
[3, 1, 3, 1]],
[[3, 1, 3, 1],
[3, 1, 3, 1],
[3, 1, 3, 1],
[3, 1, 3, 1]]], dtype=uint8)
并在所有维度上将其缩小 2 倍,我希望输出为
array([[[2, 2],
[2, 2]]], dtype=uint8)
尝试的解决方案:
A. SciPy ndimage:
>>> scipy.ndimage.interpolation.zoom(x, .5, mode='nearest')
array([[[3, 1],
[3, 1]]], dtype=uint8)
(可选order
参数没有区别)
B. 循环2**3
可能的偏移量:丑陋,缓慢,仅适用于整数缩放因子,并且需要额外的步骤以避免溢出。
C. OpenCV 和 PIL 仅适用于 2D 图像。