medpy.filter.binary.size_threshold#

medpy.filter.binary.size_threshold(img, thr, comp='lt', structure=None)[source]#

Removes binary objects from an image identified by a size threshold.

The unconnected binary objects in an image are identified and all removed whose size compares (e.g. less-than) to a supplied threshold value.

The threshold thr can be any positive integer value. The comparison operator can be one of lt, le, gt, ge, ne or eq. The operators used are the functions of the same name supplied by the operator module of python.

Parameters:
imgarray_like

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

thrint

Integer defining the threshold size of the binary objects to remove.

comp{‘lt’, ‘le’, ‘gt’, ‘ge’, ‘ne’, ‘eq’}

The type of comparison to perform. Use e.g. ‘lt’ for less-than.

structurearray of ints, optional

A structuring element that defines feature connections. structure must be symmetric. If no structuring element is provided, one is automatically generated with a squared connectivity equal to one. That is, for a 2-D input array, the default structuring element is:

[[0,1,0],
 [1,1,1],
 [0,1,0]]
Returns:
binary_imagendarray

The supplied binary image with all objects removed that positively compare to the threshold thr using the comparison operator defined with comp.

Notes

If your voxel size is no isotrop i.e. of side-length 1 for all dimensions, simply divide the supplied threshold through the real voxel size.