Skip to main content

Crate bids_nifti

Crate bids_nifti 

Source
Expand description

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]);

Re-exports§

pub use cifti::BrainModel;
pub use cifti::CiftiHeader;
pub use cifti::read_cifti_header;
pub use gifti::GiftiImage;
pub use gifti::read_gifti_header;
pub use qmri::QmriMetadata;

Modules§

cifti
CIFTI-2 header parsing (.dtseries.nii, .dscalar.nii, .dlabel.nii).
gifti
GIFTI surface file reading (.gii, .surf.gii, .func.gii).
mmap
Memory-mapped NIfTI reader for large files.
qmri
Quantitative MRI (qMRI) metadata for parametric maps and acquisition files.

Structs§

NiftiHeader
NiftiImage
A loaded NIfTI image with header and voxel data.

Enums§

DataType
NIfTI datatype codes (from nifti1.h).
NiftiError