Tools for NIfTI and ANALYZE image in MATLAB

(Click LINK HERE for the latest update)

 



Description:

Frequently Asked Questions:  http://www.rotman-baycrest.on.ca/~jimmy/NIfTI/FAQ.htm

 

 

 

 

 

Basic Programs:

Example View_nii window
View fullsize image

 

  1. load_nii.m:  Load N-Dimensional NIfTI data (where N can be from 3 to 7) or ANALYZE data (where N can be from 3 to 4), and apply header info (e.g. affine geometric transform, voxel intensity scaling, etc.) to the data. If your data has more than 3-Dimension (e.g. time series etc.), you can also specify a range to extract only 1 or several volumes.  For usage, type:  help load_nii

 

  1. save_nii.m:  Save N-Dimensional NIfTI data (where N can be from 3 to 7) that is loaded by "load_nii.m" or made by "make_nii.m".  For usage, type:  help save_nii

 

  1. make_nii.m:  Make N-Dimensional NIfTI data (where N can be from 3 to 7) based on the N-Dimensional matrix and other optional parameters (e.g. voxel_size, origin, etc.). Using "save_nii" command, the NIfTI data that is made by "make_nii" can be saved into a NIfTI file.  For usage, type:  help make_nii

 

  1. make_ana.m:  Make 3D ANALYZE data based on the 3D matrix and other optional parameters (e.g. voxel_size, origin, etc.). Using "save_untouch_nii" command, the ANALYZE data that is made by "make_ana" can be saved into an ANALYZE file in order to be compatible with some ANALYZE only programs.  For usage, type:  help make_ana

 

  1. reslice_nii.m:  Reslice 3D (or 4D) NIfTI data or ANALYZE data with affine matrix M in .mat file. The program will base on the affine matrix, which is especially useful for oblique images with non-orthogonal rotation or shearing that cannot be loaded with "load_nii.m". You can also specify voxel_size, etc. It will not cause negative effect, as long as you remember not to do slice time correction after using "reslice_nii.m".  For usage, type:  help reslice_nii

 

  1. view_nii.m:  View 3D (or 4D) NIfTI data or ANALYZE data that is loaded by "load_nii.m" or made by "make_nii.m". Activation map, ROI, etc. can be overlaid on top of a background image (see above picture). Plotted view can be embedded into your existing figure window. See detail at http://www.rotman-baycrest.on.ca/~jimmy/NIfTI/examples.txt.  For usage, type:  help view_nii

 

  1. load_untouch_nii.m:  Load N-Dimensional NIfTI data (where N can be from 3 to 7) or ANALYZE data (where N can be from 3 to 4), but do not apply any changes indicated in the header. (Warning: Do not apply "view_nii.m" to the dataset loaded with "load_untouch_nii.m".  For usage, type:  help load_untouch_nii

 

  1. save_untouch_nii.m:  Save N-Dimensional NIfTI data (where N can be from 3 to 7) or ANALYZE data (where N can be from 3 to 4) that is loaded by "load_untouch_nii.m" or made by "make_ana.m". If you do not modify the loaded dataset, the header and data in the new saved file should be the same as those in the original file.  For usage, type:  help save_untouch_nii

 

Other Programs:

 

  1. collapse_nii_scan.m:  Integrate multiple single-scan NIfTI or ANALYZE files into a multiple-scan NIfTI file.  For usage, type:  help collapse_nii_scan

 

  1. expand_nii_scan.m:  Break a multiple-scan NIfTI file into multiple single-scan NIfTI files.  For usage, type:  help expand_nii_scan

 

  1. flip_lr.m:  Convert ANALYZE or NIfTI file to an L-R flipped NIfTI file. (Warning: please use this program with caution!).  For usage, type:  help flip_lr

 

  1. get_nii_frame.m:  Return number of time frames of a NIfTI dataset.  For usage, type:  help get_nii_frame

 

  1. load_nii_ext.m:  Load NIfTI header extension.  For usage, type:  help load_nii_ext

 

  1. mat_into_hdr.m:  Integrate the affine matrix in old SPM MATLAB file into its .hdr header file to become NIfTI format file.  For usage, type:  help mat_into_hdr

 

For NIfTI image, "load_nii.m" will take the affine matrix in its header and make appropriate space transformation. So the loaded dataset will always be in RAS orientation, i.e. X axis from Left to Right, Y axis from Posterior to Anterior, and Z axis from Inferior to Superior.

 

For ANALYZE image, "load_nii.m" will load the image as is. Since an ANALYZE image could be in RAS or LAS depending on your assumption, many people are confused by its laterality, especially when an ANALYZE image is processed by different software. If you are still using ANALYZE image, I strongly suggest that you take a look at the table that I summarized:

 

http://www.rotman-baycrest.on.ca/~jimmy/UseANALYZE.htm

 

Because "load_nii.m" can only handle a subset of affine transform (flipping and orthogonal rotation with a total of 48 orientations), you should use "reslice_nii.m" to handle the rest of the space transformation (e.g. NIfTI files with non-orthogonal rotation, shearing etc.). It will not cause negative effect, as long as you remember not to do slice time correction after using "reslice_nii.m".

 

If you prefer the loaded dataset untouched, you have to use "load_untouch_nii.m" and " save_untouch_nii.m" program pair. In this case, the affine matrix in NIfTI header will not be applied to the loaded dataset, and the loaded dataset should not be used for other programs, like "view_nii.m" etc.

 

Two example datasets, "avg152T1_LR_nifti.nii" and "avg152T1_RL_nifti.nii", are provided under NIfTI web site http://nifti.nimh.nih.gov/nifti-1/data. As is indicated on NIfTI web site, "The first image (LR) is stored in radiological convention (LAS). The second image (RL) is stored in neurological convention (RAS). Any NIfTI compliant viewing software should display these images identically". When you load them with "load_nii.m", and display them with "view_nii.m", you can expect the same result.

 



Update History:

 

 

(Also available on MathWorks File Exchange)

 


Contact: Please send your feed back to me (jimmy@rotman-baycrest.on.ca)