Skip to content

Instantly share code, notes, and snippets.

@mrajchl
Created June 8, 2018 15:01
Show Gist options
  • Save mrajchl/6244a35c51f22ba926998f4c59e324fc to your computer and use it in GitHub Desktop.
Save mrajchl/6244a35c51f22ba926998f4c59e324fc to your computer and use it in GitHub Desktop.
Reading a .nii image with SimpleITK
import SimpleITK as sitk
import numpy as np
# A path to a T1-weighted brain .nii image:
t1_fn = './brain_t1_0001.nii'
# Read the .nii image containing the volume with SimpleITK:
sitk_t1 = sitk.ReadImage(t1_fn)
# and access the numpy array:
t1 = sitk.GetArrayFromImage(sitk_t1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment