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:
| input | thresholded image | magnitude for BET / HD-BET / RS2-Net / signal-gated erosion |
|---|---|---|
MaskingInput::MagnitudeFirst | echo 1 | echo 1 |
MaskingInput::Magnitude | root-sum-of-squares over echoes | the RSS |
MaskingInput::MagnitudeLast | last echo | last echo |
MaskingInput::PhaseQuality | ROMEO voxel quality of echoes 1–2, weighted by the RSS | the 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
inputthresholds (see the module docs). - run_
hd_ 🔒bet - Source the HD-BET weights and run it. Requires the
onnxfeature; weights come from the model registry throughcrate::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
onnxfeature; weights come from the model registry throughcrate::models(supplied bytes first, then local/download on native). - run_
rs2_ 🔒net - Source the RS2-Net weights and run it. Requires the
onnxfeature; weights come from the model registry throughcrate::models(supplied bytes first, then local/download on native). - section_
input 🔒 - The image a section with this
inputthresholds, built frommagnitude(that section’ssection_magnitude) and, for phase quality, the phases. - section_
magnitude - The magnitude a section with this
inputworks from (see the module docs): echo 1, the root-sum-of-squares over echoes, or the last echo.MaskingInput::PhaseQualityuses the RSS.Nonewhen there are no magnitudes.