SciPy — Image Processing
Read and display
from scipy import ndimage
import numpy as np
# Create test image
image = np.random.rand(100, 100)
Filtering
from scipy.ndimage import gaussian_filter, uniform_filter
# Gaussian blur
blurred = gaussian_filter(image, sigma=1)
# Mean filter
filtered = uniform_filter(image, size=3)
Edge detection
from scipy.ndimage import sobel
# Compute gradients
sx = sobel(image, axis=0)
sy = sobel(image, axis=1)
edges = np.hypot(sx, sy)
Morphology
from scipy.ndimage import binary_dilation, binary_erosion
# Create binary image
binary = image > 0.5
# Dilate
dilated = binary_dilation(binary)
# Erode
eroded = binary_erosion(binary)
Transformations
from scipy.ndimage import rotate, shift, zoom
# Rotate
rotated = rotate(image, 45)
# Shift
shifted = shift(image, (10, 10))
# Zoom
zoomed = zoom(image, 2)
Labeling
from scipy.ndimage import label
# Label connected components
labeled, num_features = label(binary)
print(f"Found {num_features} objects")
Measurements
from scipy.ndimage import center_of_mass, find_objects
# Center of mass
com = center_of_mass(image)
# Find objects
objects = find_objects(labeled)
Mini Practice
- Apply Gaussian blur
- Detect edges
- Perform morphological operations
- Label connected components
Up Next
Continue with Sparse Matrices - Efficient matrices.
Related Topics
Frequently Asked Questions about Image Processing
What is Image Processing in SciPy?
Image Processing is a fundamental concept in SciPy. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Image Processing?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Image Processing.
Why is Image Processing important in SciPy?
Image Processing is essential for SciPy development. Understanding this concept will help you write better code and solve real-world problems more effectively.