All problems
Bounding Box of a Mask
Problem
Find the bounding box of the non-zero pixels in a binary mask.
Return [min_row, min_col, max_row, max_col] using inclusive indices, scanned in row-major order. Return None when the mask contains no non-zero pixel.
Test cases
case 1
in: [[[0,1,0],[1,1,0],[0,0,0]]]
expected: [0,0,1,1]
case 2
in: [[[1]]]
expected: [0,0,0,0]
case 3
in: [[[0,0],[0,0]]]
expected: null
case 4
in: [[[1,0,1],[0,0,0],[1,0,1]]]
expected: [0,0,2,2]
Starter codePython
def bounding_box(mask):
# Your code here
pass4 test cases · run your code against them in the editor