Skip to main content

mppca_denoise

Function mppca_denoise 

Source
pub fn mppca_denoise(
    data: &[f64],
    dims: (usize, usize, usize),
    n_vols: usize,
    patch_radius: usize,
    mask: Option<&[u8]>,
) -> Vec<f64>
Expand description

Denoise multi-volume data with MP-PCA, as DIPY’s mppca (genpca with sigma=None, pca_method='eig').

For every voxel at least patch_radius from the volume border and inside the mask, the (2r+1)³ patch around it is centred on its per-volume mean, its covariance eigen-decomposed, the noise variance estimated from the Marchenko–Pastur bulk (DIPY’s _pca_classifier), and the components with eigenvalue below τ = (1 + √(n/m))² σ² dropped. Every voxel of the patch gets that patch’s estimate, weighted by 1 / (1 + n − ncomps) with ncomps the dropped count (Manjón et al. 2013, eq. 3), and the output is the weighted mean of the estimates of all patches covering a voxel.

§Arguments

  • data - Interleaved [voxel0_vol0, voxel0_vol1, ..., voxel1_vol0, ...] (row-major (n_voxels, n_vols)).
  • dims - Volume dimensions (nx, ny, nz).
  • n_vols - Number of volumes (e.g. echoes).
  • patch_radius - Half-width of the cubic patch (radius 2 → 5×5×5).
  • mask - Optional binary mask: patches are centred only on voxels inside it, and voxels outside it are 0 in the output, as in DIPY. None is the whole volume.

§Returns

Denoised data in the same layout, with negative values set to 0 as DIPY’s genpca does (clip(min=0)): the input is magnitude, where a negative value has no physical meaning. Voxels inside the mask that no patch covers (possible only at the volume border, next to the mask’s edge) keep their input values, where DIPY’s 0/0 leaves NaN.