user844597
user844597

Reputation: 35

Medical Imaging Data - how to convert .raw/mhd to Nifti/nii

Is there a way in Python or any other language to convert .raw/mhd image data to Nifti/nii?

I can load the .raw/mhd file in python via SimpleITK as in this post: Reading *.mhd/*.raw format in python

import skimage.io as io
img = io.imread('file.mhd', plugin='simpleitk')

I am having a hard time exporting as nii with proper dimensions... would ideally use the header information in the original mhd file...

Thanks

Upvotes: 0

Views: 4247

Answers (1)

Dave Chen
Dave Chen

Reputation: 2085

You should be able to just do in with SimpleITK. You would do something like this:

import SimpleITK as sitk

img = sitk.ReadImage("input.mhd")
sitk.WriteImage(img, "output.nii")

If you don't have SimpleITK in python, installing it as follows:

pip install SimpleITK

SimpleITK does its best effort of preserving all header information, although it's not perfect. Hopefully the voxel dimensions will be preserved.

Upvotes: 3

Related Questions