Skip to main content

Module gradient

Module gradient 

Source
Expand description

DWI gradient table parsing (.bval and .bvec files).

BIDS diffusion-weighted imaging stores gradient information in two companion files alongside the NIfTI image:

  • _dwi.bval — b-values, one per volume, whitespace-separated
  • _dwi.bvec — gradient directions, 3 rows × N columns

This module parses both files into typed structures.

§Example

use std::path::Path;
use bids_io::gradient::{read_bvals, read_bvecs, GradientTable};

let bvals = read_bvals(Path::new("sub-01_dwi.bval")).unwrap();
let bvecs = read_bvecs(Path::new("sub-01_dwi.bvec")).unwrap();
let table = GradientTable::new(bvals, bvecs).unwrap();

println!("{} volumes, {} non-zero", table.n_volumes(), table.n_diffusion_volumes());
for (i, (bval, dir)) in table.iter().enumerate() {
    println!("vol {i}: b={bval:.0}, dir=[{:.3}, {:.3}, {:.3}]", dir[0], dir[1], dir[2]);
}

Structs§

GradientTable
Combined b-value + b-vector gradient table for a DWI acquisition.

Functions§

read_bvals
Read a .bval file — whitespace-separated b-values on one or more lines.
read_bvecs
Read a .bvec file — 3 rows of whitespace-separated values (x, y, z directions).

Type Aliases§

Bvals
A parsed b-value file: one f64 per volume.
Bvecs
A parsed b-vector file: one [x, y, z] direction per volume.