Main Content

niftiinfo

R2026b

Read metadata from NIfTI file

Description

info = niftiinfo(filename) returns metadata, info, from the Neuroimaging Informatics Technology Initiative (NIfTI) file specified by filename. The niftiinfo function supports both the NIfTI1 and NIfTI2 file formats.

example

Examples

collapse all

Load metadata from the NIfTI file brain.nii.

info = niftiinfo('brain.nii');

Display the version of the file.

info.Version
ans = 
'NIfTI1'

Display the pixel dimensions of the file.

info.PixelDimensions
ans = 1×3

     1     1     1

Display the raw header content.

info.raw
ans = struct with fields:
        sizeof_hdr: 348
          dim_info: ' '
               dim: [3 256 256 21 1 1 1 1]
         intent_p1: 0
         intent_p2: 0
         intent_p3: 0
       intent_code: 0
          datatype: 2
            bitpix: 8
       slice_start: 0
            pixdim: [1 1 1 1 0 0 0 0]
        vox_offset: 352
         scl_slope: 0
         scl_inter: 0
         slice_end: 0
        slice_code: 0
        xyzt_units: 0
           cal_max: 0
           cal_min: 0
    slice_duration: 0
           toffset: 0
           descrip: ''
          aux_file: ''
        qform_code: 0
        sform_code: 0
         quatern_b: 0
         quatern_c: 0
         quatern_d: 0
         qoffset_x: 0
         qoffset_y: 0
         qoffset_z: 0
            srow_x: [0 0 0 0]
            srow_y: [0 0 0 0]
            srow_z: [0 0 0 0]
       intent_name: ''
             magic: 'n+1 '

Display the intent code from the raw structure.

info.raw.intent_code
ans = 
0

Input Arguments

collapse all

Name of NIfTI file, specified as a string scalar or a character vector.

  • If you do not specify a file extension, then niftiinfo looks for a file with the extension .nii (or .nii.gz if the file is compressed).

  • If niftiinfo cannot find a file with the .nii or .nii.gz extension, then it looks for a file with the file extension .hdr (or .hdr.gz if the file is compressed). In the dual-file NIfTI format, the .hdr file holds the metadata associated with the volume.

You can import valid data from URLs and remote locations, such as cloud services, for easier collaboration and data management. Depending on the location of your file, filename can take one of these forms.

Location

Form

Current folder or folder on the MATLAB® path

Specify the name of the file in filename.

Example: "medicalData.nii"

File in a folder

If the file is not in the current folder or in a folder on the MATLAB path, then specify the full or relative path name.

Example: "C:\myFolder\medicalData.nii"

Example: "\imgDir\medicalData.nii"

Uniform resource locator (URL)

If you specify the file as an internet URL, then filename must contain the protocol type, such as http://.

Example: "http://my_hostname/my_path/medicalData.nii"

Remote location

If the file is stored at a remote location, then filename must contain the full path of the file specified as a URL of the form:

scheme_name://path_to_file/my_file.ext

Based on the remote location, scheme_name can be one of the values in this table.

Remote Locationscheme_name
Amazon S3™s3
Windows Azure® Blob Storagewasb, wasbs
HDFS™hdfs

For more information, see Work with Remote Data.

Example: "s3://my_bucket/my_path/medicalData.nii"

The function downloads each new remote file only once per session to a temporary directory. If you access the same remote data again during the same MATLAB session, the function uses the downloaded file from the temporary directory.

Data Types: char | string

Output Arguments

collapse all

Metadata associated with a NIfTI volume, returned as a structure.

niftiinfo returns the metadata from the header in simplified form. The function renames, reorders, and packages fields into easier to read MATLAB structures. For example, niftiinfo creates the DisplayIntensityRange field from the cal_max and cal_min fields of the file metadata. To view the metadata as it appears in the file, see the raw field of the structure returned.

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.

Version History

Introduced in R2017b

expand all