Skip to content
DeepForgeby svx
All problems
MediumComputer Visioncv-108

Bounding Boxes from Mask

Problem

Return the bounding boxes of all 4-connected components of 1-valued pixels.

Each box is [min_row, min_col, max_row, max_col] with inclusive indices, and boxes are listed in row-major order of the first pixel encountered. An empty mask returns [].

Test cases

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

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