Skip to main content

Module masking

Module masking 

Source
Expand description

Masking stage

Generates a binary brain mask from magnitude/phase data using a configurable sequence of operations (threshold, BET, morphological ops). Multiple mask sections can be OR’d together.

§Each section builds its own input

The stage takes every echo’s magnitude, and each MaskSection builds what its MaskingInput asks for, independently of the other sections:

inputthresholded imagemagnitude for BET / HD-BET / RS2-Net / signal-gated erosion
MaskingInput::MagnitudeFirstecho 1echo 1
MaskingInput::Magnituderoot-sum-of-squares over echoesthe RSS
MaskingInput::MagnitudeLastlast echolast echo
MaskingInput::PhaseQualityROMEO voxel quality of echoes 1–2, weighted by the RSSthe RSS

Phase quality is weighted by the RSS, not echo 1: it is the highest-SNR magnitude there is, it is the same whatever other sections ask for, and it is what ROMEO itself weights by when unwrapping multi-echo data. With one echo the RSS is that echo.

Any homogeneity correction is the caller’s, applied to all echoes before they are passed in.

§Reference pipeline

The default section (ROMEO phase quality → Otsu threshold → dilate 1, fill holes, erode 1; MaskingConfig::default) is QSMxT’s phase-based masking: Stewart, A.W., Robinson, S.D., O’Brien, K., et al. (2022). “QSMxT: Robust masking and artifact reduction for quantitative susceptibility mapping.” Magn Reson Med 87(3):1289-1300, https://doi.org/10.1002/mrm.29048. The Python QSMxT releases’ defaults (qsmxt/qsm_pipelines.json:31-45,53, local copy 75d537c) differ from this one: Otsu scaled by threshold_algorithm_factor 1.5 (and 1.3 for the second pass), hole filling both (morphological and Gaussian), 2 erosions, two-pass masking, and no inhomogeneity correction (MaskingConfig::default has it on). The ROMEO authors’ own quality mask is a threshold of 0.1 on ROMEO’s voxel quality (ROMEO.jl ext/RomeoApp/argparse.jl:38-40, caller.jl:205-215). The brain-extraction generators (BET, HD-BET, RS2-Net, MindGrab) document their own reference inputs in their modules; of them only MindGrab needs ScanMetadata::affine, and HD-BET expects a volume already in MNI-like orientation.

Functions§

apply_mask_ops
Apply mask operations to an existing mask, in order.
build_mask_section
Build a mask from a single section (generator + refinements). The section builds its own input and magnitude from the echoes (see the module docs).
check_volumes 🔒
Check every volume is the grid’s size.
resolve_masking_input
The image a section with this input thresholds (see the module docs).
run_hd_bet 🔒
Source the HD-BET weights and run it. Requires the onnx feature; weights come from the model registry through crate::models (supplied bytes first, then local/download on native).
run_masking
Build a mask from multiple sections, OR’d together.
run_mindgrab 🔒
Source the MindGrab weights and run it. Requires the onnx feature; weights come from the model registry through crate::models (supplied bytes first, then local/download on native).
run_rs2_net 🔒
Source the RS2-Net weights and run it. Requires the onnx feature; weights come from the model registry through crate::models (supplied bytes first, then local/download on native).
section_input 🔒
The image a section with this input thresholds, built from magnitude (that section’s section_magnitude) and, for phase quality, the phases.
section_magnitude
The magnitude a section with this input works from (see the module docs): echo 1, the root-sum-of-squares over echoes, or the last echo. MaskingInput::PhaseQuality uses the RSS. None when there are no magnitudes.