I want to rotate MxNx3 images (e.g. 640x480x3) images by 90 and 270 degrees using numpy functions like swapaxes, transpose etc and keep the image dimensions intact after rotation.
i.e. A 640x480x3 image should remain 640x480x3 after it is rotated by 90 degrees.
I have already implemented the rotation functionality thank to this link. It works fine for MxMx3 images
Below is my code.
for 90 deg CW rotation
rotated_img = np.transpose(image.swapaxes(-1, -0)[..., ::-1], (1,2,0))
for 270 deg CW rotation
rotated_img = np.transpose(image.swapaxes(-0,-1)[...,::-1,:], (1, 2, 0))
I want to know:
- how to rotate MxNX3 images by 90 and 270 degree and keep their dimensions intact?
- it is possible to achieve (1) by using only numpy swapaxes, transpose etc?
- is Affine transform the only way for rotating MxNx3 images by 90 and 270 degrees and keeping their dimensions intact?