PIXELBANKv9.1.0
Menu

Morphological Boundary Extraction

Implement a morphological operation to extract the boundary of objects in a binary image using a given structuring element. This process involves applying erosion to the image and then subtracting the eroded result from the original image.

The concept of morphological operations is crucial in Computer Vision as it allows for the analysis and manipulation of shapes in images. Erosion is a fundamental operation that shrinks objects in an image by removing pixels from their boundaries. The structuring element is a small binary image used to probe the input image, determining which pixels to remove.

To extract the boundary, the following steps are involved:

  1. Apply erosion to the input image using the structuring element.
  2. Subtract the eroded image from the original image.
boundary=image−erode(image,se)\text{boundary} = \text{image} - \text{erode}(\text{image}, \text{se})

This technique is widely used in image processing and object detection tasks.

Example:

Input:
image = [[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]]
se = [[0,1,0],[1,1,1],[0,1,0]]
Output:
[[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 0, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]]
Reasoning:
  • The given image is first eroded using the structuring element (se): erode(image,se)erode(\text{image}, \text{se}). This process applies the se to each pixel in the image, effectively shrinking the objects.
  • The erosion operation with the given se removes the boundary pixels of the objects in the image, resulting in: [[0,0,0,0,0],[0,0,0,0,0],[0,1,1,1,0],[0,0,0,0,0],[0,0,0,0,0]]
  • The boundary of the objects is then extracted by subtracting the eroded image from the original image: boundary=image−erode(image,se)\text{boundary} = \text{image} - \text{erode}(\text{image}, \text{se}). This leaves only the boundary pixels of the original objects.
  • The resulting boundary image is: [[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 0, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]]

Constraints:

  • image is a 2D binary list (0 or 1)
  • se is a 2D binary structuring element with odd dimensions
  • Return the boundary as a binary 2D list
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Morphological Boundary Extraction - Medium | PixelBank