def skullstrip_ants(name='ANTsBrainExtraction', settings=None): from niworkflows.data import get_ants_oasis_template_ras if settings is None: settings = {'debug': False} workflow = pe.Workflow(name=name) inputnode = pe.Node(niu.IdentityInterface(fields=['in_file', 'source_file']), name='inputnode') outputnode = pe.Node(niu.IdentityInterface( fields=['out_file', 'out_mask', 'out_report']), name='outputnode') t1_skull_strip = pe.Node(BrainExtractionRPT( dimension=3, use_floatingpoint_precision=1, debug=settings['debug'], generate_report=True, num_threads=settings['ants_nthreads']), name='Ants_T1_Brain_Extraction') # should not be necesssary byt does not hurt - make sure the multiproc # scheduler knows the resource limits t1_skull_strip.interface.num_threads = settings['ants_nthreads'] t1_skull_strip.inputs.brain_template = op.join( get_ants_oasis_template_ras(), 'T_template0.nii.gz' ) t1_skull_strip.inputs.brain_probability_mask = op.join( get_ants_oasis_template_ras(), 'T_template0_BrainCerebellumProbabilityMask.nii.gz' ) t1_skull_strip.inputs.extraction_registration_mask = op.join( get_ants_oasis_template_ras(), 'T_template0_BrainCerebellumRegistrationMask.nii.gz' ) workflow.connect([ (inputnode, t1_skull_strip, [('in_file', 'anatomical_image')]), (t1_skull_strip, outputnode, [('BrainExtractionMask', 'out_mask'), ('BrainExtractionBrain', 'out_file'), ('out_report', 'out_report')]) ]) return workflow
def init_skullstrip_ants_wf(debug, omp_nthreads, name='skullstrip_ants_wf'): from niworkflows.data import get_ants_oasis_template_ras workflow = pe.Workflow(name=name) inputnode = pe.Node( niu.IdentityInterface(fields=['in_file', 'source_file']), name='inputnode') outputnode = pe.Node(niu.IdentityInterface( fields=['bias_corrected', 'out_file', 'out_mask', 'out_report']), name='outputnode') t1_skull_strip = pe.Node(BrainExtractionRPT(dimension=3, use_floatingpoint_precision=1, debug=debug, generate_report=True, num_threads=omp_nthreads, keep_temporary_files=1), name='t1_skull_strip') # should not be necesssary byt does not hurt - make sure the multiproc # scheduler knows the resource limits t1_skull_strip.interface.num_threads = omp_nthreads t1_skull_strip.inputs.brain_template = op.join( get_ants_oasis_template_ras(), 'T_template0.nii.gz') t1_skull_strip.inputs.brain_probability_mask = op.join( get_ants_oasis_template_ras(), 'T_template0_BrainCerebellumProbabilityMask.nii.gz') t1_skull_strip.inputs.extraction_registration_mask = op.join( get_ants_oasis_template_ras(), 'T_template0_BrainCerebellumRegistrationMask.nii.gz') workflow.connect([ (inputnode, t1_skull_strip, [('in_file', 'anatomical_image')]), (t1_skull_strip, outputnode, [('BrainExtractionMask', 'out_mask'), ('BrainExtractionBrain', 'out_file'), ('N4Corrected0', 'bias_corrected'), ('out_report', 'out_report')]) ]) return workflow
def init_skullstrip_ants_wf(debug, omp_nthreads, name='skullstrip_ants_wf'): r""" This workflow performs skull-stripping using ANTs' ``BrainExtraction.sh`` .. workflow:: :graph2use: orig :simple_form: yes from fmriprep.workflows.anatomical import init_skullstrip_ants_wf wf = init_skullstrip_ants_wf(debug=False, omp_nthreads=1) **Parameters** debug : bool Enable debugging outputs omp_nthreads : int Maximum number of threads an individual process may use **Inputs** in_file T1-weighted structural image to skull-strip **Outputs** bias_corrected Bias-corrected ``in_file``, before skull-stripping out_file Skull-stripped ``in_file`` out_mask Binary mask of the skull-stripped ``in_file`` out_report Reportlet visualizing quality of skull-stripping """ from niworkflows.data import get_ants_oasis_template_ras workflow = pe.Workflow(name=name) inputnode = pe.Node(niu.IdentityInterface(fields=['in_file']), name='inputnode') outputnode = pe.Node(niu.IdentityInterface( fields=['bias_corrected', 'out_file', 'out_mask', 'out_report']), name='outputnode') t1_skull_strip = pe.Node(BrainExtractionRPT(dimension=3, use_floatingpoint_precision=1, debug=debug, generate_report=True, num_threads=omp_nthreads, keep_temporary_files=1), name='t1_skull_strip', n_procs=omp_nthreads) t1_skull_strip.inputs.brain_template = op.join( get_ants_oasis_template_ras(), 'T_template0.nii.gz') t1_skull_strip.inputs.brain_probability_mask = op.join( get_ants_oasis_template_ras(), 'T_template0_BrainCerebellumProbabilityMask.nii.gz') t1_skull_strip.inputs.extraction_registration_mask = op.join( get_ants_oasis_template_ras(), 'T_template0_BrainCerebellumRegistrationMask.nii.gz') workflow.connect([ (inputnode, t1_skull_strip, [('in_file', 'anatomical_image')]), (t1_skull_strip, outputnode, [('BrainExtractionMask', 'out_mask'), ('BrainExtractionBrain', 'out_file'), ('N4Corrected0', 'bias_corrected'), ('out_report', 'out_report')]) ]) return workflow
def init_skullstrip_ants_wf(skull_strip_template, debug, omp_nthreads, name='skullstrip_ants_wf'): r""" This workflow performs skull-stripping using ANTs' ``BrainExtraction.sh`` .. workflow:: :graph2use: orig :simple_form: yes from fmriprep.workflows.anatomical import init_skullstrip_ants_wf wf = init_skullstrip_ants_wf(skull_strip_template='OASIS', debug=False, omp_nthreads=1) **Parameters** skull_strip_template : str Name of ANTs skull-stripping template ('OASIS' or 'NKI') debug : bool Enable debugging outputs omp_nthreads : int Maximum number of threads an individual process may use **Inputs** in_file T1-weighted structural image to skull-strip **Outputs** bias_corrected Bias-corrected ``in_file``, before skull-stripping out_file Skull-stripped ``in_file`` out_mask Binary mask of the skull-stripped ``in_file`` out_report Reportlet visualizing quality of skull-stripping """ if skull_strip_template == 'OASIS': from niworkflows.data import get_ants_oasis_template_ras template_dir = get_ants_oasis_template_ras() brain_template = op.join(template_dir, 'T_template0.nii.gz') brain_probability_mask = op.join( template_dir, 'T_template0_BrainCerebellumProbabilityMask.nii.gz') extraction_registration_mask = op.join( template_dir, 'T_template0_BrainCerebellumRegistrationMask.nii.gz') elif skull_strip_template == 'NKI': from niworkflows.data.getters import get_ants_nki_template_ras template_dir = get_ants_nki_template_ras() brain_template = op.join(template_dir, 'T_template.nii.gz') brain_probability_mask = op.join( template_dir, 'T_template_BrainCerebellumProbabilityMask.nii.gz') extraction_registration_mask = op.join( template_dir, 'T_template_BrainCerebellumExtractionMask.nii.gz') else: raise ValueError("Unknown skull-stripping template; select from {OASIS, NKI}") workflow = pe.Workflow(name=name) inputnode = pe.Node(niu.IdentityInterface(fields=['in_file']), name='inputnode') outputnode = pe.Node(niu.IdentityInterface( fields=['bias_corrected', 'out_file', 'out_mask', 'out_segs', 'out_report']), name='outputnode') t1_skull_strip = pe.Node( BrainExtraction(dimension=3, use_floatingpoint_precision=1, debug=debug, keep_temporary_files=1), name='t1_skull_strip', n_procs=omp_nthreads) t1_skull_strip.inputs.brain_template = brain_template t1_skull_strip.inputs.brain_probability_mask = brain_probability_mask t1_skull_strip.inputs.extraction_registration_mask = extraction_registration_mask workflow.connect([ (inputnode, t1_skull_strip, [('in_file', 'anatomical_image')]), (t1_skull_strip, outputnode, [('BrainExtractionMask', 'out_mask'), ('BrainExtractionBrain', 'out_file'), ('BrainExtractionSegmentation', 'out_segs'), ('N4Corrected0', 'bias_corrected')]) ]) return workflow