如何将Nifti文件转换为Numpy数组?

时间:2017-06-07 20:32:56

标签: numpy nifti

我在Nifti文件(.ii.gz)中有3D数组,我想将其保存为3D numpy数组。我使用Nibabel将Numpy转换为Nifti1。我可以反其道而行吗?

2 个答案:

答案 0 :(得分:5)

来自nipy

import numpy as np
import nibabel as nib

img = nib.load(example_filename)

a = np.array(img.dataobj)

答案 1 :(得分:0)

您也可以这样做:

import numpy as np
import nibabel as nib

img_nifti = nib.load(filepath)
img = img_nifti.get_data()