Struct nifti::header::NiftiHeader

source ·
pub struct NiftiHeader {
Show 44 fields pub sizeof_hdr: i32, pub data_type: [u8; 10], pub db_name: [u8; 18], pub extents: i32, pub session_error: i16, pub regular: u8, pub dim_info: u8, pub dim: [u16; 8], pub intent_p1: f32, pub intent_p2: f32, pub intent_p3: f32, pub intent_code: i16, pub datatype: i16, pub bitpix: i16, pub slice_start: i16, pub pixdim: [f32; 8], pub vox_offset: f32, pub scl_slope: f32, pub scl_inter: f32, pub slice_end: i16, pub slice_code: u8, pub xyzt_units: u8, pub cal_max: f32, pub cal_min: f32, pub slice_duration: f32, pub toffset: f32, pub glmax: i32, pub glmin: i32, pub descrip: Vec<u8>, pub aux_file: [u8; 24], pub qform_code: i16, pub sform_code: i16, pub quatern_b: f32, pub quatern_c: f32, pub quatern_d: f32, pub quatern_x: f32, pub quatern_y: f32, pub quatern_z: f32, pub srow_x: [f32; 4], pub srow_y: [f32; 4], pub srow_z: [f32; 4], pub intent_name: [u8; 16], pub magic: [u8; 4], pub endianness: Endianness,
}
Expand description

The NIFTI-1 header data type. All fields are public and named after the specification’s header file. The type of each field was adjusted according to their use and array limitations.

Examples

use nifti::{NiftiHeader, Endianness};

let hdr1 = NiftiHeader::from_file("0000.hdr")?;
let hdr2 = NiftiHeader::from_file("0001.hdr.gz")?;
let hdr3 = NiftiHeader::from_file("4321.nii.gz")?;

Or to build one yourself:

let mut hdr = NiftiHeader::default();
hdr.cal_min = 0.;
hdr.cal_max = 128.;
hdr.datatype = 4;
assert_eq!(hdr.cal_min, 0.);
assert_eq!(hdr.cal_max, 128.);
assert_eq!(hdr.data_type().unwrap(), NiftiType::Int16);

Fields§

§sizeof_hdr: i32

Header size, must be 348

§data_type: [u8; 10]

Unused in NIFTI-1

§db_name: [u8; 18]

Unused in NIFTI-1

§extents: i32

Unused in NIFTI-1

§session_error: i16

Unused in NIFTI-1

§regular: u8

Unused in NIFTI-1

§dim_info: u8

MRI slice ordering

§dim: [u16; 8]

Data array dimensions

§intent_p1: f32

1st intent parameter

§intent_p2: f32

2nd intent parameter

§intent_p3: f32

3rd intent parameter

§intent_code: i16

NIFTI_INTENT_* code

§datatype: i16

Defines the data type!

§bitpix: i16

Number of bits per voxel

§slice_start: i16

First slice index

§pixdim: [f32; 8]

Grid spacings

§vox_offset: f32

Offset into .nii file to reach the volume.

Note: the highly unusual choice of f32 is intentional and due to trying to achieve header backwards compatibility to ANALYZE 7.5

§scl_slope: f32

Data scaling: slope

§scl_inter: f32

Data scaling: offset

§slice_end: i16

Last slice index

§slice_code: u8

Slice timing order

§xyzt_units: u8

Units of pixdim[1..4]

§cal_max: f32

Max display intensity

§cal_min: f32

Min display intensity

§slice_duration: f32

Time for 1 slice

§toffset: f32

Time axis shift

§glmax: i32

Unused in NIFTI-1

§glmin: i32

Unused in NIFTI-1

§descrip: Vec<u8>

Any text you like

§aux_file: [u8; 24]

Auxiliary filename

§qform_code: i16

NIFTI_XFORM_* code

§sform_code: i16

NIFTI_XFORM_* code

§quatern_b: f32

Quaternion b param

§quatern_c: f32

Quaternion c param

§quatern_d: f32

Quaternion d param

§quatern_x: f32

Quaternion x shift

§quatern_y: f32

Quaternion y shift

§quatern_z: f32

Quaternion z shift

§srow_x: [f32; 4]

1st row affine transform

§srow_y: [f32; 4]

2nd row affine transform

§srow_z: [f32; 4]

3rd row affine transform

§intent_name: [u8; 16]

‘name’ or meaning of data

§magic: [u8; 4]

Magic code. Must be b"ni1\0" or b"ni+\0"

§endianness: Endianness

Original data Endianness

Implementations§

source§

impl NiftiHeader

source

pub fn from_file<P: AsRef<Path>>(path: P) -> Result<NiftiHeader>

Retrieve a NIFTI header, along with its byte order, from a file in the file system. If the file’s name ends with “.gz”, the file is assumed to need GZip decoding.

source

pub fn from_reader<S>(input: S) -> Result<NiftiHeader>where S: Read,

Read a NIfTI-1 header, along with its byte order, from the given byte stream. It is assumed that the input is currently at the start of the NIFTI header.

source

pub fn fix(&mut self)

Fix some commonly invalid fields.

Currently, only the following problems are fixed:

  • If pixdim[0] isn’t equal to -1.0 or 1.0, it will be set to 1.0
source

pub fn dim(&self) -> Result<&[u16]>

Retrieve and validate the dimensions of the volume. Unlike how NIfTI-1 stores dimensions, the returned slice does not include dim[0] and is clipped to the effective number of dimensions.

Error

NiftiError::InconsistentDim if dim[0] does not represent a valid dimensionality, or any of the real dimensions are zero.

source

pub fn dimensionality(&self) -> Result<usize>

Retrieve and validate the number of dimensions of the volume. This is dim[0] after the necessary byte order conversions.

Error

NiftiError:: if dim[0] does not represent a valid dimensionality (it must be positive and not higher than 7).

source

pub fn data_type(&self) -> Result<NiftiType>

Get the data type as a validated enum.

source

pub fn xyzt_to_space(&self) -> Result<Unit>

Get the spatial units type as a validated unit enum.

source

pub fn xyzt_to_time(&self) -> Result<Unit>

Get the time units type as a validated unit enum.

source

pub fn xyzt_units(&self) -> Result<(Unit, Unit)>

Get the xyzt units type as a validated pair of space and time unit enum.

source

pub fn slice_order(&self) -> Result<SliceOrder>

Get the slice order as a validated enum.

source

pub fn intent(&self) -> Result<Intent>

Get the intent as a validated enum.

source

pub fn qform(&self) -> Result<XForm>

Get the qform coordinate mapping method as a validated enum.

source

pub fn sform(&self) -> Result<XForm>

Get the sform coordinate mapping method as a validated enum.

source

pub fn validate_description(&mut self) -> Result<()>

Ensure that the current descrip field is valid and is exactly equal to 80 bytes.

Descriptions shorter than 80 bytes will be extended with trailing zeros.

source

pub fn set_description<D>(&mut self, description: D) -> Result<()>where D: Into<Vec<u8>> + Deref<Target = [u8]>,

Safely set the descrip field using a buffer.

source

pub fn set_description_str<T>(&mut self, description: T) -> Result<()>where T: Into<String>,

Safely set the descrip field using a &str.

source§

impl NiftiHeader

source

pub fn affine<T>(&self) -> Matrix4<T>where T: RealField, f32: SubsetOf<T>,

Retrieve best of available transformations.

Return the ‘sform’ transformation if sform_code has a valid value, ‘qform’ transformation if qform_code has a valid value, otherwise return a “base” transformation, constructed from the declared shape and zooms.

If sform_code and qform_code both have valid values, the ‘sform’ affine transformation is prioritized.

source

pub fn sform_affine<T>(&self) -> Matrix4<T>where T: RealField, f32: SubsetOf<T>,

Retrieve affine transformation from ‘sform’ fields.

source

pub fn qform_affine<T>(&self) -> Matrix4<T>where T: RealField,

Retrieve affine transformation from qform-related fields.

source

pub fn set_affine<T>(&mut self, affine: &Matrix4<T>)where T: RealField + SubsetOf<f64> + ToPrimitive,

Set affine transformation.

Will set both affine transformations to avoid interoperability problems:

  • ‘sform’ from unmodified affine, with sform_code set to AlignedAnat.
  • ‘qform’ from a quaternion built from affine. However, the ‘qform’ won’t be used by most nifti readers because the qform_code will be set to Unknown.
source

pub fn set_sform<T>(&mut self, affine: &Matrix4<T>, code: XForm)where T: RealField + ToPrimitive,

Set affine transformation in ‘sform’ fields.

source

pub fn set_qform<T>(&mut self, affine4: &Matrix4<T>, code: XForm)where T: RealField + SubsetOf<f64> + ToPrimitive,

Set affine transformation in qform-related fields.

The qform transform only encodes translations, rotations and zooms. If there are shear components to the affine transform, the written qform gives the closest approximation where the rotation matrix is orthogonal. This is to allow quaternion representation. The orthogonal representation enforces orthogonal axes.

Trait Implementations§

source§

impl Clone for NiftiHeader

source§

fn clone(&self) -> NiftiHeader

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for NiftiHeader

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for NiftiHeader

source§

fn default() -> NiftiHeader

Returns the “default value” for a type. Read more
source§

impl PartialEq<NiftiHeader> for NiftiHeader

source§

fn eq(&self, other: &NiftiHeader) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for NiftiHeader

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Scalar for Twhere T: 'static + Clone + PartialEq<T> + Debug,