Convert hdr/img to nii fromat


#1

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


#2

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

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


#4

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/)


#5

Thanks all for your replies .
cheers