11

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?

0

2 Answers 2

24

From nipy

import numpy as np
import nibabel as nib

img = nib.load(example_filename)

a = np.array(img.dataobj)
Sign up to request clarification or add additional context in comments.

Comments

10

You can also do this:

import numpy as np
import nibabel as nib
    
img_nifti = nib.load(filepath)
img = img_nifti.get_fdata()

1 Comment

get_data() is now deprecated, now you can use get_fdata() instead

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.