Erosion removes pixels at edges of white regions. The center pixel (0) surrounded by 255s will cause erosion to shrink the white area.
Step 2: Apply 3x3 kernel erosion
Since the kernel covers neighbors, any pixel with a zero neighbor becomes zero. The white cross shape will erode to a smaller cross with zeros at the center and edges.
Final Answer:
White cross with zeros at center and edges as shown in option A -> Option A
Quick Check:
Erosion shrinks white, so edge pixels vanish but some inner pixels remain [OK]
Hint: Erosion removes edge pixels, shrinking white areas [OK]
Common Mistakes:
Assuming erosion keeps center pixels
Confusing erosion with dilation output
Ignoring zero pixels in kernel neighborhood
4. You wrote this code to perform opening on an image img but it does not remove noise as expected:
kernel = np.ones((3,3), np.uint8)
opened = cv2.dilate(cv2.erode(img, kernel), kernel)
What is the error and how to fix it?
medium
A. Kernel size is too small; increase kernel size to remove noise.
B. The order is reversed; opening is dilation followed by erosion, so swap the calls.
C. Use cv2.morphologyEx with cv2.MORPH_OPEN instead for correct opening.
D. The order is reversed; opening is erosion followed by dilation, so code is correct.
Solution
Step 1: Check the definition of opening
Opening is erosion followed by dilation. The code applies erosion then dilation, which is correct in order.
Step 2: Identify practical issue
Manual calls may work but can be error-prone; using cv2.morphologyEx with MORPH_OPEN is recommended for correct and optimized opening.
Final Answer:
Use cv2.morphologyEx with cv2.MORPH_OPEN instead for correct opening. -> Option C
Quick Check:
Use built-in morphologyEx for opening [OK]
Hint: Use cv2.morphologyEx with MORPH_OPEN for opening [OK]
Common Mistakes:
Swapping erosion and dilation order
Not using built-in morphology functions
Assuming kernel size fixes logic errors
5. You have a noisy binary image with small black holes inside white objects. Which morphological operation should you apply to fill these holes without changing the object shapes much?
hard
A. Closing
B. Dilation
C. Opening
D. Erosion
Solution
Step 1: Understand the problem of black holes inside white objects
Black holes are small dark spots inside white regions that need to be filled.
Step 2: Choose operation that fills holes without shrinking objects
Closing is dilation followed by erosion; it fills small holes and gaps while preserving object shape.
Final Answer:
Closing -> Option A
Quick Check:
Closing fills holes inside white objects [OK]
Hint: Closing fills holes inside white objects [OK]