Skip to main content

largest_filled_object

largest_filled_object(mask)

The biggest connected piece of a mask, with its holes filled.

The repair a shape measurement needs before it can mean anything, and it is applied to the truth as well as to the prediction so that both sides of a comparison went through the same arithmetic. A prediction is not an ellipse: it can arrive in two pieces or with a hole in the middle, and the second moments of either are not the second moments of the object - a hole pushes the variance outwards and a stray island drags the centre.

Parameters

Name Type Description Default
mask np.ndarray Anything with a foreground; read as a boolean through > 0. required

Returns

Name Type Description
np.ndarray A boolean array of the same shape, with one connected region.

mask = np.zeros((9, 9), dtype=bool) mask[1:8, 1:8] = True mask[4, 4] = False # a hole mask[0, 8] = True # and a stray pixel int(largest_filled_object(mask).sum()) 49