niftiread

Read NIfTI image

Description

example

V = niftiread(filename) reads the NIfTI image file specified by filename in the current folder or on the path, and returns volumetric data in V. The niftiread function supports both the NIfTI1 and NIfTI2 file formats.

V = niftiread(headerfile,imgfile) reads a NIfTI header file (.hdr) and image file (.img) pair.

example

V = niftiread(info) reads a NIfTI file described by the metadata structure info. To create an info structure, use the niftiinfo function

Examples

collapse all

Load volumetric data from a NIfTI file. The file uses the NIfTI combined format--the image and metadata are in the same file. This type of NIfTI file has the .nii file extension.

V = niftiread('brain.nii');

View the variable in the workspace.

whos V
  Name        Size                  Bytes  Class    Attributes

  V         256x256x21            1376256  uint8              

Read the metadata from a NIfTI file.

info = niftiinfo('brain.nii');

Read the volumetric image using the metadata structure returned by niftiinfo.

V = niftiread(info);

View the variable in the workspace.

whos V
  Name        Size                  Bytes  Class    Attributes

  V         256x256x21            1376256  uint8              

Input Arguments

collapse all

Name of the NIfTI file, specified as a string scalar or character vector. The file can be in the NIfTI1 or NIfTI2 file format.

  • If you do not specify a file extension, then niftiread looks for a file with the .nii extension.

  • If niftiread cannot find a file with the .nii extension, then it looks for a gzipped version of the file, with extension .nii.gz.

  • If niftiread cannot find a file with the .nii.gz extension, then it looks for a file with the .hdr, .hdr.gz, .img, or .img.gz file extension.

  • If niftiread cannot find a file that matches any of these options, then it returns an error.

Data Types: char | string

Name of the file containing metadata, specified as a string scalar or a character vector. The NIfTI header file (.hdr) holds the metadata associated with a NIfTI volume. If you do not specify a corresponding imgfile, then niftiread looks in the same folder for a file with the same name and extension .img.

Data Types: char | string

Name of the file containing volume, specified as a string scalar or a character vector. The NIfTI image file (.img) holds the volume data. If you do not specify a corresponding header file, then niftiread looks in the same folder for a file with the same name and extension .hdr.

Data Types: char | string

NIfTI file metadata, specified as a structure returned by niftiinfo.

Data Types: struct

Output Arguments

collapse all

Volumetric data, returned as a numeric array.

More About

collapse all

NifTI File Format

NIfTI (Neuroimaging Informatics Technology Initiative) is an NIH-sponsored working group to promote the interoperability of functional neuroimaging software tools. NIfTI uses a single or dual file storage format.

  • The dual file format stores data in a pair of files: a header file (.hdr) containing the metadata and a data file (.img) containing image data.

  • The single file format stores the data in a single file (.nii), which contains header information followed by image data.

References

[1] Cox, R. W., J. Ashburner, H. Breman, K. Fissell, C. Haselgrove, C. J. Holmes, J. L. Lancaster, D. E. Rex, S. M. Smith, J. B. Woodward, and S. C. Strother. "A (sort of) new image data format standard: NiFTI-1." 10th Annual Meeting of Organisation of Human Brain Mapping, Budapest, Hungary, June 2004.

Introduced in R2017b