在Python中调整3D图像堆栈

时间:2017-02-25 02:16:32

标签: python image numpy

我有一个3D numpy数组,它是100个300x300图像的堆栈。我想将堆栈中的所有图像调整为200x200。我试着使用numpy resize函数:

import numpy as np

img_stack_sm = np.resize(img_stack, (100, 200, 200))

...但这样做会扰乱图像(如绘图所示)。怎么能一次完成呢?谢谢。

1 个答案:

答案 0 :(得分:4)

我最后只使用了for循环和cv2:

import cv2

width = 200
height = 200
img_stack_sm = np.zeros((len(img_stack), width, height))

for idx in range(len(img_stack)):
    img = img_stack[idx, :, :]
    img_sm = cv2.resize(img, (width, height), interpolation=cv2.INTER_CUBIC)
    img_stack_sm[idx, :, :] = img_sm