简体   繁体   中英

How to resize a nifti (nii.gz medical image) file

I have some medical images of nii.gz format which are of different shapes. I want to resize all to the same shape inorder to feed to a deep learnig model, I tried using resample_img() of nibabel, but it destroys my images. I want to do some other function just to resize it to a particular shape, say (512,512,129).

Someone please help me in this regard. I am stuck in this step for quite a good number of days.

Maybe you can use this:

https://scikit-image.org/docs/dev/api/skimage.transform.html

I saw it in one of the papers. Here is the example in function ScaleToFixed:

https://github.com/sacmehta/3D-ESPNet/blob/master/Transforms.py

Here is how I did it. I have the volume of shape 320x320x130 (black and white so no rgb dimension). I want to make it twice as small. This worked for me:

import skimage.transform as skTrans
im = nib.load(file_path).get_fdata()
result1 = skTrans.resize(im, (160,160,130), order=1, preserve_range=True)

You can use TorchIO :

import torchio as tio

image = tio.ScalarImage('path/to/image.nii.gz')
transform = tio.CropOrPad((512,512,129))
output = transform(image)

If you would like to keep the original field of view, you could use the Resample transform instead.

Disclaimer: I'm the main developer of TorchIO.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM