Skip to main content

NiftiHeader

Struct NiftiHeader 

Source
pub struct NiftiHeader {
    pub ndim: usize,
    pub dim: [i64; 8],
    pub pixdim: [f64; 8],
    pub datatype: i16,
    pub bitpix: i16,
    pub version: u8,
    pub vox_offset: u64,
    pub scl_slope: f64,
    pub scl_inter: f64,
    pub affine: [[f64; 4]; 4],
    pub sform_code: i16,
    pub qform_code: i16,
}

Fields§

§ndim: usize

Number of dimensions (1-7).

§dim: [i64; 8]

Size of each dimension: dim[0]=ndim, dim[1..8].

§pixdim: [f64; 8]

Voxel sizes / TR: pixdim[1..3] = voxel mm, pixdim[4] = TR for 4D.

§datatype: i16

Data type code.

§bitpix: i16

Bits per voxel.

§version: u8

NIfTI version (1 or 2).

§vox_offset: u64

Byte offset to the start of voxel data.

§scl_slope: f64

Slope for intensity scaling: scaled = raw * scl_slope + scl_inter. If 0.0, no scaling is applied.

§scl_inter: f64

Intercept for intensity scaling.

§affine: [[f64; 4]; 4]

sform affine matrix (4×4, row-major). Maps voxel (i,j,k) → (x,y,z) in mm. Set from sform if sform_code > 0, else from qform.

§sform_code: i16

sform code (0=unknown, 1=scanner, 2=aligned, 3=Talairach, 4=MNI).

§qform_code: i16

qform code.

Implementations§

Source§

impl NiftiHeader

Source

pub fn from_file(path: &Path) -> Result<Self, NiftiError>

Read header from a NIfTI file (.nii, .nii.gz, .hdr).

Source

pub fn n_vols(&self) -> usize

Number of volumes (4th dimension). Returns 1 for 3D images.

Source

pub fn voxel_size(&self) -> (f64, f64, f64)

Voxel dimensions in mm: (x, y, z).

Source

pub fn matrix_size(&self) -> (usize, usize, usize)

Matrix size: (nx, ny, nz).

Source

pub fn tr(&self) -> Option<f64>

Repetition time in seconds (pixdim[4] for 4D time series).

Source

pub fn n_voxels(&self) -> usize

Total number of voxels across all dimensions.

Source

pub fn shape(&self) -> Vec<usize>

Shape as a Vec (dims 1..ndim).

Source

pub fn has_scaling(&self) -> bool

Whether slope/intercept scaling should be applied.

Source

pub fn data_type(&self) -> DataType

Parsed datatype enum.

Source

pub fn affine(&self) -> &[[f64; 4]; 4]

Get the 4×4 affine matrix mapping voxel indices to mm coordinates. Equivalent to nibabel’s img.affine.

Source

pub fn voxel_to_world(&self, ijk: [f64; 3]) -> [f64; 3]

Transform voxel indices [i, j, k] to world coordinates [x, y, z] in mm.

Trait Implementations§

Source§

impl Clone for NiftiHeader

Source§

fn clone(&self) -> NiftiHeader

Returns a duplicate 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

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.