A simple convenience script to convert between image formats. Let's look at our image first.

With medpy_info.py we can look at it's details.


In [1]:
medpy_info.py resources/flair.nii.gz


Informations obtained from image header:
header type=<class 'nibabel.nifti1.Nifti1Image'>
voxel spacing=(1.0, 1.0)
offset=(-0.0, -0.0)

Informations obtained from image array:
datatype=float32,dimensions=2,shape=(181, 217)
first and last element: 0.0 / 0.0

No we convert it to another format.


In [2]:
medpy_convert.py resources/flair.nii.gz output/flair.hdr

Note: if you get an error that the file already exists, you can force an overwrite by appending -f to the command. This is true for most medpy scripts.

HDR is an Analyze 7.5 format which is composed by a header file (.hdr) and a data file (.img).


In [3]:
ls output/flair.*


output/flair.hdr  output/flair.img

Checking the newly created image (we just supply the header file), we see that nothing changes except the format.


In [4]:
medpy_info.py output/flair.hdr


Informations obtained from image header:
header type=<class 'nibabel.nifti1.Nifti1Pair'>
voxel spacing=(1.0, 1.0)
offset=(-0.0, -0.0)

Informations obtained from image array:
datatype=float32,dimensions=2,shape=(181, 217)
first and last element: 0.0 / 0.0

In [ ]: