kwneuro.structural

Classes

StructuralImage

A structural (e.g. T1-weighted) MRI image.

Module Contents

class kwneuro.structural.StructuralImage

A structural (e.g. T1-weighted) MRI image.

volume: kwneuro.resource.VolumeResource

The structural MRI volume. Expected to be a 3D volume.

load() StructuralImage

Load any on-disk resources into memory and return a StructuralImage with all resources loaded.

save(path: kwneuro.util.PathLike, basename: str) StructuralImage

Save the volume to disk and return a StructuralImage with an on-disk resource.

Parameters:
  • path – The desired save directory.

  • basename – The desired file basename (without extension).

Returns: A StructuralImage with its internal resource being on-disk.

correct_bias() StructuralImage

Apply N4 bias field correction using ANTsPy.

Returns: A new StructuralImage with the bias-corrected volume.

extract_brain() kwneuro.resource.InMemoryVolumeResource

Extract a brain mask using HD-BET.

This is meant to be convenient rather than efficient. Using this in a loop could result in unnecessary repetition of file I/O operations. For efficiency, see kwneuro.masks.brain_extract_structural_batch().

segment_tissues(mask: kwneuro.resource.VolumeResource | None = None, method: str = 'atropos') kwneuro.resource.InMemoryVolumeResource

Segment brain tissues into labeled classes.

Parameters:
  • mask – Optional brain mask. Used only with method="atropos"; when omitted a mask is generated automatically via ants.get_mask(). Ignored for method="deep_atropos", which handles preprocessing internally.

  • method

    Segmentation method. One of:

    • "atropos" (default): Classical ANTsPy k-means Atropos. Returns a 3-class labeled volume (1=CSF, 2=GM, 3=WM). No extra installation required.

    • "deep_atropos": Deep-learning segmentation via ANTsPyNet. Returns a 6-class labeled volume (1=CSF, 2=GM, 3=WM, 4=deep GM, 5=cerebellum, 6=brainstem). Requires pip install kwneuro[antspynet].

Returns: A labeled segmentation volume.

parcellate(method: str = 'dkt') kwneuro.resource.InMemoryVolumeResource

Cortical parcellation.

Parameters:

method – Parcellation method. Currently only "dkt" is supported: Desikan-Killiany-Tourville (DKT) cortical labeling via ANTsPyNet (~84 regions). Requires pip install kwneuro[antspynet].

Returns: A DKT-labeled parcellation volume.