NIfTI-1 / NIfTI-2 reader for BIDS datasets.
Reads headers to extract dimensions, voxel sizes, TR, and volume count.
Also loads voxel data as f64 arrays with automatic type conversion and
scl_slope/scl_inter scaling.
Handles .nii, .nii.gz, .dtseries.nii, and legacy .hdr/.img pairs.
Performance
- Bulk reads entire data region in one I/O call
- Type-specific decode paths (no branch in inner loop)
- Pre-computed scaling:
value = raw * slope + inter - For
.nii.gz: streams through gzip decompressor
Example
use bids_nifti::{NiftiHeader, NiftiImage};
// Header only (fast)
let hdr = NiftiHeader::from_file("sub-01_bold.nii.gz".as_ref()).unwrap();
println!("{}D, {} vols, TR={:?}s", hdr.ndim, hdr.n_vols(), hdr.tr());
// Full image load
let img = NiftiImage::from_file("sub-01_bold.nii.gz".as_ref()).unwrap();
println!("shape: {:?}, {} voxels", img.shape(), img.data.len());
let val = img.get_voxel(&[32, 32, 16, 0]);