This script can be used to extract as sub-volume from one of your images. Let's assume we have this one.

with the dimensions 181x217


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

We can now cut out the middle part with


In [3]:
medpy_extract_sub_volume.py resources/flair.nii.gz output/subvolume.nii.gz 60:120,70:140

which results in

As usual for medpy, the script works for images of all dimensions.


In [ ]: