ants.label.multi_label_morphology
- multi_label_morphology(image, operation, radius, dilation_mask=None, label_list=None, force=False)[source]
Morphology on multi label images.
Wraps calls to iMath binary morphology. Additionally, dilation and closing operations preserve pre-existing labels. The choices of operation are:
Dilation: dilates all labels sequentially, but does not overwrite original labels. This reduces dependence on the intensity ordering of adjoining labels. Ordering dependence can still arise if two or more labels dilate into the same space - in this case, the label with the lowest intensity is retained. With a mask, dilated labels are multiplied by the mask and then added to the original label, thus restricting dilation to the mask region.
Erosion: Erodes labels independently, equivalent to calling iMath iteratively.
Closing: Close holes in each label sequentially, but does not overwrite original labels.
Opening: Opens each label independently, equivalent to calling iMath iteratively.
- Parameters:
image (
ants.core.ANTsImage) – Input image should contain only 0 for background and positive integers for labels.operation (
str) – One of MD, ME, MC, MO, passed to iMath.radius (
int) – radius of the morphological operation.dilation_mask (
ants.core.ANTsImage) – Optional binary mask to constrain dilation only (eg dilate cortical label into WM).label_list (
listortupleornumpy.ndarray) – Optional list of labels, to perform operation upon. Defaults to all unique intensities in image.
- Return type:
ants.core.ANTsImage
Example
>>> import ants >>> img = ants.image_read(ants.get_data('r16')) >>> labels = ants.get_mask(img,1,150) + ants.get_mask(img,151,225) * 2 >>> labels_dilated = ants.multi_label_morphology(labels, 'MD', 2) >>> # should see original label regions preserved in dilated version >>> # label N should have mean N and 0 variance >>> print(ants.label_stats(labels_dilated, labels))