|
1 | | -# -*- coding: utf-8 -*- |
2 | 1 | # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- |
3 | 2 | # vi: set ft=python sts=4 ts=4 sw=4 et: |
4 | | -from __future__ import absolute_import, division, print_function, unicode_literals |
5 | | -from nipype.interfaces import ants, afni, fsl, utility as niu |
| 3 | +"""Brain extraction workflows.""" |
| 4 | +from nipype.interfaces import afni, utility as niu |
6 | 5 | from nipype.pipeline import engine as pe |
| 6 | +from ..interfaces.nibabel import Binarize |
| 7 | +from ..interfaces.fixes import FixN4BiasFieldCorrection as N4BiasFieldCorrection |
7 | 8 |
|
8 | 9 |
|
9 | 10 | def afni_wf(name='AFNISkullStripWorkflow', unifize=False, n4_nthreads=1): |
10 | 11 | """ |
11 | | - Skull-stripping workflow |
| 12 | + Create a skull-stripping workflow based on AFNI's tools. |
12 | 13 |
|
13 | | - Originally derived from the `codebase of the |
14 | | - QAP <https://github.com/preprocessed-connectomes-project/\ |
15 | | -quality-assessment-protocol/blob/master/qap/anatomical_preproc.py#L105>`_. |
| 14 | + Originally derived from the `codebase of the QAP |
| 15 | + <https://github.com/preprocessed-connectomes-project/quality-assessment-protocol/blob/master/qap/anatomical_preproc.py#L105>`_. |
16 | 16 | Now, this workflow includes :abbr:`INU (intensity non-uniformity)` correction |
17 | 17 | using the N4 algorithm and (optionally) intensity harmonization using |
18 | 18 | ANFI's ``3dUnifize``. |
19 | 19 |
|
20 | | -
|
21 | 20 | """ |
22 | | - |
23 | 21 | workflow = pe.Workflow(name=name) |
24 | 22 | inputnode = pe.Node(niu.IdentityInterface(fields=['in_file']), |
25 | 23 | name='inputnode') |
26 | 24 | outputnode = pe.Node(niu.IdentityInterface( |
27 | 25 | fields=['bias_corrected', 'out_file', 'out_mask', 'bias_image']), name='outputnode') |
28 | 26 |
|
29 | 27 | inu_n4 = pe.Node( |
30 | | - ants.N4BiasFieldCorrection(dimension=3, save_bias=True, num_threads=n4_nthreads, |
31 | | - copy_header=True), |
| 28 | + N4BiasFieldCorrection(dimension=3, save_bias=True, num_threads=n4_nthreads, |
| 29 | + rescale_intensities=True, copy_header=True), |
32 | 30 | n_procs=n4_nthreads, |
33 | 31 | name='inu_n4') |
34 | 32 |
|
35 | 33 | sstrip = pe.Node(afni.SkullStrip(outputtype='NIFTI_GZ'), name='skullstrip') |
36 | 34 | sstrip_orig_vol = pe.Node(afni.Calc( |
37 | 35 | expr='a*step(b)', outputtype='NIFTI_GZ'), name='sstrip_orig_vol') |
38 | | - binarize = pe.Node(fsl.Threshold(args='-bin', thresh=1.e-3), name='binarize') |
| 36 | + binarize = pe.Node(Binarize(thresh_low=0.0), name='binarize') |
39 | 37 |
|
40 | 38 | if unifize: |
41 | 39 | # Add two unifize steps, pre- and post- skullstripping. |
@@ -64,7 +62,7 @@ def afni_wf(name='AFNISkullStripWorkflow', unifize=False, n4_nthreads=1): |
64 | 62 | (sstrip, sstrip_orig_vol, [('out_file', 'in_file_b')]), |
65 | 63 | (inputnode, inu_n4, [('in_file', 'input_image')]), |
66 | 64 | (sstrip_orig_vol, binarize, [('out_file', 'in_file')]), |
67 | | - (binarize, outputnode, [('out_file', 'out_mask')]), |
| 65 | + (binarize, outputnode, [('out_mask', 'out_mask')]), |
68 | 66 | (inu_n4, outputnode, [('bias_image', 'bias_image')]), |
69 | 67 | ]) |
70 | 68 | return workflow |
0 commit comments