Crate nifti

source ·
Expand description

Rust implementation of the NIfTI-1 file format.

Example

use nifti::{NiftiObject, ReaderOptions, NiftiVolume};

let obj = ReaderOptions::new().read_file("myvolume.nii.gz")?;
// use obj
let header = obj.header();
let volume = obj.volume();
let dims = volume.dim();

The library will automatically look for the respective volume when specifying just the header file:

use nifti::{NiftiObject, ReaderOptions};
let obj = ReaderOptions::new().read_file("myvolume.hdr.gz")?;

With the ndarray_volumes Cargo feature enabled, you can also convert a volume to an ndarray::Array and work from there:

use nifti::IntoNdArray;
let volume = obj.into_volume().into_ndarray::<f32>()?;

An additional volume API is also available for reading large volumes slice by slice.

let obj = ReaderStreamedOptions::new().read_file("minimal.nii.gz")?;

let volume = obj.into_volume();
for slice in volume {
    let slice = slice?;
    // manipulate slice here
}

Re-exports

Modules

  • This module defines some affine-related utilities.
  • Types for error handling go here.
  • This module contains definitions for the extension and related types. Extensions are optional data frames sitting before the voxel data. When present, an extender frame of 4 bytes is also present at the end of the NIFTI-1 header, with the first byte set to something other than 0.
  • This module defines the NiftiHeader struct, which is used to provide important information about NIFTI-1 volumes.
  • Module for handling and retrieving complete NIFTI-1 objects.
  • This module contains multiple types defined by the standard. At the moment, not all of them are used internally (NiftiType makes the exception, which also provides a safe means of reading voxel values). However, primitive integer values can be converted to these types and vice-versa.
  • This module defines the voxel volume API, as well as data types for reading volumes from files. An integration with ndarray allows for more elegant and efficient approaches, and should be preferred when possible. In order to do so, you must add the ndarray_volumes feature to this crate.
  • Utility functions to write nifti images.

Enums

  • Enumerate for materializing the two kinds of machine byte order supported by Rust in a dynamic fashion. That is, the information of whether to read or write data in Little Endian or in Big Endian is resolved at run time by observing this value.