Convert hdr/img to nii fromat

I am using iSEG2017 data. but the data is in .hdr/.img format. where as the code I am trying to run on it is accepting .nii. how to get around this problem.

Thanks

1 Like

If you have FSL installed you can convert a .hdr/.img pair to a .nii image using
fslchfiletype NIFTI fmri.hdr
If your .hdr/.img pair is in NIfTI format you will be all set. However, be aware that the /hdr/.img pair was also used for the older Analyze format that did not include a spatial transform. If your data is Analyze format, the spatial alignment of the results images may be incorrect. You can check the input images with fslhd to look at this.

3 Likes

I also find C3D from ITK-SNAP to be helpful. Sometimes it works where fslchfiletype fails and vice versa.

http://www.itksnap.org/pmwiki/pmwiki.php?n=Downloads.C3D

1 Like

And just to add one more option, in Python:

import nibabel as nb
fname = '<file name>.img'  
img = nb.load(fname)
nb.save(img, fname.replace('.img', '.nii'))

Again, you’ll want to check orientation, but assuming it is a valid Analyze (or two-part NIfTI) file, it should just work. (If not, you can submit a bug report at https://github.com/nipy/nibabel/issues/)

3 Likes

Thanks all for your replies .
cheers

In this option, does the .nii file also include the info from the hdr file? Thanks in advance!

1 Like

Yes. The NIfTI format is just <hdr><offset bytes><img> where <offset bytes> is some number of zero-bytes needed to get the starting index of <img> to be a multiple of 16

2 Likes

I used this code to convert iSeg-2017 https://iseg2017.web.unc.edu/

The output images have problem

I want to convert .hdr/img to nii

1 Like