Home > Software engineering >  change image dimentions (a, z, y, x) to (x, y, z)
change image dimentions (a, z, y, x) to (x, y, z)

Time:07-09

I have a NumPy array which is representing an image with shape (1, 3, 480, 640). How would I turn this to have a shape (640, 480, 3)?

Thanks

CodePudding user response:

You can use numpy.squeeze and numpy.swapaxes.

img = np.random.rand(1,3,480,640)
img = np.squeeze(img)
print(img.shape)
# (3, 480, 640)

img = np.swapaxes(img, axis1=2, axis2=0)
print(img.shape)
# (3, 480, 640)
  • Related