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()?

Sign up to request clarification or add additional context in comments.

3 Comments

For 90 degree rotations, rot90 (as acm suggests) is probably faster. For arbitrary angles, use ndimage.rotate.
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...
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/…
6

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.