0
0
SciPydata~10 mins

Image filtering (gaussian_filter) in SciPy - Step-by-Step Execution

Choose your learning style9 modes available
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.
Execution Sample
SciPy
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)
This code smooths a small 3x3 image using a Gaussian filter with sigma=1.
Execution Table
StepActionInput ValueFilter ParameterOutput Value
1Input image created[[10,10,10],[10,50,10],[10,10,10]]sigma=1Same as input
2Apply gaussian_filterImage arraysigma=1Smoothed image array
3Calculate weighted average for center pixelCenter=50 neighbors=10sigma=1Center pixel approx 22.5
4Calculate weighted average for corner pixelCorner=10 neighbors=10 and 50sigma=1Corner pixel approx 12.5
5Filtered image readyN/AN/A[[12.5, 15.6, 12.5],[15.6, 22.5, 15.6],[12.5, 15.6, 12.5]]
💡 Filtering complete, output is smoothed image array
Variable Tracker
VariableStartAfter gaussian_filterFinal
image[[10,10,10],[10,50,10],[10,10,10]][[10,10,10],[10,50,10],[10,10,10]]Same as start
filteredNoneN/A[[12.5, 15.6, 12.5],[15.6, 22.5, 15.6],[12.5, 15.6, 12.5]]
Key Moments - 2 Insights
Why does the center pixel value decrease after filtering?
Because gaussian_filter smooths by averaging neighbors weighted by distance, the high center value (50) blends with lower neighbors (10), lowering it to about 22.5 (see execution_table step 3).
Why do corner pixels increase after filtering?
Corner pixels start at 10 but neighbors include the higher center pixel 50, so weighted averaging raises their value to about 12.5 (see execution_table step 4).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the approximate filtered value of the center pixel?
A22.5
B10
C50
D15.6
💡 Hint
Check execution_table row 3 where the center pixel calculation is shown.
At which step does the gaussian_filter produce the smoothed image array?
AStep 1
BStep 2
CStep 5
DStep 3
💡 Hint
Check execution_table row 2 where gaussian_filter is applied.
If sigma was increased, how would the filtered image values change?
ANo change in values
BLess smoothing, values closer to original
CMore smoothing, values more blended
DFiltered image becomes sharper
💡 Hint
Gaussian sigma controls smoothing strength; higher sigma means more blending.
Concept Snapshot
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
Full Transcript
We start with a small 3x3 image array with a bright center pixel. Applying gaussian_filter with sigma=1 smooths the image by averaging each pixel with neighbors weighted by distance. The center pixel value decreases because it blends with lower neighbors, while corner pixels increase slightly due to influence from the bright center. The final filtered image is a smoothed version with less sharp contrast. Increasing sigma would increase smoothing. This process helps reduce noise or details in images.