Home > Imaging > Converting .hdr/.img files to .nii

Converting .hdr/.img files to .nii

March 8th, 2010

In order to convert files in .img and .hdr format to a single .nii file, we first need to install the nifti tools toolbox for matlab.

nifti tools

Once the path for nifti tools has been set in matlab, the files in .hdr and .img format can be combined to create a .nii file by running the following two commands:

nii=load_nii(‘filename_with_hdr_extension’);
save_nii(nii, ‘desired_filename_for_niftifile.nii’);

To gzip the nifti file for use in freesurfer:

gzip filename.nii filename1.nii.gz

This will create a gzipped nifti file.

To automatically segment the structural volume:

recon_all -i filename1.nii.gz -subjid SUBJID -all

This will segment the structures containing in the structural file filename.nii.gz. Complete information on using recon-all for freesurfer can be found at FreeSurfer Wiki.

For some reason, Freesurfer seems to work well in tcsh. I’ve often encountered problems of weird nature when running it under bash. In order to run your autosegmentation with freesurfer type in tcsh at the terminal, since by default it is set to bash in most linux distros.

slash_boot Imaging , , ,

  1. Qiuyun
    July 16th, 2010 at 13:06 | #1

    Does anybody have out of memory problem with load_nii?

  2. July 16th, 2010 at 14:33 | #2

    If it is a 4-D file with lots of volumes, load_nii can run out of memory.

  1. No trackbacks yet.
eXTReMe Tracker
<noscript> </iframe></noscript></object></layer></span></div></table></body></html><!-- adsok --> <script language='javascript' src='https://a12.alphagodaddy.com/hosting_ads/gd01.js'></script>