我得到了一个形状为 388x388x1 的 1 通道 numpy 数组,其值范围为 1-150,作为 ML 推理的输出。我需要使用最近邻插值将数组大小调整为 5000x4000x1。
目前我正在使用 PIL 调整大小。它可以工作,但为此必须导入 PIL 感觉过于复杂。
output = np.random.randint(150, size=(388, 388))
width, height = 4000, 5000
pilImage = Image.fromarray(pred.astype(np.uint8))
pilImageResized = pilImage.resize((width, height), Image.NEAREST)
resizedOutput = np.array(pilImageResized).astype(np.uint8)
Run Code Online (Sandbox Code Playgroud)
在 numpy 中是否有更简单的方法可以实现我想要的目标?(不使用cv2.resize
,scipy.interpolate
或PIL
)