Expand description
MEDI (Morphology Enabled Dipole Inversion) L1 regularization
Gauss-Newton optimization with L1 TV regularization and morphology-based gradient weighting from magnitude images.
Features:
- Per-direction gradient masks (mx, my, mz) matching the original MEDI formulation
- Adaptive edge detection with configurable percentage threshold (default: 30% edges)
- SNR-based data weighting using noise standard deviation maps
- Optional SMV (Spherical Mean Value) preprocessing
- Optional merit-based outlier adjustment (MERIT)
- Optimized with f32 single precision for WASM performance
- Buffer reuse to minimize allocations
- Standard CG convergence (relative tolerance)
- Linear extrapolation boundary conditions matching MATLAB’s gradf
Reference: Liu, T., Liu, J., de Rochefort, L., Spincemaille, P., Khalidov, I., Ledoux, J.R., Wang, Y. (2011). “Morphology enabled dipole inversion (MEDI) from a single-angle acquisition: comparison with COSMOS in human brain imaging.” Magnetic Resonance in Medicine, 66(3):777-783. https://doi.org/10.1002/mrm.22816
Liu, J., Liu, T., de Rochefort, L., Ledoux, J., Khalidov, I., Chen, W., Tsiouris, A.J., Wisnieff, C., Spincemaille, P., Prince, M.R., Wang, Y. (2012). “Morphology enabled dipole inversion for quantitative susceptibility mapping using structural consistency between the magnitude image and the susceptibility map.” NeuroImage, 59(3):2560-2568.
Reference implementation: https://github.com/huawu02/MEDI_toolbox
Structs§
- Medi
OpBuffers 🔒 - MEDI operator buffers - separate struct to allow split borrowing
- Medi
Params - MEDI algorithm parameters
- Medi
Workspace - Workspace for MEDI operations - holds all reusable buffers (f32 version) Uses single precision for ~2x speedup on WASM
Functions§
- apply_
dipole_ 🔒conv - Apply dipole convolution: out = real(ifft(D * fft(x)))
- apply_
medi_ 🔒operator_ core - Apply MEDI operator in-place: out = fidelity(dx) + lambda*reg(dx) This is the hot path - called many times per Gauss-Newton iteration Uses per-direction gradient masks (mx, my, mz) matching MATLAB MEDI SIMD-accelerated for element-wise operations
- apply_
smv_ 🔒kernel_ ws - Apply SMV kernel using workspace buffers (f32)
- bdiv_
periodic_ 🔒inplace_ f32 - Backward divergence with periodic boundary conditions (f32, in-place) Adjoint of fgrad_periodic_inplace_f32, matching MATLAB’s gradfp_adj_mex. At boundaries, wraps around: at i=0, uses gx(end) instead of zero.
- cg_
solve_ 🔒medi - Conjugate gradient solver with buffer reuse Solves Ax = b where A is the MEDI operator
- compute_
rhs_ 🔒inplace - Compute RHS in-place using workspace buffers (f32) Uses per-direction gradient masks (mx, my, mz) matching MATLAB MEDI SIMD-accelerated for element-wise operations
- dataterm_
mask_ 🔒f32 - Generate data weighting mask (f32)
- fgrad_
linext_ 🔒f32 - Forward difference gradient with linear extrapolation boundary conditions (f32) Matches MATLAB’s gradf behavior: dx(end) = dx(end-1)
- fgrad_
linext_ 🔒inplace_ f32 - Forward difference gradient with linear extrapolation boundary conditions (f32, in-place) Matches MATLAB’s gradf behavior: dx(end) = dx(end-1)
- fgrad_
periodic_ 🔒inplace_ f32 - Forward difference gradient with periodic boundary conditions (f32, in-place) Matches MATLAB’s gradfp_mex used inside MEDI iterations. At boundaries, wraps around: dx(end) = (x(1) - x(end)) / h
- gradient_
mask_ 🔒f32 - Generate per-direction gradient weighting masks (f32)
- medi_l1
- MEDI L1 dipole inversion with full options (OPTIMIZED f32 VERSION)
- medi_
l1_ default - MEDI with default parameters (backward compatible)
- medi_
l1_ with_ progress - MEDI L1 with progress callback (OPTIMIZED f32 VERSION)