segmentationtools module

clabtoolkit.segmentationtools.abased_parcellation(t1, t1_temp, atlas, out_parc, xfm_output, atlas_type='spam', interp='Linear', cont_tech='local', cont_image=None, force=False)[source]

Perform atlas-based parcellation using ANTs registration and transformation.

Registers individual T1-weighted image to template space, then applies inverse transformation to bring atlas into subject space, creating subject-specific parcellation based on template atlas.

Parameters:
  • t1 (str) – Path to input T1-weighted image.

  • t1_temp (str) – Path to T1-weighted template image for registration target.

  • atlas (str) – Path to atlas image (either SPAM probabilities or discrete labels).

  • out_parc (str) – Path for output parcellation file.

  • xfm_output (str) – Base path/name for transformation files. Extensions and descriptors will be automatically added.

  • atlas_type (str, optional) – Atlas format: ‘spam’ for probability maps or ‘maxprob’ for discrete labels. Default is ‘spam’.

  • interp (str, optional) – Interpolation method: ‘Linear’, ‘NearestNeighbor’, ‘BSpline’. Default is ‘Linear’.

  • cont_tech (str, optional) – Container technology: ‘local’, ‘singularity’, ‘docker’. Default is ‘local’.

  • cont_image (str, optional) – Container image specification. Default is None.

  • force (bool, optional) – Whether to overwrite existing files. Default is False.

Returns:

Path to the generated parcellation file.

Return type:

str

Notes

The method performs the following steps: 1. ANTs SyN registration between subject T1 and template 2. Generates affine and non-linear transformation files 3. Applies inverse transformation to atlas 4. For SPAM atlases, preserves probability values 5. For maxprob atlases, uses nearest neighbor interpolation

Generated transformation files follow BIDS naming conventions with descriptors: affine, warp, iwarp.

Examples

>>> # Basic SPAM atlas parcellation
>>> parc_file = abased_parcellation(
...     t1='subject_T1w.nii.gz',
...     t1_temp='MNI152_T1_1mm.nii.gz',
...     atlas='AAL_SPAM.nii.gz',
...     out_parc='subject_AAL.nii.gz',
...     xfm_output='transforms/subject_to_MNI'
... )
>>>
>>> # Discrete atlas with nearest neighbor interpolation
>>> parc_file = abased_parcellation(
...     t1='T1w.nii.gz',
...     t1_temp='template.nii.gz',
...     atlas='discrete_atlas.nii.gz',
...     out_parc='parcellation.nii.gz',
...     xfm_output='xfm/transform',
...     atlas_type='maxprob'
... )
clabtoolkit.segmentationtools.tissue_seg_table(tsv_filename)[source]

Create standard tissue segmentation lookup table.

Parameters:

tsv_filename (str) – Output TSV file path.

Returns:

DataFrame with tissue segmentation information (CSF, GM, WM).

Return type:

pd.DataFrame

Examples

>>> seg_df = Parcellation.tissue_seg_table('tissues.tsv')
>>> print(seg_df)

The segmentationtools module provides atlas-based and automated image segmentation capabilities, with particular focus on brain parcellation using template registration.

Key Features

  • Atlas-based parcellation using ANTs registration

  • Template-based segmentation workflows

  • Multi-atlas segmentation support

  • Registration parameter optimization

  • Quality control for segmentation results

  • Integration with multiple neuroimaging atlases

Main Functions

Atlas-based Segmentation

  • abased_parcellation(): Perform atlas-based parcellation using ANTs

  • tissue_seg_table(): Create tissue segmentation table from FreeSurfer data

Common Usage Examples

Basic atlas-based segmentation:

from clabtoolkit.segmentationtools import abased_parcellation

# Perform atlas-based parcellation
abased_parcellation(
    moving_image="sub-001_T1w.nii.gz",
    atlas_image="MNI152_T1_1mm.nii.gz",
    atlas_labels="MNI152_parcellation.nii.gz",
    output_prefix="sub-001_space-MNI152",
    registration_type="SyN"
)

Tissue segmentation analysis:

# Create tissue segmentation summary table
tissue_stats = tissue_seg_table(
    aseg_file="/path/to/aseg.mgz",
    subject_id="sub-001",
    session_id="ses-01"
)

print(tissue_stats[['region', 'volume_mm3']].head())