Challenge - 5 Problems
Image Filtering Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of 3x3 averaging filter on a grayscale image
What is the output matrix after applying the given 3x3 averaging filter to the input image matrix?
MATLAB
input_img = [10 20 30; 40 50 60; 70 80 90]; filter = ones(3,3) / 9; output_img = conv2(input_img, filter, 'valid'); disp(output_img);
Attempts:
2 left
💡 Hint
Remember that 'valid' convolution returns only positions where the filter fully overlaps the image.
✗ Incorrect
The 3x3 averaging filter sums all 9 pixels in the 3x3 window and divides by 9. Sum is 10+20+30+40+50+60+70+80+90=450, average is 50. Since 'valid' is used on 3x3 input and 3x3 filter, conv2 returns 1x1 output [50].
🧠 Conceptual
intermediateEffect of zero-padding in image filtering
What is the main effect of using zero-padding when applying a filter to an image in MATLAB?
Attempts:
2 left
💡 Hint
Think about how padding affects the borders of the image during filtering.
✗ Incorrect
Zero-padding adds zeros around the image edges so the filter can be applied at the borders. This keeps the output image size the same as the input and helps preserve edge information.
🔧 Debug
advancedIdentify the error in median filtering code
What error will this MATLAB code produce when applying a median filter to a grayscale image?
MATLAB
img = imread('cameraman.tif'); filtered_img = medfilt2(img, [3 3 3]); imshow(filtered_img);
Attempts:
2 left
💡 Hint
Check the number of dimensions specified in the filter size argument.
✗ Incorrect
The medfilt2 function expects a 2-element vector for the filter size. Passing [3 3 3] is invalid and causes an error because SIZE must be a two-element vector.
📝 Syntax
advancedSyntax error in applying Gaussian filter
Which option contains the correct syntax to apply a Gaussian filter with standard deviation 2 to an image 'img' using MATLAB's imgaussfilt function?
Attempts:
2 left
💡 Hint
Check the function signature and how parameters are passed in MATLAB.
✗ Incorrect
imgaussfilt takes the image and the standard deviation as the second positional argument. Named parameters require name-value pairs as strings.
🚀 Application
expertNumber of pixels changed after edge detection filter
Given a 5x5 grayscale image matrix with all values 100 except the center pixel which is 0, how many pixels will have a non-zero value after applying the following edge detection filter?
filter = [-1 -1 -1; -1 8 -1; -1 -1 -1];
output_img = conv2(img, filter, 'same');
MATLAB
img = 100*ones(5,5); img(3,3) = 0; filter = [-1 -1 -1; -1 8 -1; -1 -1 -1]; output_img = conv2(img, filter, 'same'); nonzero_count = nnz(output_img);
Attempts:
2 left
💡 Hint
Consider how the filter highlights differences around the center pixel.
✗ Incorrect
The filter detects edges by emphasizing differences. The center pixel is 0 surrounded by 100s, so the 3x3 neighborhood around the center will have non-zero values after filtering, totaling 9 pixels.
