8

I have a 2D array that represents the values of an image that can be viewed with the imshow() command in matplotlib. I would like to rotate the values of this array ("Rotate the image") and have not found a way to do so with a typical NxN array. Anyone know how to do this?

Thanks for your time

2 Answers 2

7

How about scipy.ndimage.interpolation.rotate()?

3
  • 1
    For 90 degree rotations, rot90 (as acm suggests) is probably faster. For arbitrary angles, use ndimage.rotate.
    – Luke
    Jul 5, 2011 at 21:44
  • Luke, thank you very much. This is exactly what I need for arbitrary angles. However, this functions much like an interpolation function and so the resultant image is of different dimensions than the first. Do you know how to resize the image? Again I think this has to do with interpolation... Jul 5, 2011 at 22:15
  • 2
    In general, rotating an image should always change its dimensions (unless it is cropped/resized afterward). You can manually resize the image with ndimage.zoom. But also see "reshape" option in the rotate documentation: docs.scipy.org/doc/scipy/reference/generated/…
    – Luke
    Jul 5, 2011 at 22:22
6

You should be able to use rot90 on the array to rotate it and then imshow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.