Erosion and Dilation
======================
Implement erosion and dilation operations on a binary image.
Example:
Suppose we have a binary image represented as a 2D numpy array.
import numpy as np
# Binary image
image = np.array([
[0, 0, 1, 1, 0],
[0, 0, 1, 1, 0],
[0, 0, 0, 0, 0],
[1, 1, 1, 1, 1],
[0, 0, 0, 0, 0]
])
We want to perform erosion and dilation operations on this image using a 3x3 structuring element.
Constraints:
Your function should return the resulting images after the erosion and dilation operations.
Test Cases
Test Case 1
Input:
[[0, 0, 1, 1, 0],[0, 0, 1, 1, 0],[0, 0, 0, 0, 0],[1, 1, 1, 1, 1],[0, 0, 0, 0, 0]]Expected:
[[False, False, False, False, False],[False, False, False, False, False],[False, False, False, False, False],[False, False, False, False, False],[False, False, False, False, False]]Test Case 2
Input:
[[1, 1, 1, 1, 1],[1, 1, 1, 1, 1],[1, 1, 1, 1, 1],[1, 1, 1, 1, 1],[1, 1, 1, 1, 1]]Expected:
[[True, True, True, True, True],[True, True, True, True, True],[True, True, True, True, True],[True, True, True, True, True],[True, True, True, True, True]]+ 3 hidden test cases