What is the scipy.ndimage module in Python?
Scipy ndimage (n- dimensional image) is a widely used module for image processing.
Below are among the most common tasks performed in image processing using ndimage:
-
Input, outputting, and displaying images.
-
Cropping an image, inverting an image, rotating an image, etc.
-
Image filtering operations such as denoising or sharpening an image.
-
Image Classification.
-
Feature extraction.
Input and output images
from scipy import miscimport matplotlib.pyplot as pltimg = misc.face()plt.imshow(img)plt.show()## lets look at some statistics like, mean, max, min valuesprint(img.mean(), img.max(), img.min())
All images in Python are numbers ranging between 0 and 255. Lets perform
import matplotlib.pyplot as pltimport numpy as npimport scipy.ndimage as ndimagefrom scipy import miscimg = misc.face()# Cropping an imagex = img.shape[0]y = img.shape[1]cropped = img[int(x / 4): int(- x / 4), int(y / 4): int(- y / 4)]plt.imshow(cropped)plt.show()plt.savefig('output/1.png')# inverted imageinverted = np.flipud(img)plt.imshow(inverted)plt.show()plt.savefig('output/2.png')# rotationrotating_by_45_degrees = ndimage.rotate(img, 45)plt.imshow(rotating_by_45_degrees)plt.show()plt.savefig('output/3.png')# blurring using gaussian filterblurred = ndimage.gaussian_filter(img, sigma=8)plt.imshow(blurred)plt.show()plt.savefig('output/4.png')
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved