Skip to content
DeepForgeby svx
All problems
MediumComputer Visioncv-031

Binary Dilation

Problem

Dilate a binary mask with a full 3x3 structuring element and zero padding.

A pixel becomes 1 if any pixel in its 3x3 neighborhood (clipped to the image) is 1. The output has the same shape as the mask.

Test cases

case 1
in: [[[0,0,0,0],[0,0,1,0],[0,0,0,0],[0,0,0,0]]]
expected: [[0,1,1,1],[0,1,1,1],[0,1,1,1],[0,0,0,0]]
case 2
in: [[[1,0],[0,0]]]
expected: [[1,1],[1,1]]
case 3
in: [[[0,0],[0,0]]]
expected: [[0,0],[0,0]]
case 4
in: [[[1,1],[1,1]]]
expected: [[1,1],[1,1]]
Starter codePython
def binary_dilate(mask):
    # Your code here
    pass

4 test cases · run your code against them in the editor