Skip to content

Instantly share code, notes, and snippets.

@xgrg
Created March 21, 2018 13:06
Show Gist options
  • Save xgrg/e0caa4f1ce3282079ca92db4c1d76ff9 to your computer and use it in GitHub Desktop.
Save xgrg/e0caa4f1ce3282079ca92db4c1d76ff9 to your computer and use it in GitHub Desktop.
def rescale(source, target):
import nibabel as nib
import numpy as np
from nilearn import image
n = nib.load(source)
d = np.array(n.dataobj)
s = n.dataobj.slope
i = image.new_img_like(n, d/s)
i.to_filename(target)
log.info('Rescaling done: %s rescaled to %s'%(source, target))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment