Concept Flow - Image filtering (gaussian_filter)
Input Image Array
Apply gaussian_filter
Smooth Image Output
Use or Display Result
Start with an image array, apply gaussian_filter to smooth it, then get the filtered image for use or display.
Jump into concepts and practice - no test required
import numpy as np from scipy.ndimage import gaussian_filter image = np.array([[10, 10, 10], [10, 50, 10], [10, 10, 10]]) filtered = gaussian_filter(image, sigma=1)
| Step | Action | Input Value | Filter Parameter | Output Value |
|---|---|---|---|---|
| 1 | Input image created | [[10,10,10],[10,50,10],[10,10,10]] | sigma=1 | Same as input |
| 2 | Apply gaussian_filter | Image array | sigma=1 | Smoothed image array |
| 3 | Calculate weighted average for center pixel | Center=50 neighbors=10 | sigma=1 | Center pixel approx 22.5 |
| 4 | Calculate weighted average for corner pixel | Corner=10 neighbors=10 and 50 | sigma=1 | Corner pixel approx 12.5 |
| 5 | Filtered image ready | N/A | N/A | [[12.5, 15.6, 12.5],[15.6, 22.5, 15.6],[12.5, 15.6, 12.5]] |
| Variable | Start | After gaussian_filter | Final |
|---|---|---|---|
| image | [[10,10,10],[10,50,10],[10,10,10]] | [[10,10,10],[10,50,10],[10,10,10]] | Same as start |
| filtered | None | N/A | [[12.5, 15.6, 12.5],[15.6, 22.5, 15.6],[12.5, 15.6, 12.5]] |
gaussian_filter(image, sigma) - Smooths image by weighted averaging neighbors - sigma controls blur amount (higher = more blur) - Output is same shape, float values - Useful to reduce noise or details - Works on numpy arrays representing images
gaussian_filter in image processing?gaussian_filter applies a blur effect that smooths the image by averaging nearby pixels weighted by a Gaussian curve.image?scipy.ndimage, so import it with from scipy.ndimage import gaussian_filter.gaussian_filter(image, sigma=2) to blur with sigma 2.import numpy as np
from scipy.ndimage import gaussian_filter
image = np.array([[0, 0, 0],
[0, 10, 0],
[0, 0, 0]])
filtered = gaussian_filter(image, sigma=1)
print(np.round(filtered, 2))import numpy as np from scipy.ndimage import gaussian_filter image = np.ones((5,5)) filtered = gaussian_filter(image, sigma='2') print(filtered)
sigma parameter must be a numeric value (int or float), not a string.'2' as a string causes a type error when the filter tries to compute the blur.gaussian_filter and its parameters is best?