Challenge - 5 Problems
Morphological Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of erosion on a binary image
What is the output array after applying erosion with a 3x3 square structuring element on the given binary image?
SciPy
import numpy as np from scipy.ndimage import binary_erosion image = np.array([ [0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0] ], dtype=bool) structure = np.ones((3,3), dtype=bool) eroded = binary_erosion(image, structure=structure) print(eroded.astype(int))
Attempts:
2 left
💡 Hint
Erosion shrinks the white regions by removing pixels on the edges.
✗ Incorrect
Erosion with a 3x3 structuring element removes pixels on the border of the white square, leaving only the center pixel as 1.
❓ Predict Output
intermediate2:00remaining
Result of dilation on a sparse binary image
What is the output after applying dilation with a 3x3 cross-shaped structuring element on the binary image below?
SciPy
import numpy as np from scipy.ndimage import binary_dilation image = np.array([ [0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0] ], dtype=bool) structure = np.array([ [0, 1, 0], [1, 1, 1], [0, 1, 0] ], dtype=bool) dilated = binary_dilation(image, structure=structure) print(dilated.astype(int))
Attempts:
2 left
💡 Hint
Dilation adds pixels around existing white pixels according to the structuring element shape.
✗ Incorrect
The cross-shaped structuring element dilates the single pixel to its immediate neighbors in a cross shape.
❓ visualization
advanced3:00remaining
Visualize erosion and dilation effects
Which option shows the correct pair of images after applying erosion and dilation respectively on the given binary image with a 3x3 square structuring element?
SciPy
import numpy as np from scipy.ndimage import binary_erosion, binary_dilation import matplotlib.pyplot as plt image = np.array([ [0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0] ], dtype=bool) structure = np.ones((3,3), dtype=bool) eroded = binary_erosion(image, structure=structure) dilated = binary_dilation(image, structure=structure) fig, axs = plt.subplots(1, 2) axs[0].imshow(eroded, cmap='gray') axs[0].set_title('Erosion') axs[1].imshow(dilated, cmap='gray') axs[1].set_title('Dilation') plt.show()
Attempts:
2 left
💡 Hint
Erosion shrinks white areas, dilation expands them.
✗ Incorrect
Erosion reduces the 3x3 white square to a single pixel, dilation expands it to fill the entire 5x5 area.
🧠 Conceptual
advanced1:30remaining
Effect of structuring element shape on dilation
Which statement correctly describes how the shape of the structuring element affects the dilation result on a binary image?
Attempts:
2 left
💡 Hint
Think about how dilation adds pixels around existing ones.
✗ Incorrect
Dilation adds pixels in the shape of the structuring element around each white pixel, so the output shape depends on the structuring element shape.
🔧 Debug
expert2:00remaining
Identify the error in morphological operation code
What error will occur when running the following code snippet for erosion, and why?
SciPy
import numpy as np from scipy.ndimage import binary_erosion image = np.array([ [1, 1, 1], [1, 0, 1], [1, 1, 1] ]) structure = np.array([ [1, 1], [1, 1] ]) eroded = binary_erosion(image, structure=structure) print(eroded)
Attempts:
2 left
💡 Hint
Check the data type required by binary_erosion for the input image.
✗ Incorrect
binary_erosion expects a boolean array for the image. Using integers without converting to boolean causes a TypeError.