0
0
SciPydata~20 mins

Image filtering (gaussian_filter) in SciPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Gaussian Filter Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Gaussian filter on a simple 2D array
What is the output of applying gaussian_filter with sigma=1 to the following 2D array?
SciPy
import numpy as np
from scipy.ndimage import gaussian_filter

arr = np.array([[0, 0, 0], [0, 10, 0], [0, 0, 0]])
result = gaussian_filter(arr, sigma=1)
print(result.round(2))
A
[[0.46 0.91 0.46]
 [0.91 1.81 0.91]
 [0.46 0.91 0.46]]
B
[[0.00 0.00 0.00]
 [0.00 10.00 0.00]
 [0.00 0.00 0.00]]
C
[[1.00 1.00 1.00]
 [1.00 10.00 1.00]
 [1.00 1.00 1.00]]
D
[[0.10 0.20 0.10]
 [0.20 2.00 0.20]
 [0.10 0.20 0.10]]
Attempts:
2 left
💡 Hint
Think about how Gaussian smoothing spreads the value around neighbors.
🧠 Conceptual
intermediate
1:30remaining
Effect of increasing sigma in gaussian_filter
What happens to the output image when you increase the sigma parameter in gaussian_filter?
AThe image colors invert as sigma increases.
BThe image becomes sharper as sigma increases.
CThe image size increases as sigma increases.
DThe image becomes more blurred as sigma increases.
Attempts:
2 left
💡 Hint
Think about what smoothing means for an image.
🔧 Debug
advanced
1:30remaining
Identify the error in gaussian_filter usage
What error will this code raise when run?
SciPy
from scipy.ndimage import gaussian_filter

arr = [[1, 2], [3, 4]]
result = gaussian_filter(arr, sigma='two')
print(result)
ATypeError: sigma must be a number or sequence of numbers
BValueError: sigma cannot be a string
CSyntaxError: invalid syntax
DNo error, runs successfully
Attempts:
2 left
💡 Hint
Check the type expected for sigma parameter.
data_output
advanced
1:30remaining
Number of unique values after gaussian_filter
Given this 1D array, how many unique values does the output have after applying gaussian_filter with sigma=0.5?
SciPy
import numpy as np
from scipy.ndimage import gaussian_filter

arr = np.array([0, 0, 10, 0, 0])
result = gaussian_filter(arr, sigma=0.5)
unique_count = len(np.unique(result))
print(unique_count)
A1
B2
C3
D5
Attempts:
2 left
💡 Hint
Consider the symmetry of the array: edge positions are equal, next-to-center equal, center different.
🚀 Application
expert
2:00remaining
Choosing sigma for edge preservation in image smoothing
You want to smooth an image using gaussian_filter but keep edges sharp. Which sigma value strategy is best?
AUse a very large sigma to blur edges heavily.
BUse a very small sigma (close to 0) to minimize smoothing.
CUse sigma=0 to disable filtering.
DUse sigma=5 to smooth only edges.
Attempts:
2 left
💡 Hint
Less smoothing means edges stay sharper.