# Scipy Rotate Image + Examples

In this Python tutorial, we will learn about the “Scipy Rotate Image“, here will rotate the image according to different angles. Additionally, we will cover the following topics.

• Scipy Rotate Image
• Scipy Rotate Image 90 degrees
• Scipy Rotate Image 90 degrees clockwise
• Scipy Rotate Image 180 degrees
• Scipy Rotate Image 120 degrees
• Scipy Rotate Image 60 degrees
• Scipy Rotate Image 40 degrees

## Scipy Rotate Image

The Scipy has a module `scipy.ndimage` to control images like shape, size and etc, or perform image processing tasks and this library has many functions for image processing operations. Here we will use the function `rotate()` to rotate the provided image at a given angle.

The syntax of the method `scipy.ndimage.rotate()` is given below.

``scipy.ndimage.rotate(input, angle, axes=(1, 0), reshape=True, output=None, mode='constant')``

Here are the most used parameters with the method `rotate()`.

• input(array_data): It is the input array or image that we are going to rotate.
• angle(float): It is used to specify the rotation angle like 20 degrees or 90 degrees.
• axes(two ints in tuples): The plane of the rotation is defined by the two axes.
• output(datatype or array): It defines the datatype of the returned array, by default returned array datatype is the same as the input array.
• mode: It is used to specify the modes `‘constant’, ‘mirror’, ‘wrap’, ‘reflect’, ‘nearest’`.

Let’s understand through an example by following the below steps:

Import the required libraries such `matplotlib` and `scipy` using the below python code.

``````from matplotlib import image, pyplot
from scipy import ndimage``````

Load the image from the directory or wherever the image exists on your computer using the below code.

``img = image.imread('rob_potter.jpg')``

Here the function `imread()`of the module `image` read the images in the form of an array of pixels.

View the loaded image with the help of a function `imshow()` of the module `pyplot` as shown below.

``pyplot.imshow(img)``

Let’s rotate the above-loaded image to some angle using the below code.

``rob_potter_rotate = ndimage.rotate(img,20,mode='constant')``

Here in the above code, we are using the function `rotate()` of the module `ndimage` of Scipy for rotating any image. Also providing some parameters like the image `img` that we are going to rotate, the angle of the rotation `20` degrees, and the mode as `constant`.

Now view the image which rotated to an angle of 20 degrees using the below code.

``pyplot.imshow(rob_ptter_rotate)``

Look in the above output at how we have rotated the image to an angle of 20 degrees.

## Scipy Rotate Image 90 degrees

Here we will rotate the image to 90 degrees anticlockwise using the below code.

Import the required libraries `matplotlib` and scipy use the below python code.

``````from matplotlib import image, pyplot
from scipy import ndimage``````

Load the image from the directory or wherever the image exists on your computer using the function `imread()` as shown in the below code.

``img = image.imread('rob_potter.jpg')``
``rob_potter_rotate = ndimage.rotate(img,-90,mode='constant')``

Here in the above code, we are using the function `rotate()` of the module `ndimage` of Scipy for rotating any image. Also providing some parameters like the image `img` that we are going to rotate, the angle of the rotation `-90` degrees, and the mode as `constant`.

``pyplot.imshow(rob_potter_rotate)``

This is how we rotate the provided image at ninety degrees anticlockwise.

## Scipy Rotate Image 90 degrees clockwise

Here we will rotate the provided image 90 degrees clockwise.

Import the required libraries `matplotlib` and scipy use the below python code.

``````from matplotlib import image, pyplot
from scipy import ndimage``````

Load the image from the directory or wherever the image exists on your computer using the function `imread()` as shown in the below code.

``img = image.imread('rob_potter.jpg')``
``rob_potter_rotate = ndimage.rotate(img,90,mode='constant')``

Here in the above code, we are using the function `rotate()` of the module `ndimage` of Scipy for rotating any image. Also providing some parameters like the image `img` that we are going to rotate, the angle of the rotation `90` degrees, and the mode as `constant`.

``pyplot.imshow(rob_potter_rotate)``

From the above output, we can see the image rotated to 90 degrees.

## Scipy Rotate Image 180 degrees

Here we will rotate the given image 180 degrees clockwise.

Import the required libraries `matplotlib` and scipy use the below python code.

``````from matplotlib import image, pyplot
from scipy import ndimage``````

Load the image from the directory or wherever the image exists on your computer using the function `imread()` as shown in the below code.

``img = image.imread('rob_potter.jpg')``
``rob_potter_rotate = ndimage.rotate(img,180,mode='constant')``

Here in the above code, we are using the function `rotate()` of the module `ndimage` of Scipy for rotating any image. Also providing some parameters like the image `img` that we are going to rotate, the angle of the rotation `180` degrees, and the mode as `constant`.

``pyplot.imshow(rob_potter_rotate)``

From the above output, we can see the image rotated to 180 degrees.

## Scipy Rotate Image 120 degrees

Here we will rotate the provided image at 120 degrees.

Import the required libraries `matplotlib` and scipy use the below python code.

``````from matplotlib import image, pyplot
from scipy import ndimage``````

Load the image from the directory or wherever the image exists on your computer using the function `imread()` as shown in the below code.

``img = image.imread('rob_potter.jpg')``
``rob_potter_rotate = ndimage.rotate(img,120,mode='constant')``

Here in the above code, we are using the function `rotate()` of the module `ndimage` of Scipy for rotating any image. Also providing some parameters like the image `img` that we are going to rotate, the angle of the rotation `120` degrees, and the mode as `constant`.

``pyplot.imshow(rob_potter_rotate)``

From the above output, we can see the image rotated to 120 degrees

## Scipy Rotate Image 60 degrees

Here we will rotate the provided image at 60 degrees.

Import the required libraries `matplotlib` and scipy use the below python code.

``````from matplotlib import image, pyplot
from scipy import ndimage``````

Load the image from the directory or wherever the image exists on your computer using the function `imread()` as shown in the below code.

``img = image.imread('rob_potter.jpg')``
``rob_potter_rotate = ndimage.rotate(img,60,mode='constant')``

Here in the above code, we are using the function `rotate()` of the module `ndimage` of Scipy for rotating any image. Also providing some parameters like the image `img` that we are going to rotate, the angle of the rotation `60` degrees, and the mode as `constant`.

``pyplot.imshow(rob_potter_rotate)``

From the above output, we can see the image rotated to 60 degrees.

## Scipy Rotate Image 40 degrees

Here we will rotate the provided image at 40 degrees.

Import the required libraries `matplotlib` and scipy use the below python code.

``````from matplotlib import image, pyplot
from scipy import ndimage``````

Load the image from the directory or wherever the image exists on your computer using the function `imread()` as shown in the below code.

``img = image.imread('rob_potter.jpg')``
``rob_potter_rotate = ndimage.rotate(img,40,mode='constant')``

Here in the above code, we are using the function `rotate()` of the module `ndimage` of Scipy for rotating any image. Also providing some parameters like the image `img` that we are going to rotate, the angle of the rotation `40` degrees, and the mode as `constant`.

``pyplot.imshow(rob_potter_rotate)``

From the above output, we can see the image rotated to 40 degrees.

Also, check the following list of related tutorials:

So, in this tutorial, we have learned the “Scipy Rotate Image” and covered the following topics.

• Scipy Rotate Image
• Scipy Rotate Image 90 degrees
• Scipy Rotate Image 90 degrees clockwise
• Scipy Rotate Image 180 degrees
• Scipy Rotate Image 120 degrees
• Scipy Rotate Image 60 degrees
• Scipy Rotate Image 40 degrees