Rotating an image array in Numpy

12,013

Solution 1

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

Solution 2

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

Share:
12,013

Related videos on Youtube

Sebastian De Pascuale
Author by

Sebastian De Pascuale

Updated on June 01, 2022

Comments

  • Sebastian De Pascuale
    Sebastian De Pascuale almost 2 years

    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

  • Luke
    Luke almost 13 years
    For 90 degree rotations, rot90 (as acm suggests) is probably faster. For arbitrary angles, use ndimage.rotate.
  • Sebastian De Pascuale
    Sebastian De Pascuale almost 13 years
    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...
  • Luke
    Luke almost 13 years
    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/…