All problems
Component Area Filter
Problem
Remove small connected components from a binary mask.
Keep only 4-connected components that have at least min_area pixels; all other pixels become 0. The output has the same shape as the input mask.
Test cases
case 1
in: [[[1,1,0],[0,1,0],[1,0,1]],2]
expected: [[1,1,0],[0,1,0],[0,0,0]]
case 2
in: [[[1,1,0],[0,1,0],[1,0,1]],1]
expected: [[1,1,0],[0,1,0],[1,0,1]]
case 3
in: [[[1,1,0],[0,1,0],[1,0,1]],4]
expected: [[0,0,0],[0,0,0],[0,0,0]]
Starter codePython
def filter_components(mask, min_area):
# Your code here
pass3 test cases · run your code against them in the editor