Skip to main content

Module medi

Module medi 

Source
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§

MediOpBuffers 🔒
MEDI operator buffers - separate struct to allow split borrowing
MediParams
MEDI algorithm parameters
MediWorkspace
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)