mrsiprep.tissue.synthseg_fast

SynthSeg-constrained FSL FAST tissue backend.

Functions

extract_t1_synthseg(config, subject, ...)

Create a SynthSeg-masked T1w and binary mask without running FAST.

find_freesurfer_tool(tool)

Locate a FreeSurfer tool without hardcoding a version.

run_or_load_synthseg_labels(config, subject, ...)

Return SynthSeg's native-resolution anatomical labels for t1_path.

segment_t1_synthseg_fast(config, subject, ...)

Segment GM/WM/CSF with SynthSeg-constrained FAST.

synthseg_fast_brain_mask_path(config, ...)

Derivative path for the binary brain mask matching synthseg_fast_brain_path().

synthseg_fast_brain_path(config, subject, ...)

Derivative path for the SynthSeg-masked (skull-stripped) T1w image.

synthseg_fast_csf_probseg_path(config, ...)

Derivative path for the SynthSeg+FAST CSF probability-segmentation map.

synthseg_fast_input_path(config, subject, ...)

Derivative path for the SynthSeg-masked T1w image FSL FAST is run on.

synthseg_native_labels_path(config, subject, ...)

Derivative path for SynthSeg's native-resolution anatomical label map (dseg).

synthseg_work_dir(config, subject, session)

Scratch working directory (under config.work_dir) for a recording's SynthSeg+FAST intermediates.

mrsiprep.tissue.synthseg_fast.extract_t1_synthseg(config, subject, session, t1_path)[source]

Create a SynthSeg-masked T1w and binary mask without running FAST.

Used by --mode midas, which needs SynthSeg brain extraction as an input to its own fuzzy c-means tissue segmentation (mrsiprep.tissue.fuzzy_cmeans.fuzzy_cmeans_segment()) instead of FAST.

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) -- Raw (non-skull-stripped) T1w image to segment.

Returns:

(brain_path, mask_path) -- the skull-stripped T1w and its binary brain mask. Recordings already extracted are skipped (returned as-is) unless config.overwrite_seg/config.overwrite is set.

Return type:

tuple[Path, Path]

mrsiprep.tissue.synthseg_fast.find_freesurfer_tool(tool)[source]

Locate a FreeSurfer tool without hardcoding a version.

Resolution order: PATH, then FREESURFER_HOME (direct and one level of version subdir), then any versioned install under the common roots (freesurfer-*/ or */ subdirs), newest-looking first.

Parameters:

tool (str)

Return type:

str

mrsiprep.tissue.synthseg_fast.run_or_load_synthseg_labels(config, subject, session, t1_path)[source]

Return SynthSeg's native-resolution anatomical labels for t1_path.

Runs mri_synthseg and caches its output at synthseg_native_labels_path(), or loads that cached array directly if it already exists (and config.overwrite_seg/config.overwrite is not set). Used both by segment_t1_synthseg_fast() and by callers that only need the raw label volume (e.g. brain-mask derivation) without running FAST.

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) -- Raw (non-skull-stripped) T1w image to segment.

Returns:

Integer SynthSeg label array, resampled onto t1_path's grid if mri_synthseg's own output grid differs.

Return type:

ndarray

mrsiprep.tissue.synthseg_fast.segment_t1_synthseg_fast(config, subject, session, t1_path)[source]

Segment GM/WM/CSF with SynthSeg-constrained FAST.

SynthSeg supplies the brain/CSF mask and anatomical labels. FAST runs only inside that mask and supplies the partial-volume estimates, which are then corrected for known SynthSeg/FAST disagreement at CSF/ventricle boundaries (see _apply_synthseg_csf_tissue_correction). This is the default (synthseg-fast) tissue_backend.

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) -- Raw (non-skull-stripped) T1w image to segment.

Returns:

{"GM": path, "WM": path, "CSF": path} of T1w-space tissue probability-segmentation maps. Recordings already segmented are skipped (returned as-is) unless config.overwrite_seg/ config.overwrite is set.

Return type:

dict[str, Path]

mrsiprep.tissue.synthseg_fast.synthseg_fast_brain_mask_path(config, subject, session)[source]

Derivative path for the binary brain mask matching synthseg_fast_brain_path().

Parameters:
  • subject (str)

  • session (str | None)

Return type:

Path

mrsiprep.tissue.synthseg_fast.synthseg_fast_brain_path(config, subject, session)[source]

Derivative path for the SynthSeg-masked (skull-stripped) T1w image.

Parameters:
  • subject (str)

  • session (str | None)

Return type:

Path

mrsiprep.tissue.synthseg_fast.synthseg_fast_csf_probseg_path(config, subject, session)[source]

Derivative path for the SynthSeg+FAST CSF probability-segmentation map.

Parameters:
  • subject (str)

  • session (str | None)

Return type:

Path

mrsiprep.tissue.synthseg_fast.synthseg_fast_input_path(config, subject, session)[source]

Derivative path for the SynthSeg-masked T1w image FSL FAST is run on.

Parameters:
  • subject (str)

  • session (str | None)

Return type:

Path

mrsiprep.tissue.synthseg_fast.synthseg_native_labels_path(config, subject, session)[source]

Derivative path for SynthSeg's native-resolution anatomical label map (dseg).

The filename encodes config.synthseg_mode (fast/standard/ robust), so switching modes doesn't reuse a stale cached segmentation from a different mode.

Parameters:
  • subject (str)

  • session (str | None)

Return type:

Path

mrsiprep.tissue.synthseg_fast.synthseg_work_dir(config, subject, session)[source]

Scratch working directory (under config.work_dir) for a recording's SynthSeg+FAST intermediates.

Parameters:
  • subject (str)

  • session (str | None)

Return type:

Path