How to convert Nifti file to Numpy array?

2020-07-11 08:33发布

I have 3D array in Nifti file (.ii.gz) and I want to save it as a 3D numpy array. I used Nibabel to convert Numpy to Nifti1. Can I do the opposite?

标签: numpy nifti
2条回答
Rolldiameter
2楼-- · 2020-07-11 09:04

From nipy

import numpy as np
import nibabel as nib

img = nib.load(example_filename)

a = np.array(img.dataobj)
查看更多
倾城 Initia
3楼-- · 2020-07-11 09:08

You can also do this:

import numpy as np
import nibabel as nib

img_nifti = nib.load(filepath)
img = img_nifti.get_data()
查看更多
登录 后发表回答