Skip to content

Instantly share code, notes, and snippets.

@ilkayisik
Created April 16, 2019 15:48
Show Gist options
  • Save ilkayisik/4a379622482b8cbfa7c31cb974f80649 to your computer and use it in GitHub Desktop.
Save ilkayisik/4a379622482b8cbfa7c31cb974f80649 to your computer and use it in GitHub Desktop.
T1w to MNI transformation with ANTS apply transforms
from nipype.interfaces.ants import ApplyTransforms
# necessary files
norm_template = root + '/derivatives/mni152_bet.nii'
ants_transforms = sorted(glob(root + 'derivatives/fmriprep/sub-*/anat/sub-*_T1w_target-MNI152NLin2009cAsym_warp.h5'))
# files to transform from T1w to MNI
copes = sorted(glob(root + 'derivatives/analysis/sub-*/video/betaseries/level_2.gfeat/cope1.feat/stats/cope1.nii.gz'))
# loop and transform files for all participants
for s in range(nr_sub):
fname = copes[s]
con_norm = fname.replace('.nii.gz', '_inMNI.nii.gz')
ApplyTransforms(
reference_image=norm_template,
input_image_type=3,
float=True,
interpolation='NearestNeighbor',
invert_transform_flags=[False],
output_image=con_norm,
input_image=fname,
transforms=[ants_transforms[s]]).run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment