Skip to main content

qsm_core/pipeline/
mod.rs

1//! QSM pipeline stages and utilities
2//!
3//! Shared stage functions that both qsmxt.rs and qsmbly call to ensure
4//! identical processing. Each consumer calls the stages individually with
5//! its own I/O and caching layer on top.
6//!
7//! ## Pipeline stages (typical order)
8//!
9//! 0. [`run_motion_correction`] — optional: co-register the echo series before fitting across it
10//! 1. [`run_field_mapping`] — multi-echo phase → B0 field map (ppm)
11//! 2. [`run_bg_removal`] — total field → local field (ppm)
12//! 3. [`run_dipole_inversion`] — local field → susceptibility (ppm)
13//! 4. [`apply_reference`] — mean subtraction
14//!
15//! Two-pass artefact reduction ([`two_pass`]) runs stages 2-3 a second time against a mask whose
16//! holes are intact, then folds the two reconstructions together.
17//!
18//! [`per_echo`] runs stages 1-4 once per echo instead ([`QsmPipelineConfig::qsm_per_echo`]): a
19//! QSM for each echo, and their mean.
20//!
21//! For TGV, use [`run_tgv`] which combines steps 1-4 internally.
22//!
23//! [`run_qsmart`] reports its progress and intermediates (vessel mask, per-stage local fields and
24//! χ) to an [`Observer`] as borrowed slices, so a host can show or save them without the stage
25//! keeping copies.
26//!
27//! [`rules`] says what each method requires, recommends and discourages of the rest of the
28//! configuration, with sources, and checks a configuration against it ([`rules::evaluate`]).
29//!
30//! ## Combined algorithms
31//!
32//! - HARPERELLA: SMV-based exterior Laplacian estimation (Li et al., 2014)
33//! - iHARPERELLA: Phase-domain exterior estimation with improved low-freq suppression (Li et al., 2015)
34
35// HARPERELLA / iHARPERELLA live in `bgremove` (their single canonical home);
36// the pipeline uses them via `crate::bgremove::...`.
37
38// Pipeline stage modules
39pub mod config;
40pub mod phase_utils;
41pub mod referencing;
42pub mod masking;
43pub mod motion;
44pub mod field_mapping;
45pub mod bg_removal;
46pub mod inversion;
47pub mod separation;
48pub mod observer;
49pub mod qsmart;
50pub mod two_pass;
51pub mod per_echo;
52pub mod rules;
53
54pub use config::*;
55pub use phase_utils::{
56    scale_phase_to_pi, hz_to_ppm, rads_to_ppm, ppm_to_hz, ppm_to_rads, rss_combine,
57};
58pub use referencing::apply_reference;
59pub use masking::{apply_mask_ops, build_mask_section, resolve_masking_input, run_masking, section_magnitude};
60pub use motion::{run_motion_correction, MotionCorrectionConfig, MotionCorrectionResult};
61pub use field_mapping::run_field_mapping;
62pub use bg_removal::run_bg_removal;
63pub use inversion::{heidi_seed_problem, run_dipole_inversion, run_heidi_cone_fill, run_tgv, run_nextqsm, run_iqsm, run_iqsm_plus, run_iqfm};
64pub use separation::{run_separation, SeparationInputs, SeparationResult};
65pub use observer::{Observer, VolumeRef};
66pub use qsmart::run_qsmart;
67pub use two_pass::{combine_two_pass, default_reliable_sections, restrict_reliable_mask};