medpy.filter.binary.largest_connected_component#

medpy.filter.binary.largest_connected_component(img, structure=None)[source]#

Select the largest connected binary component in an image.

Treats all zero values in the input image as background and all others as foreground. The return value is an binary array of equal dimensions as the input array with TRUE values where the largest connected component is situated.

Parameters:
imgarray_like

An array containing connected objects. Will be cast to type bool.

structurearray_like

A structuring element that defines the connectivity. Structure must be symmetric. If no structuring element is provided, one is automatically generated with a squared connectivity equal to one.

Returns:
binary_imagendarray

The supplied binary image with only the largest connected component remaining.