I have a 3D numpy array, which is a stack of 100 300x300 images. I want to resize all the images in the stack to be 200x200. I tried to use the numpy resize function:
import numpy as np
img_stack_sm = np.resize(img_stack, (100, 200, 200))
...but doing so scrambles the images (as shown by plotting). How can this be done in one pass? Thank you.
I just used a for loop in the end and 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With