Skip to main content

Module io

Module io 

Source
Expand description

NIfTI file I/O for WASM

Provides functions to load and save NIfTI files from/to byte arrays, suitable for use in WebAssembly where filesystem access is not available.

Structs§

NiftiData
NIfTI data loaded from bytes
QForm 🔒
NIfTI-1’s quaternion (“qform”) description of a voxel→world transform — method 2 in the spec.

Constants§

NIFTI_XYZT_UNITS
xyzt_units for every file this crate writes: NIFTI_UNITS_MM | NIFTI_UNITS_SEC.

Functions§

affine_from_quatern 🔒
Rebuild the voxel→world affine a reader derives from a qform — the spec’s nifti_quatern_to_mat44. pixdim is pixdim[1..=3] as it appears in the header.
encode_nifti 🔒
Encode volumes (each nx*ny*nz values, x fastest) as an uncompressed NIfTI-1 file, 3D (four_d = false, exactly one volume) or 4D (dim[4] = volumes.len()). Both writers share this, so they cannot disagree on the header: float32 data, unit scaling, sform plus a matching qform where one exists, and NIFTI_XYZT_UNITS.
get_affine 🔒
Get affine transformation matrix from header
get_header_info 🔒
Get header info for diagnostics
gzip 🔒
is_gzip 🔒
Check if bytes are gzip compressed
load_itk_geometry
The image geometry ITK (ITK 5.3, as in ANTs 2.4.3) reads from a NIfTI file’s header (ItkGeometry::from_nifti_header), for ports whose output depends on it (n4_bias_correction). Supports .nii and .nii.gz bytes.
load_nifti
Load a NIfTI file from bytes
load_nifti_4d
Load a 4D NIfTI file from bytes (for multi-echo data)
qform_for 🔒
The qform to write alongside an sform, or None when no quaternion reproduces the affine.
quatern_from_affine 🔒
Decompose a row-major voxel→world affine into its quaternion form, following the NIfTI-1 spec’s nifti_mat44_to_quatern.
read_itk_geometry_file
load_itk_geometry of a file.
read_nifti_dims
Read only the dimensions from a NIfTI file header without loading volume data.
read_nifti_file
Read a NIfTI file from a filesystem path
save_nifti
Save data as NIfTI bytes
save_nifti_4d
Save several 3D volumes on one grid as a single uncompressed 4D NIfTI file.
save_nifti_4d_gz
save_nifti_4d, gzipped (.nii.gz).
save_nifti_4d_to_file
Save several 3D volumes as one 4D NIfTI file (see save_nifti_4d).
save_nifti_gz
Save data as gzipped NIfTI bytes (.nii.gz)
save_nifti_to_file
Save NIfTI data to a file

Type Aliases§

Nifti4d
A loaded 4D volume: (data, (nx, ny, nz, nt), (vsx, vsy, vsz), affine).