ANTsPy Segmentation and Labels
Use this sub-skill when a task asks for ANTsPy segmentation, label images, connected components, label statistics, overlap/geometry measures, label matrices, centroid or point-image workflows, multi-label morphology, or segmentation-to-mask/registration handoffs.
Start Here
- Import the public package as
import ants; the package distribution isantspyx. - Check verified signatures and return contracts in API reference.
- Pick a recipe from workflows: k-means, Atropos, Otsu, prior-based segmentation, joint label fusion, label stats/overlap/matrix, point images, or mask alignment validation.
- Use troubleshooting before changing class counts, masks, priors, label dtypes, or physical metadata.
- Run scripts/antspy_segmentation_smoke.py for a tiny deterministic in-memory check in an environment with
antspyxinstalled.
Core Contracts
ants.atropos(...),ants.kmeans_segmentation(...), andants.prior_based_segmentation(...)return dictionaries withsegmentationandprobabilityimages;ants.otsu_segmentation(...)returns only anANTsImagelabel image.ants.joint_label_fusion(...)returns anANTsImagefor intensity-only fusion when no labels are supplied, and a dictionary withsegmentation,intensity,probabilityimages, andsegmentation_numberswhenlabel_listis supplied.ants.fuzzy_spatial_cmeans_segmentation(...)andants.functional_lung_segmentation(...)use snake_case keyssegmentation_imageandprobability_images; lung segmentation also returnsprocessed_image.- Label-measure helpers generally clone labels to
unsigned int; non-integer or out-of-range labels can fail or silently collapse if not validated first. - Overlap, statistics, matrices, and label/image interactions assume matching dimension, shape, origin, spacing, and direction; validate with image-core helpers before computing metrics.
- Register intensity images with registration-transforms, apply transforms to labels with nearest-neighbor or label-safe interpolation, then return here for label statistics and overlap.
Route Elsewhere
- Image creation, IO, cloning, metadata repair, dtype conversion,
image_physical_space_consistency, and coordinate transforms: image-core. - Generic masks, thresholding, binary/grayscale morphology, smoothing, resampling, bias correction, and
iMath: image-ops-math. - Registration mechanics, transform lists, and label-safe transform application: registration-transforms.
- Plotting label overlays or exporting images for visualization: visualization-interop.
- Learning one-hot segmentation, patch extraction, and augmentation workflows: learning-deeplearn.
References
- API reference: verified public signatures, return keys, label dataframe contracts, dtype rules, and expensive-function caveats.
- Workflows: self-contained recipes for segmentation, priors, labels, overlap/statistics, label matrices, centroids, points, and registration/mask interactions.
- Troubleshooting: Atropos probability failures, mask/image mismatch, class ordering, label dtype handling, joint label fusion/KellyKapowski costs, and physical-space consistency before overlap.