mrsiprep.workflows.anatomical

Anatomical preparation workflow.

Functions

create_brain_csf_t1(skull_t1, raw_t1, p3, ...)

Re-add the CSF compartment to a skull-stripped T1w for the brain-csf registration target.

prepare_anatomical(config, subject, session, ...)

Resolve which T1w image/mask registration should target.

Classes

AnatomicalResult(t1w, raw_t1w, brain_mask, ...)

T1w images/masks selected for registration, from prepare_anatomical().

class mrsiprep.workflows.anatomical.AnatomicalResult(t1w, raw_t1w, brain_mask, registration_t1w, registration_mask, target_kind)[source]

Bases: object

T1w images/masks selected for registration, from prepare_anatomical().

Variables:
  • t1w -- The skull-stripped T1w passed in as t1_path (SynthSeg or CAT12 brain extraction output, depending on config.tissue_backend).

  • raw_t1w -- The original, non-skull-stripped T1w acquisition, if found in the BIDS layout; None if the dataset only provides a pre-skull-stripped image.

  • brain_mask -- Brain-only mask corresponding to t1w, if available.

  • registration_t1w -- The T1w image registration should actually target -- equal to t1w for the brain target, raw_t1w for raw, or a freshly built brain+CSF composite for brain-csf.

  • registration_mask -- Mask matching registration_t1w (None for the raw target, which registers without a fixed mask).

  • target_kind -- The resolved config.registration_t1_target value ("brain", "brain-csf", or "raw").

Parameters:
  • t1w (Path)

  • raw_t1w (Path | None)

  • brain_mask (Path | None)

  • registration_t1w (Path)

  • registration_mask (Path | None)

  • target_kind (str)

brain_mask: Path | None
raw_t1w: Path | None
registration_mask: Path | None
registration_t1w: Path
t1w: Path
target_kind: str
mrsiprep.workflows.anatomical.create_brain_csf_t1(skull_t1, raw_t1, p3, out_t1, out_mask, threshold=0.95, overwrite=False)[source]

Re-add the CSF compartment to a skull-stripped T1w for the brain-csf registration target.

Combines the skull_t1 brain mask with voxels where the CAT12 CSF probability map (p3) exceeds threshold, then masks raw_t1 with the union -- so CSF-adjacent MRSI signal isn't clipped at the brain-only boundary. skull_t1, raw_t1, and p3 must share the same shape and affine.

Parameters:
  • skull_t1 (Path) -- Skull-stripped T1w (defines the brain-only mask via > 0).

  • raw_t1 (Path) -- Original, non-skull-stripped T1w acquisition -- only its CSF-region voxels are used.

  • p3 (Path) -- CAT12 CSF tissue-probability map, same grid as skull_t1.

  • out_t1 (Path) -- Output path for the brain+CSF composite T1w.

  • out_mask (Path) -- Output path for the corresponding brain+CSF binary mask.

  • threshold (float) -- Minimum CSF probability (in p3) for a voxel outside the brain mask to be classified as CSF and included.

  • overwrite (bool) -- Recompute even if out_t1/out_mask already exist.

Returns:

(out_t1, out_mask).

Raises:

ValueError -- If the three input images don't share a shape or affine.

Return type:

tuple[Path, Path]

mrsiprep.workflows.anatomical.prepare_anatomical(config, subject, session, t1_path, p3_override=None, brain_mask_override=None)[source]

Resolve which T1w image/mask registration should target.

Dispatches on config.registration_t1_target:

  • "brain" -- register directly to the skull-stripped t1_path (the common case).

  • "brain-csf" -- build a fresh T1w with the CSF compartment re-added to the skull-stripped image (via create_brain_csf_t1(), using the CAT12 p3 CSF probability map), so CSF-adjacent MRSI signal isn't clipped at the brain-only boundary. Requires both a raw T1w acquisition and a p3 map to be found in the BIDS layout.

  • "raw" -- register to the original, non-skull-stripped T1w with no fixed mask.

Parameters:
  • config -- Run-wide mrsiprep.config.settings.MRSIPrepConfig.

  • subject (str) -- BIDS subject label, without the sub- prefix.

  • session (str | None) -- BIDS session label without the ses- prefix, or None for session-less datasets.

  • t1_path (Path) -- Skull-stripped T1w image (SynthSeg/CAT12 brain extraction output).

  • p3_override (Path | None) -- Explicit CAT12 p3 CSF probseg path, bypassing BIDS-layout lookup; used by brain-csf when set.

  • brain_mask_override (Path | None) -- Explicit brain mask path, bypassing BIDS-layout lookup.

Returns:

AnatomicalResult describing which image/mask pair downstream registration should use.

Raises:
  • FileNotFoundError -- If target_kind is "brain-csf" or "raw" and the required raw T1w / p3 map isn't found.

  • ValueError -- If config.registration_t1_target isn't one of the three supported values.

Return type:

AnatomicalResult