[][src]Crate nifti

Rust implementation of the NIfTI-1 file format.


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


pub use error::NiftiError;
pub use error::Result;
pub use extension::Extender;
pub use extension::Extension;
pub use extension::ExtensionSequence;
pub use header::NiftiHeader;
pub use object::InMemNiftiObject;
pub use object::NiftiObject;
pub use object::ReaderOptions;
pub use object::ReaderStreamedOptions;
pub use object::StreamedNiftiObject;
pub use typedef::Intent;
pub use typedef::NiftiType;
pub use typedef::SliceOrder;
pub use typedef::Unit;
pub use typedef::XForm;
pub use volume::element::DataElement;
pub use volume::ndarray::IntoNdArray;
pub use volume::InMemNiftiVolume;
pub use volume::NiftiVolume;
pub use volume::RandomAccessNiftiVolume;
pub use volume::Sliceable;
pub use volume::StreamedNiftiVolume;



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.



Enumerate for materializing the two kinds of machine byte order supported by Rust.