Challenge - 5 Problems
Median and Uniform Filters Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of median filter on 1D array
What is the output of the following code applying a median filter with size 3 on a 1D array?
SciPy
import numpy as np from scipy.ndimage import median_filter arr = np.array([1, 2, 80, 4, 5, 6, 7]) filtered = median_filter(arr, size=3) print(filtered.tolist())
Attempts:
2 left
💡 Hint
Median filter replaces each element with the median of neighbors within the window size.
✗ Incorrect
The median filter with size 3 looks at each element and its neighbors (previous and next). For example, at index 2, neighbors are [2, 80, 4], median is 4. This smooths out the spike at 80.
❓ data_output
intermediate2:00remaining
Result of uniform filter on 2D array
What is the resulting 2D array after applying a uniform filter with size 3 on this 3x3 array?
SciPy
import numpy as np from scipy.ndimage import uniform_filter arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) filtered = uniform_filter(arr, size=3, mode='constant', cval=0) print(filtered)
Attempts:
2 left
💡 Hint
Uniform filter computes the average over the window including zero padding outside edges.
✗ Incorrect
The uniform filter with size 3 averages each 3x3 neighborhood. Since mode='constant' with cval=0, zeros pad the edges, lowering averages near borders.
❓ visualization
advanced3:00remaining
Visual effect of median vs uniform filter on noisy image
Which option best describes the visual difference after applying median and uniform filters on a noisy grayscale image?
SciPy
import numpy as np import matplotlib.pyplot as plt from scipy.ndimage import median_filter, uniform_filter np.random.seed(0) image = np.ones((10,10)) * 100 noise = np.random.randint(0, 50, (10,10)) noisy_image = image + noise median_img = median_filter(noisy_image, size=3) uniform_img = uniform_filter(noisy_image, size=3) plt.subplot(1,3,1) plt.title('Noisy') plt.imshow(noisy_image, cmap='gray') plt.subplot(1,3,2) plt.title('Median Filter') plt.imshow(median_img, cmap='gray') plt.subplot(1,3,3) plt.title('Uniform Filter') plt.imshow(uniform_img, cmap='gray') plt.show()
Attempts:
2 left
💡 Hint
Median filter is good for salt-and-pepper noise; uniform filter averages values.
✗ Incorrect
Median filter replaces each pixel with median of neighbors, preserving edges better. Uniform filter averages neighbors, causing blur and edge smoothing.
🧠 Conceptual
advanced2:00remaining
Effect of filter size on median and uniform filters
How does increasing the filter size affect the output of median and uniform filters on a noisy signal?
Attempts:
2 left
💡 Hint
Think about how larger windows affect averaging and median calculations.
✗ Incorrect
Larger filter sizes mean more neighbors considered, increasing smoothing. Median filter still preserves edges better but may remove small features as size grows.
🔧 Debug
expert2:00remaining
Identify the error in applying median filter on a 3D array
What error will this code raise when applying median_filter with size=3 on a 3D array without specifying axis?
SciPy
import numpy as np from scipy.ndimage import median_filter arr = np.random.randint(0, 10, (4,4,4)) filtered = median_filter(arr, size=3) print(filtered.shape)
Attempts:
2 left
💡 Hint
Check how median_filter handles size parameter for multi-dimensional arrays.
✗ Incorrect
median_filter accepts an integer size and applies it to all axes. The output shape matches input shape. No error occurs.