Reputation: 35
I'm trying to reshape an image into the size I want. There is an image dataset I got online and the shape of each image in the dataset is (3, 128, 128)
.
I want the shape of each image to be (128, 128, 3)
. I know that there are several functions in python for reshaping (np.reshape) and resizing (skimage.transform.resize), but I'm not sure if these functions are the right functions for this situation.
Upvotes: 0
Views: 1900
Reputation: 388
An appropriate function for this situation is numpy.transpose()
. Assuming you have an image
of shape (3, 128, 128)
, you can reshape it into your desired dimensions (128, 128, 3)
like so:
reshaped_image = np.transpose(image, axes=(1, 2, 0))
Upvotes: 1