My Coding >
Programming language >
Python >
Python libraries and packages >
Python NumPy >
How to turn image 90 degree with NumPy
How to turn image 90 degree with NumPyPretty common task is to rotate image 90 degree. If the image already loaded into NumPy it is very easy to do with rot90() function. Actually this can be used to matrix rotation as well if you need it! As usual, start with proper libraries. You need to have NumPy for manipulations with data and PIL for reading image.
Then load image and convert it to NumPy array
Next step is rotate the matrix, which corresponds to the image
Where rotate is a number of 90 degree turns you need to perform. The rotation will be done in the plane specified by axes in the direction from the first towards the second axis. So, to rotate image anticlockwise use by 90 degree, use:
It is necessary to remember, that after rotation, Numpy Array will be allocated in the memory a bit messy, and some function will not work properly, giving an error:
to avoid this error, you need to make this array continuous again
|
Last 10 artitles
9 popular artitles
|
|
© 2020 MyCoding.uk -My blog about coding and further learning. This blog was writen with pure Perl and front-end output was performed with TemplateToolkit. |