Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to perform dilation on the binary image.
MATLAB
dilatedImage = imdilate(binaryImage, [1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using fspecial which is for filtering, not morphological operations.
Passing an image instead of a structuring element to imdilate.
✗ Incorrect
The function imdilate requires a structuring element, here a square of size 5 is used.
2fill in blank
mediumComplete the code to perform erosion on the binary image.
MATLAB
erodedImage = imerode(binaryImage, [1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using imdilate instead of imerode.
Using filtering functions like fspecial.
✗ Incorrect
imerode requires a structuring element; here a disk of radius 2 is appropriate.
3fill in blank
hardFix the error in the code to perform morphological opening.
MATLAB
openedImage = imopen(binaryImage, [1]);Attempts:
3 left
💡 Hint
Common Mistakes
Passing an image or filter instead of a structuring element.
Using imerode or imdilate directly instead of imopen.
✗ Incorrect
imopen requires a structuring element, not an image or filter.
4fill in blank
hardFill both blanks to create a structuring element and perform morphological closing.
MATLAB
se = [1]; closedImage = imclose(binaryImage, [2]);
Attempts:
3 left
💡 Hint
Common Mistakes
Using different structuring elements in creation and closing.
Passing the structuring element creation call directly to imclose instead of the variable.
✗ Incorrect
First create the structuring element 'se' with strel('diamond', 4), then use it in imclose.
5fill in blank
hardFill all three blanks to create a structuring element, perform morphological gradient, and display the result.
MATLAB
se = [1]; gradientImage = imsubtract(imdilate(binaryImage, [2]), imerode(binaryImage, [3])); imshow(gradientImage);
Attempts:
3 left
💡 Hint
Common Mistakes
Using different structuring elements for dilation and erosion.
Not using the variable 'se' consistently.
✗ Incorrect
Create 'se' with strel('square', 3), then use 'se' for both dilation and erosion in the gradient calculation.
