Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numpy image - rotate matrix 270 degrees

I've got a Numpy 2d array that represents a grey-scale image and I need to rotate it 270 degrees. Might be being a bit thick here but the two ways I can find to do this seem quite... circulous:

rotated = numpy.rot90(numpy.rot90(numpy.rot90(orignumpyarray)))  rotated = numpy.fliplr(numpy.flipud(numpy.rot90(orignumpyarray))) 

I'm thinking there must be a better way to do this in one operation. Basically a rot270() function? Any ideas?

like image 616
Mikesname Avatar asked Mar 17 '10 10:03

Mikesname


People also ask

How do you rotate a matrix 270 degrees?

In the same way, you can rotate a matrix by 270 degrees by reversing the rows and then transposing. Lastly, you can rotate a matrix by 180 degrees by reversing the rows and the columns.

How do I rotate a matrix in NumPy?

NumPy: rot90() function The rot90() function is used to rotate an array by 90 degrees in the plane specified by axes. Rotation direction is from the first towards the second axis. Array of two or more dimensions. Number of times the array is rotated by 90 degrees.

How do I rotate an image in NumPy Python?

Rotate image with NumPy: np. The NumPy function that rotates ndarray is np. rot90() . Specify the original ndarray as the first argument and the number of times to rotate 90 degrees as the second argument.

How do I rotate a picture 180 degrees NumPy?

rot90) Using numpy. rot90() , you can rotate the NumPy array ndarray by 90/180/270 degrees.


1 Answers

You can tell rot90 to rotate several times, this should work:

rotated = numpy.rot90(orignumpyarray,3) 
like image 117
Anders Lindahl Avatar answered Sep 17 '22 20:09

Anders Lindahl