简体   繁体   English

如何调整 nifti (nii.gz 医学图像) 文件的大小

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

I have some medical images of nii.gz format which are of different shapes.我有一些形状不同的 nii.gz 格式的医学图像。 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.我想将所有大小调整为相同的形状,以便提供给深度学习模型,我尝试使用 nibabel 的 resample_img(),但它破坏了我的图像。 I want to do some other function just to resize it to a particular shape, say (512,512,129).我想做一些其他功能只是将其调整为特定形状,例如 (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.htmlhttps://scikit-image.org/docs/dev/api/skimage.transform.html

I saw it in one of the papers.我在其中一篇论文中看到过。 Here is the example in function ScaleToFixed:这是函数 ScaleToFixed 中的示例:

https://github.com/sacmehta/3D-ESPNet/blob/master/Transforms.py 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).我有 320x320x130 形状的体积(黑色和白色,所以没有 rgb 尺寸)。 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 :您可以使用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.如果您想保留原始视野,则可以改用Resample变换。

Disclaimer: I'm the main developer of TorchIO.免责声明:我是 TorchIO 的主要开发者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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