Last active
May 31, 2017 11:04
-
-
Save xgrg/d74133ae693fe98cd1a0dae58aace346 to your computer and use it in GitHub Desktop.
Arithmetics on images with nibabel/numpy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import nibabel as nib | |
im1 = nib.load('/tmp/path_to_image.nii.gz') | |
a = np.array(im1.dataobj) | |
im2 = nib.Nifti1Image(a/2.0, header=im1.header, affine=im1.affine) | |
im2.to_filename('/tmp/path_to_new_image.nii.gz') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment