How to read NIfTI file in Python

Nifti (NIfTI) is a file format that is used to store medical imaging data such as magnetic resonance imaging (MRI) and computed tomography (CT) scans. We can use the NiBabel library to read the Nifti file. If you want to learn about computer vision, I strongly advise you to read This book.

Step 1: Install the NiBabel library

pip install nibabel

Step 2: Read the Nifti File

# Import the Nibabel library
import nibabel as nib

# Load the Nifti File
image = nib.load('data.nii')

# Convert the image data as a NumPy array
array = image.get_fdata()

# Display the shape of NumPy array
print(array.shape)

Output:

(240, 240, 155)

Related Articles:

Leave a Comment

Your email address will not be published.