PIXELBANKv9.1.0
Menu

Implement a binary image dilation operation, which is a fundamental morphological operation in computer vision. This task involves expanding the boundaries of objects in a binary image using a structuring element.

The concept of dilation is crucial in image processing as it allows for the enlargement of objects, filling of gaps, and connection of separated components. Mathematically, dilation can be represented as a set operation, where the resulting image is formed by the union of the structuring element translated to each point in the original image.

To perform dilation, follow these steps:

  1. Center the structuring element at each pixel in the image.
  2. Check for overlap between the structuring element and the image.
  3. If any overlap is found, mark the corresponding pixel in the output image as 1.
Output(x,y)=max⁡(i,j)∈SEImage(x+i,y+j)\text{Output}(x, y) = \max_{(i, j) \in \text{SE}} \text{Image}(x + i, y + j)

This technique is widely used in image segmentation and object detection applications.

Example:

Input:
image = [[0,0,0],[0,1,0],[0,0,0]]
se = [[0,1,0],[1,1,1],[0,1,0]]
Output:
[[0, 1, 0], [1, 1, 1], [0, 1, 0]]
Reasoning:
  • The structuring element se is centered over each pixel in the image. When centered over the middle pixel of the image (which is 1), the overlapping pixels between se and image include the middle pixel of se and the corresponding 1 in the image.
  • The se has a size of 3×33 \times 3, so when it's centered over the middle pixel of the image, it extends one pixel to the left, right, top, and bottom of the middle pixel, covering the entire 3×33 \times 3 image.
  • For the pixels to the left, right, top, and bottom of the middle pixel in the image, the se overlaps with at least one 1 (the middle pixel of the image), resulting in the corresponding output pixels being set to 1.
  • The final output reflects the dilation operation, where any overlap between the se and a 1 in the image results in a 1 in the output, producing [[0, 1, 0], [1, 1, 1], [0, 1, 0]].

Constraints:

  • image is a 2D binary list (0 or 1)
  • se (structuring element) is a 2D binary list with odd dimensions
  • Return dilated binary image (same size as input)
🔒

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.