Brain Image File Conversion/Import Tips for MATLAB

Moo K. Chung
Department of Biostatistics and Medical Informatics
Waisman Laboratory for Brain Imaging and Behavior
University of Wisconsin-Madison

Analyze file format

December 5, 2007

Please d/l and install
It is the simplest way to view medical images one slice at a time.
Get image dimension from MRICRO and run the following code
for i=1:711
    if i==427
It will load the 427th image slice into MATLAB.
Now compare the loaded image with MRIcro display.

AFNI file format

December 5, 2007

Converting MINC to BRIK

This is the part of AFNI package 

3. Converting BRIK to MINC

This is the part of AFNI package

4. Loading BRIK into MATLAB
This is based on the AFNI MATLAB package written by Ziad Saad of NIH.

Opt.Format = 'matrix';
[err, image, Info, ErrMessage] = BrikLoad (BrikName, Opt);

% image = 181 x 217 x 181

NIFTI file format

October 6, 2014

To read and write NIFTI file formats in MATLAB, you need to download the following package. To read a NIFTI file with file name sample.nii, run

nii = load_nii('sample.nii)
Image is stored in nii.img. Image dimension can be obtained by running


Saving volume image into NIFTI file is a bit complicated. Header information (image size, number formats etc) should be manually entered. Alteratively, you can copy and paste the header information from other NIFTI file formats. If you want to save image variable vol to NIFTI file name vol.nii, run

output.img = vol
save_nii(output, 'vol.nii')