0
0
Computer Visionml~20 mins

Morphological operations (erosion, dilation, opening, closing) in Computer Vision - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Morphological Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of erosion on a binary image
Given the following 5x5 binary image and a 3x3 square structuring element, what is the output after applying one iteration of erosion?
Computer Vision
import numpy as np
import cv2

image = np.array([
  [1, 1, 1, 1, 0],
  [1, 1, 1, 1, 0],
  [1, 1, 1, 1, 0],
  [1, 1, 1, 1, 1],
  [0, 0, 0, 1, 1]
], dtype=np.uint8)

kernel = np.ones((3,3), np.uint8)
eroded = cv2.erode(image, kernel, iterations=1)
print(eroded)
A
[[1 1 1 0 0]
 [1 1 1 0 0]
 [1 1 1 0 0]
 [0 0 0 1 1]
 [0 0 0 1 1]]
B
[[0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]]
C
[[0 0 0 0 0]
 [0 1 1 0 0]
 [0 1 1 0 0]
 [0 0 0 0 0]
 [0 0 0 0 1]]
D
[[0 0 0 0 0]
 [0 1 1 0 0]
 [0 1 1 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]]
Attempts:
2 left
💡 Hint
Erosion shrinks white regions by removing pixels on object boundaries where the structuring element does not fit entirely.
🧠 Conceptual
intermediate
1:30remaining
Effect of dilation on image noise
Which of the following best describes the effect of applying dilation to a binary image with small isolated noise pixels?
ADilation enlarges white regions and can cause isolated noise pixels to grow.
BDilation removes isolated noise pixels by shrinking white regions.
CDilation converts white pixels to black pixels in isolated noise areas.
DDilation has no effect on isolated noise pixels.
Attempts:
2 left
💡 Hint
Think about how dilation changes the size of white areas.
Hyperparameter
advanced
2:00remaining
Choosing kernel size for opening operation
You want to remove small white noise dots from a binary image without affecting larger objects. Which kernel size for the opening operation is most appropriate?
AA kernel size slightly larger than the noise dots but smaller than the smallest object.
BA kernel size smaller than the noise dots but larger than the smallest object.
CA very large kernel that is bigger than the largest object in the image.
DA kernel size equal to the entire image size.
Attempts:
2 left
💡 Hint
Opening removes small objects smaller than the kernel size.
Metrics
advanced
1:30remaining
Evaluating closing operation effect
After applying a closing operation on a binary image, which metric would best indicate that small black holes inside white objects have been filled?
AIncrease in the number of connected white components.
BIncrease in the total white pixel area inside objects.
CDecrease in the number of white pixels.
DDecrease in the total black pixel area outside objects.
Attempts:
2 left
💡 Hint
Closing fills small black holes inside white regions.
🔧 Debug
expert
2:00remaining
Identifying error in morphological operation code
What error will this code raise when applying dilation with an invalid kernel shape? import numpy as np import cv2 image = np.array([[0,1,0],[1,1,1],[0,1,0]], dtype=np.uint8) kernel = np.array([1,1,1]) # Incorrect kernel shape result = cv2.dilate(image, kernel)
AValueError: invalid kernel shape
BTypeError: kernel must be a 2D array
Ccv2.error: (-215:Assertion failed) !ksize.empty() in function 'dilate'
DNo error, code runs successfully
Attempts:
2 left
💡 Hint
Check the expected shape of the kernel argument in OpenCV dilation.