def create_ants_nonlinear_xfm(name='ants_nonlinear_xfm'): import nipype.interfaces.ants as ants from nipype.interfaces.ants.legacy import GenWarpFields ants_nonlinear_xfm = pe.Workflow(name=name) inputspec = pe.Node( util.IdentityInterface(fields=['anatomical_brain', 'reference_brain']), name='inputspec') # use ANTS to warp the masked anatomical image to a template image warp_brain = pe.Node(GenWarpFields(), name='warp_brain') outputspec = pe.Node(util.IdentityInterface(fields=[ 'warp_field', 'affine_transformation', 'inverse_warp', 'output_brain' ]), name='outputspec') ants_nonlinear_xfm.connect(inputspec, 'anatomical_brain', warp_brain, 'input_image') ants_nonlinear_xfm.connect(inputspec, 'reference_brain', warp_brain, 'reference_image') ants_nonlinear_xfm.connect(warp_brain, 'warp_field', outputspec, 'warp_field') ants_nonlinear_xfm.connect(warp_brain, 'affine_transformation', outputspec, 'affine_transformation') ants_nonlinear_xfm.connect(warp_brain, 'inverse_warp_field', outputspec, 'inverse_warp') ants_nonlinear_xfm.connect(warp_brain, 'output_file', outputspec, 'output_brain') return ants_nonlinear_xfm
def create_ants_nonlinear_xfm(name='ants_nonlinear_xfm'): """ Calculates the nonlinear ANTS registration transform. Parameters ---------- name : string, optional Name of the workflow. Returns ------- ants_nonlinear_xfm : nipype.pipeline.engine.Workflow Notes ----- Workflow Inputs:: inputspec.anatomical_brain : string (nifti file) File of brain to be normalized (registered) inputspec.reference_brain : string (nifti file) Target brain file to normalize to Workflow Outputs:: outputspec.warp_field : string (nifti file) Output warp field of registration outputspec.affine_transformation : text file Affine matrix of nonlinear transformation of brain file outputspec.inverse_warp : string (nifti file) Inverse of the warp field of the registration outputspec.output_brain : string (nifti file) Template-registered version of input brain Registration Procedure: 1. Performs a nonlinear anatomical-to-template registration. Workflow Graph: .. image:: :width: 500 Detailed Workflow Graph: .. image:: :width: 500 """ from nipype.interfaces.ants.legacy import GenWarpFields ants_nonlinear_xfm = pe.Workflow(name=name) inputspec = pe.Node( util.IdentityInterface(fields=['anatomical_brain', 'reference_brain']), name='inputspec') # use ANTS to warp the masked anatomical image to a template image warp_brain = pe.Node(GenWarpFields(), name='warp_brain') outputspec = pe.Node(util.IdentityInterface(fields=[ 'warp_field', 'affine_transformation', 'inverse_warp', 'output_brain' ]), name='outputspec') ants_nonlinear_xfm.connect(inputspec, 'anatomical_brain', warp_brain, 'input_image') ants_nonlinear_xfm.connect(inputspec, 'reference_brain', warp_brain, 'reference_image') ants_nonlinear_xfm.connect(warp_brain, 'warp_field', outputspec, 'warp_field') ants_nonlinear_xfm.connect(warp_brain, 'affine_transformation', outputspec, 'affine_transformation') ants_nonlinear_xfm.connect(warp_brain, 'inverse_warp_field', outputspec, 'inverse_warp') ants_nonlinear_xfm.connect(warp_brain, 'output_file', outputspec, 'output_brain') return ants_nonlinear_xfm
def get_struct_norm_workflow(name='normalize_struct'): """ Base structural workflow for normalization Parameters ---------- name : name of workflow. Default = 'normalize_struct' Inputs ------ inputspec.template_file : inputspec.brain : inputspec.segmentation : Outputs ------- outputspec.warp_field : outputspec.affine_transformation : outputspec.inverse_warp : outputspec.unwarped_brain : outputspec.warped_brain : Returns ------- workflow : structural normalization workflow """ #inputs to workflow import nipype.interfaces.freesurfer as fs import nipype.interfaces.ants as ants from nipype.interfaces.ants.legacy import GenWarpFields import nipype.pipeline.engine as pe import nipype.interfaces.utility as util inputspec = pe.Node(util.IdentityInterface( fields=['template_file', 'brain', 'segmentation']), name='inputspec') #converts brain from freesurfer mgz into nii brain_2nii = pe.Node(fs.preprocess.MRIConvert(), name='brain_2nii') brain_2nii.inputs.out_type = 'nii' #converts freesurfer segmentation into nii aparcaseg_2nii = pe.Node(fs.preprocess.MRIConvert(), name='aparcaseg_2nii') aparcaseg_2nii.inputs.out_type = 'nii' #create mask excluding everything outside of cortical surface (from #freesurfer segmentation file) create_mask = pe.Node(fs.model.Binarize(), name='create_mask') create_mask.inputs.min = 1 create_mask.inputs.dilate = 1 create_mask.inputs.out_type = 'nii' #apply mask to anatomical apply_mask = pe.Node(fs.utils.ApplyMask(), name='apply_mask') #use ANTS to warp the masked anatomical image to a template image warp_brain = pe.Node(GenWarpFields(), name='warp_brain') #collects workflow outputs outputspec = pe.Node(util.IdentityInterface(fields=[ 'warp_field', 'affine_transformation', 'inverse_warp', 'unwarped_brain', 'warped_brain' ]), name='outputspec') normalize_struct = pe.Workflow(name=name) normalize_struct.connect([ (inputspec, warp_brain, [('template_file', 'reference_image')]), (inputspec, brain_2nii, [('brain', 'in_file')]), (inputspec, aparcaseg_2nii, [('segmentation', 'in_file')]), (aparcaseg_2nii, create_mask, [('out_file', 'in_file')]), (create_mask, apply_mask, [('binary_file', 'mask_file')]), (brain_2nii, apply_mask, [('out_file', 'in_file')]), (apply_mask, warp_brain, [('out_file', 'input_image')]), (apply_mask, outputspec, [('out_file', 'unwarped_brain')]), (warp_brain, outputspec, [('affine_transformation', 'affine_transformation'), ('warp_field', 'warp_field'), ('inverse_warp_field', 'inverse_warp'), ('output_file', 'warped_brain')]) ]) return normalize_struct