Dilation adds pixels to the edges of white regions (1s), expanding them by one pixel in all directions.
Step 2: Apply dilation to given image
Original white pixels at (1,1),(1,2),(2,1). After dilation, neighbors become 1, resulting in the array in [[0 1 1 0 0]
[1 1 1 1 0]
[1 1 1 0 0]
[0 1 0 0 0]].
Hint: Dilation grows white pixels by one layer [OK]
Common Mistakes:
Confusing dilation with erosion
Not converting boolean to int for print
Misreading array indices
4. The following code is intended to perform erosion on a binary image, but it raises an error. What is the problem?
import numpy as np
from scipy.ndimage import erosion
image = np.array([[1, 1, 0],
[1, 0, 0],
[0, 0, 1]])
result = erosion(image)
print(result)
medium
A. The function 'erosion' does not exist in scipy.ndimage; use 'binary_erosion' instead.
B. The input image must be float type, not int.
C. The image array shape is invalid for erosion.
D. The print statement syntax is incorrect.
Solution
Step 1: Check function availability
Scipy.ndimage does not have a function named 'erosion'; the correct function is 'binary_erosion'.
Step 2: Correct the import and usage
Replace 'from scipy.ndimage import erosion' with 'from scipy.ndimage import binary_erosion' and call 'binary_erosion(image)'.
Final Answer:
The function 'erosion' does not exist in scipy.ndimage; use 'binary_erosion' instead. -> Option A
Quick Check:
Use binary_erosion, not erosion [OK]
Hint: Use binary_erosion, not erosion function [OK]
Common Mistakes:
Trying to import non-existent 'erosion'
Ignoring error messages
Assuming all morphological functions have simple names
5. You have a noisy binary image with small white dots scattered outside the main object. Which sequence of morphological operations using scipy.ndimage would best remove these small dots but keep the main shape mostly intact?
hard
A. Apply erosion followed by dilation (opening) to remove small objects.
B. Apply dilation followed by erosion (closing) to fill small holes.
C. Apply only dilation to enlarge all white areas.
D. Apply only erosion to shrink all white areas drastically.
Solution
Step 1: Understand noise removal goal
Small white dots are noise; we want to remove them without changing main shape much.
Step 2: Choose correct morphological sequence
Opening (erosion then dilation) removes small objects but keeps main shape. Closing fills holes, not remove dots.
Final Answer:
Apply erosion followed by dilation (opening) to remove small objects. -> Option A
Quick Check:
Opening = erosion + dilation removes noise [OK]
Hint: Use opening (erosion then dilation) to remove small noise [OK]
Common Mistakes:
Using closing instead of opening for noise removal