Open In App

Rotate a picture using ndimage.rotate Scipy

Last Updated : 03 Jan, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Prerequisites: Mathplotlib, Scipy

Some of the most common tasks in image processing are displaying images, Basic manipulations, Image filtering, Image segmentation. 
In this article, we will use a SciPy module “ndimage.rotate()” to rotate. The SciPy ndimage submodule is dedicated to image processing. Here, ndimage means an n-dimensional image.

Approach:

  • Import all the required modules.
  • SciPy comes with some images, We use those images.
  • Call and pass Parameter in ndimage.rotate( ).
  • Display Image.

Step 1: Import module.

Python3




from scipy import ndimage, misc
from matplotlib import pyplot as plt


Step 2: The misc package in SciPy comes with some images. We use those images to learn the image manipulations.

Python3




from scipy import ndimage, misc
from matplotlib import pyplot as plt
  
panda = misc.face()


Step 3: The SciPy “ndimage” submodule is dedicated to image processing. Here, “ndimage” means an n-dimensional image.

Syntax:

scipy.ndimage.rotate(input, angle)

Parameter:

  • input: The input array.
  • angle: The rotation angle in degrees.
  • mode: {‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’}, optional

Returns: The rotated input.

Python3




from scipy import ndimage, misc
from matplotlib import pyplot as plt
panda = misc.face()
  
#image rotated 135 degree
panda_rotate = ndimage.rotate(panda, 135, mode = 'constant')


Below is the Implementation:

Example 1:

Python3




from scipy import ndimage, misc
from matplotlib import pyplot as plt
  
panda = misc.face()
#image rotated 35 degree
panda_rotate = ndimage.rotate(panda, 35,
                              mode = 'mirror')
plt.imshow(panda_rotate)
plt.show()


Output:

Example 2:

Python3




from scipy import ndimage, misc
from matplotlib import pyplot as plt
  
panda = misc.ascent()
  
#image rotated 360 degree
panda_rotate = ndimage.rotate(panda, 45
                              mode = 'constant')
plt.imshow(panda_rotate)
plt.show()


Output:



Similar Reads

Python Scipy - ndimage.interpolation.geometric_transform() function
The given mapping function is used to find, for each point in the output, the corresponding coordinates in the input Syntax: scipy.ndimage.interpolation.geometric_transform(input, mapping, order=3) Parameters input : takes an array.mapping : accepts a tuple data structure similar to length of given output array rank.order : int parameter. which is
1 min read
Python SciPy - ndimage.map_coordinates() function
This function is used to map the given array to new coordinates by interpolation. The array of coordinates is used to find, for each point in the output, the corresponding coordinates in the input. Syntax: scipy.ndimage.map_coordinates(input, coordinates, output=None, order=3,cval=0.0, prefilter=True) Parameters input: which is of array_like - The
2 min read
Python SciPy - ndimage.spline_filter1d() function
This method is used to calculate a 1-D spline filter along the given axis. These are filtered by a spline filter. Syntax: scipy.ndimage.spline_filter1d(input, order=3, axis=-1, output=<class 'numpy.float64'>) Parameters input: array_like - The input array order: int - The order of the spline, default is 3. axis: int, - The axis along which th
2 min read
SciPy Linear Algebra - SciPy Linalg
The SciPy package includes the features of the NumPy package in Python. It uses NumPy arrays as the fundamental data structure. It has all the features included in the linear algebra of the NumPy module and some extended functionality. It consists of a linalg submodule, and there is an overlap in the functionality provided by the SciPy and NumPy su
8 min read
Post a picture automatically on Instagram using Python
Prerequisites: Python Programming LanguageInstagram is a photo and video-sharing social networking service owned by Facebook, Python provides powerful tools for interacting with Instagram. In this article, we will come to know how we can post a picture automatically on the Instagram account just by writing a few lines of Python code.Step 1: Install
2 min read
PyQtGraph – Generate Picture from Graph Item
In this article we will see how we can generate the picture of the graph item in PyQTGraph. PyQtGraph is a graphics and user interface library for Python that provides functionality commonly required in designing and science applications. Its primary goals are to provide fast, interactive graphics for displaying data (plots, video, etc.). A Graph i
3 min read
How to extract Audio Wave from a mixture of Signal using Scipy - Python?
Prerequisites: Scipy Spectral Analysis refers to analyzing of the frequency spectrum/response of the waves. This article as the title suggests deals with extracting audio wave from a mixture of signals and what exactly goes into the process can be explained as: Consider we have 3 mixed Audio Signals having frequency of 50Hz,1023Hz & 1735Hz resp
7 min read
How to find the factorial os a number using SciPy in Python?
SciPy is an open-source Python library used to solve scientific and mathematical problems. It is built on NumPy and it allows us to manipulate and visualizing with a wide range of high-level commands. Scipy also provides a scipy.special.factorial() function to calculate factorial of any number. scipy.special.factorial() This function takes two para
2 min read
Plotting A Square Wave Using Matplotlib, Numpy And Scipy
Prerequisites: linspace, Mathplotlib, Scipy A square wave is a non-sinusoidal periodic waveform in which the amplitude alternates at a steady frequency between the fixed minimum and maximum values, with the same duration at minimum and maximum. Graphical representations are always easy to understand and are adopted and preferable before any written
2 min read
Find all peaks amplitude lies above 0 Using Scipy
Prerequisites: Matplotlib, Scipy In this article, we will see how to find all 'x' point above 0 with the help of find_peaks( ) function, that takes a 1-D array and finds all local maxima by a simple comparison of neighboring values. Approach: Import required module.Find peaks inside a signal based on find_peaks() properties.Label the graph.Display
2 min read
Article Tags :
Practice Tags :