python-scipyHow do I rotate an image using Python and SciPy?
To rotate an image using Python and SciPy, you can use the ndimage.rotate
function. This function takes in an image array, an angle in degrees, and optionally an order of interpolation. The following example rotates an image 90 degrees clockwise:
from scipy import ndimage
import matplotlib.pyplot as plt
# Load the image
img = plt.imread('image.jpg')
# Rotate the image 90 degrees clockwise
rotated_img = ndimage.rotate(img, 90)
# Show the rotated image
plt.imshow(rotated_img)
Code explanation
from scipy import ndimage
: imports thendimage
module fromscipy
import matplotlib.pyplot as plt
: imports thepyplot
module frommatplotlib
img = plt.imread('image.jpg')
: loads the image from the specified filenamerotated_img = ndimage.rotate(img, 90)
: rotates the image by 90 degrees clockwiseplt.imshow(rotated_img)
: displays the rotated image
Helpful links
More of Python Scipy
- How do I create a 2D array of zeros using Python and NumPy?
- How can I use Python and SciPy to implement a quantum Monte Carlo simulation?
- How do I use Python Numpy to read and write Excel (.xlsx) files?
- How do I use the numpy vstack function in Python?
- How do I convert a Python numpy.ndarray to a list?
- How can I use Python and SciPy to find the zeros of a function?
- How do I create a zero matrix using Python and Numpy?
- How can I check if a certain version of Python is compatible with SciPy?
- How do I use Python XlsxWriter to write a NumPy array to an Excel file?
- How do I use the scipy ttest_ind function in Python?
See more codes...