-
Notifications
You must be signed in to change notification settings - Fork 15
/
util.py
623 lines (537 loc) · 22.6 KB
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""Utility workflows."""
from nipype.pipeline import engine as pe
from nipype.interfaces import utility as niu, fsl, afni
from ..engine.workflows import LiterateWorkflow as Workflow
from ..interfaces.fixes import (
FixN4BiasFieldCorrection as N4BiasFieldCorrection,
)
from ..interfaces.masks import SimpleShowMaskRPT
from ..interfaces.utils import CopyXForm
from packaging.version import parse as parseversion, Version
from pkg_resources import resource_filename as pkgr_fn
from templateflow.api import get as get_template
from ..interfaces.fixes import (
FixHeaderRegistration as Registration,
FixHeaderApplyTransforms as ApplyTransforms,
)
from ..interfaces.images import MatchHeader
DEFAULT_MEMORY_MIN_GB = 0.01
def init_enhance_and_skullstrip_asl_wf(
brainmask_thresh=0.5,
name="enhance_and_skullstrip_asl_wf",
omp_nthreads=1,
pre_mask=False,
):
"""
Enhance and run brain extraction on a ASL image.
This workflow takes in a :abbr:`ASL (Aretrrail Spin Labeling)`
average/summary (e.g., a reference image
averaging non-steady-state timepoints), and sharpens the histogram
with the application of the N4 algorithm for removing the
:abbr:`INU (intensity non-uniformity)` bias field and calculates a signal
mask.
Steps of this workflow are:
1. Calculate a tentative mask by registering (9-parameters) to *fMRIPrep*'s
:abbr:`EPI (echo-planar imaging)` -*aslref* template, which
is in MNI space.
The tentative mask is obtained by resampling the MNI template's
brainmask into *aslref*-space.
2. Binary dilation of the tentative mask with a sphere of 3mm diameter.
3. Run ANTs' ``N4BiasFieldCorrection`` on the input
:abbr:`ASL (arterial spin labeling)` average, using the
mask generated in 1) instead of the internal Otsu thresholding.
4. Calculate a loose mask using FSL's ``bet``, with one mathematical morphology
dilation of one iteration and a sphere of 6mm as structuring element.
5. Mask the :abbr:`INU (intensity non-uniformity)`-corrected image
with the latest mask calculated in 3), then use AFNI's ``3dUnifize``
to *standardize* the T2* contrast distribution.
6. Calculate a mask using AFNI's ``3dAutomask`` after the contrast
enhancement of 4).
7. Calculate a final mask as the intersection of 4) and 6).
8. Apply final mask on the enhanced reference.
Step 1 can be skipped if the ``pre_mask`` argument is set to ``True`` and
a tentative mask is passed in to the workflow throught the ``pre_mask``
Nipype input.
Workflow graph
.. workflow ::
:graph2use: orig
:simple_form: yes
from aslprep.niworkflows.func.util import init_enhance_and_skullstrip_asl_wf
wf = init_enhance_and_skullstrip_asl_wf(omp_nthreads=1)
.. _N4BiasFieldCorrection: https://hdl.handle.net/10380/3053
Parameters
----------
brainmask_thresh: :obj:`float`
Lower threshold for the probabilistic brainmask to obtain
the final binary mask (default: 0.5).
name : str
Name of workflow (default: ``enhance_and_skullstrip_asl_wf``)
omp_nthreads : int
number of threads available to parallel nodes
pre_mask : bool
Indicates whether the ``pre_mask`` input will be set (and thus, step 1
should be skipped).
Inputs
------
in_file : str
ASL image (single volume)
pre_mask : bool
A tentative brain mask to initialize the workflow (requires ``pre_mask``
parameter set ``True``).
Outputs
-------
bias_corrected_file : str
the ``in_file`` after `N4BiasFieldCorrection`_
skull_stripped_file : str
the ``bias_corrected_file`` after skull-stripping
mask_file : str
mask of the skull-stripped input file
out_report : str
reportlet for the skull-stripping
"""
workflow = Workflow(name=name)
inputnode = pe.Node(
niu.IdentityInterface(fields=["in_file", "pre_mask"]), name="inputnode"
)
outputnode = pe.Node(
niu.IdentityInterface(
fields=["mask_file", "skull_stripped_file", "bias_corrected_file"]
),
name="outputnode",
)
pre_mask=pre_mask
# Ensure mask's header matches reference's
#check_hdr = pe.Node(MatchHeader(), name="check_hdr", run_without_submitting=True)
# Run N4 normally, force num_threads=1 for stability (images are small, no need for >1)
n4_correct = pe.Node(
N4BiasFieldCorrection(
dimension=3, copy_header=True, bspline_fitting_distance=200
),
shrink_factor=2,
name="n4_correct",
n_procs=1,
)
n4_correct.inputs.rescale_intensities = True
# Create a generous BET mask out of the bias-corrected EPI
skullstrip_first_pass = pe.Node(
fsl.BET(frac=0.2, mask=True), name="skullstrip_first_pass"
)
bet_dilate = pe.Node(
fsl.DilateImage(
operation="max",
kernel_shape="sphere",
kernel_size=6.0,
internal_datatype="char",
),
name="skullstrip_first_dilate",
)
bet_mask = pe.Node(fsl.ApplyMask(), name="skullstrip_first_mask")
# Use AFNI's unifize for T2 constrast & fix header
unifize = pe.Node(
afni.Unifize(
t2=True,
outputtype="NIFTI_GZ",
# Default -clfrac is 0.1, 0.4 was too conservative
# -rbt because I'm a Jedi AFNI Master (see 3dUnifize's documentation)
args="-clfrac 0.2 -rbt 18.3 65.0 90.0",
out_file="uni.nii.gz",
),
name="unifize",
)
fixhdr_unifize = pe.Node(CopyXForm(), name="fixhdr_unifize", mem_gb=0.1)
# Run ANFI's 3dAutomask to extract a refined brain mask
skullstrip_second_pass = pe.Node(
afni.Automask(dilate=1, outputtype="NIFTI_GZ"), name="skullstrip_second_pass"
)
fixhdr_skullstrip2 = pe.Node(CopyXForm(), name="fixhdr_skullstrip2", mem_gb=0.1)
# Take intersection of both masks
combine_masks = pe.Node(fsl.BinaryMaths(operation="mul"), name="combine_masks")
# Compute masked brain
apply_mask = pe.Node(fsl.ApplyMask(), name="apply_mask")
#binarize_mask = pe.Node(Binarize(thresh_low=brainmask_thresh), name="binarize_mask")
# fmt: off
workflow.connect([
(inputnode, n4_correct, [("in_file", "mask_image")]),
(inputnode, n4_correct, [("in_file", "input_image")]),
(inputnode, fixhdr_unifize, [("in_file", "hdr_file")]),
(inputnode, fixhdr_skullstrip2, [("in_file", "hdr_file")]),
(n4_correct, skullstrip_first_pass, [("output_image", "in_file")]),
(skullstrip_first_pass, bet_dilate, [("mask_file", "in_file")]),
(bet_dilate, bet_mask, [("out_file", "mask_file")]),
(skullstrip_first_pass, bet_mask, [("out_file", "in_file")]),
(bet_mask, unifize, [("out_file", "in_file")]),
(unifize, fixhdr_unifize, [("out_file", "in_file")]),
(fixhdr_unifize, skullstrip_second_pass, [("out_file", "in_file")]),
(skullstrip_first_pass, combine_masks, [("mask_file", "in_file")]),
(skullstrip_second_pass, fixhdr_skullstrip2, [("out_file", "in_file")]),
(fixhdr_skullstrip2, combine_masks, [("out_file", "operand_file")]),
(fixhdr_unifize, apply_mask, [("out_file", "in_file")]),
(combine_masks, apply_mask, [("out_file", "mask_file")]),
(combine_masks, outputnode, [("out_file", "mask_file")]),
(apply_mask, outputnode, [("out_file", "skull_stripped_file")]),
(n4_correct, outputnode, [("output_image", "bias_corrected_file")]),
])
# fmt: on
return workflow
def init_skullstrip_asl_wf(name="skullstrip_asl_wf"):
"""
Apply skull-stripping to a ASL image.
It is intended to be used on an image that has previously been
bias-corrected with
:py:func:`~niworkflows.func.util.init_enhance_and_skullstrip_asl_wf`
Workflow Graph
.. workflow ::
:graph2use: orig
:simple_form: yes
from aslprep.niworkflows.func.util import init_skullstrip_asl_wf
wf = init_skullstrip_asl_wf()
Inputs
------
in_file : str
ASL image (single volume)
Outputs
-------
skull_stripped_file : str
the ``in_file`` after skull-stripping
mask_file : str
mask of the skull-stripped input file
out_report : str
reportlet for the skull-stripping
"""
workflow = Workflow(name=name)
inputnode = pe.Node(niu.IdentityInterface(fields=["in_file"]), name="inputnode")
outputnode = pe.Node(
niu.IdentityInterface(
fields=["mask_file", "skull_stripped_file", "out_report"]
),
name="outputnode",
)
skullstrip_first_pass = pe.Node(
fsl.BET(frac=0.2, mask=True), name="skullstrip_first_pass"
)
skullstrip_second_pass = pe.Node(
afni.Automask(dilate=1, outputtype="NIFTI_GZ"), name="skullstrip_second_pass"
)
combine_masks = pe.Node(fsl.BinaryMaths(operation="mul"), name="combine_masks")
apply_mask = pe.Node(fsl.ApplyMask(), name="apply_mask")
mask_reportlet = pe.Node(SimpleShowMaskRPT(), name="mask_reportlet")
# fmt: off
workflow.connect([
(inputnode, skullstrip_first_pass, [("in_file", "in_file")]),
(skullstrip_first_pass, skullstrip_second_pass, [("out_file", "in_file")]),
(skullstrip_first_pass, combine_masks, [("mask_file", "in_file")]),
(skullstrip_second_pass, combine_masks, [("out_file", "operand_file")]),
(combine_masks, outputnode, [("out_file", "mask_file")]),
# Masked file
(inputnode, apply_mask, [("in_file", "in_file")]),
(combine_masks, apply_mask, [("out_file", "mask_file")]),
(apply_mask, outputnode, [("out_file", "skull_stripped_file")]),
# Reportlet
(inputnode, mask_reportlet, [("in_file", "background_file")]),
(combine_masks, mask_reportlet, [("out_file", "mask_file")]),
(mask_reportlet, outputnode, [("out_report", "out_report")]),
])
# fmt: on
return workflow
def init_enhance_and_skullstrip_bold_wf(
brainmask_thresh=0.5,
name="enhance_and_skullstrip_bold_wf",
omp_nthreads=1,
pre_mask=False,
):
"""
Enhance and run brain extraction on a BOLD EPI image.
This workflow takes in a :abbr:`BOLD (blood-oxygen level-dependant)`
:abbr:`fMRI (functional MRI)` average/summary (e.g., a reference image
averaging non-steady-state timepoints), and sharpens the histogram
with the application of the N4 algorithm for removing the
:abbr:`INU (intensity non-uniformity)` bias field and calculates a signal
mask.
Steps of this workflow are:
1. Calculate a tentative mask by registering (9-parameters) to *fMRIPrep*'s
:abbr:`EPI (echo-planar imaging)` -*boldref* template, which
is in MNI space.
The tentative mask is obtained by resampling the MNI template's
brainmask into *boldref*-space.
2. Binary dilation of the tentative mask with a sphere of 3mm diameter.
3. Run ANTs' ``N4BiasFieldCorrection`` on the input
:abbr:`BOLD (blood-oxygen level-dependant)` average, using the
mask generated in 1) instead of the internal Otsu thresholding.
4. Calculate a loose mask using FSL's ``bet``, with one mathematical morphology
dilation of one iteration and a sphere of 6mm as structuring element.
5. Mask the :abbr:`INU (intensity non-uniformity)`-corrected image
with the latest mask calculated in 3), then use AFNI's ``3dUnifize``
to *standardize* the T2* contrast distribution.
6. Calculate a mask using AFNI's ``3dAutomask`` after the contrast
enhancement of 4).
7. Calculate a final mask as the intersection of 4) and 6).
8. Apply final mask on the enhanced reference.
Step 1 can be skipped if the ``pre_mask`` argument is set to ``True`` and
a tentative mask is passed in to the workflow throught the ``pre_mask``
Nipype input.
Workflow graph
.. workflow ::
:graph2use: orig
:simple_form: yes
from aslprep.niworkflows.func.util import init_enhance_and_skullstrip_bold_wf
wf = init_enhance_and_skullstrip_bold_wf(omp_nthreads=1)
.. _N4BiasFieldCorrection: https://hdl.handle.net/10380/3053
Parameters
----------
brainmask_thresh: :obj:`float`
Lower threshold for the probabilistic brainmask to obtain
the final binary mask (default: 0.5).
name : str
Name of workflow (default: ``enhance_and_skullstrip_bold_wf``)
omp_nthreads : int
number of threads available to parallel nodes
pre_mask : bool
Indicates whether the ``pre_mask`` input will be set (and thus, step 1
should be skipped).
Inputs
------
in_file : str
BOLD image (single volume)
pre_mask : bool
A tentative brain mask to initialize the workflow (requires ``pre_mask``
parameter set ``True``).
Outputs
-------
bias_corrected_file : str
the ``in_file`` after `N4BiasFieldCorrection`_
skull_stripped_file : str
the ``bias_corrected_file`` after skull-stripping
mask_file : str
mask of the skull-stripped input file
out_report : str
reportlet for the skull-stripping
"""
workflow = Workflow(name=name)
inputnode = pe.Node(
niu.IdentityInterface(fields=["in_file", "pre_mask"]), name="inputnode"
)
outputnode = pe.Node(
niu.IdentityInterface(
fields=["mask_file", "skull_stripped_file", "bias_corrected_file"]
),
name="outputnode",
)
# Dilate pre_mask
pre_dilate = pe.Node(
fsl.DilateImage(
operation="max",
kernel_shape="sphere",
kernel_size=3.0,
internal_datatype="char",
),
name="pre_mask_dilate",
)
# Ensure mask's header matches reference's
check_hdr = pe.Node(MatchHeader(), name="check_hdr", run_without_submitting=True)
# Run N4 normally, force num_threads=1 for stability (images are small, no need for >1)
n4_correct = pe.Node(
N4BiasFieldCorrection(
dimension=3, copy_header=True, bspline_fitting_distance=200
),
shrink_factor=2,
name="n4_correct",
n_procs=1,
)
n4_correct.inputs.rescale_intensities = True
# Create a generous BET mask out of the bias-corrected EPI
skullstrip_first_pass = pe.Node(
fsl.BET(frac=0.2, mask=True), name="skullstrip_first_pass"
)
bet_dilate = pe.Node(
fsl.DilateImage(
operation="max",
kernel_shape="sphere",
kernel_size=6.0,
internal_datatype="char",
),
name="skullstrip_first_dilate",
)
bet_mask = pe.Node(fsl.ApplyMask(), name="skullstrip_first_mask")
# Use AFNI's unifize for T2 constrast & fix header
unifize = pe.Node(
afni.Unifize(
t2=True,
outputtype="NIFTI_GZ",
# Default -clfrac is 0.1, 0.4 was too conservative
# -rbt because I'm a Jedi AFNI Master (see 3dUnifize's documentation)
args="-clfrac 0.2 -rbt 18.3 65.0 90.0",
out_file="uni.nii.gz",
),
name="unifize",
)
fixhdr_unifize = pe.Node(CopyXForm(), name="fixhdr_unifize", mem_gb=0.1)
# Run ANFI's 3dAutomask to extract a refined brain mask
skullstrip_second_pass = pe.Node(
afni.Automask(dilate=1, outputtype="NIFTI_GZ"), name="skullstrip_second_pass"
)
fixhdr_skullstrip2 = pe.Node(CopyXForm(), name="fixhdr_skullstrip2", mem_gb=0.1)
# Take intersection of both masks
combine_masks = pe.Node(fsl.BinaryMaths(operation="mul"), name="combine_masks")
# Compute masked brain
apply_mask = pe.Node(fsl.ApplyMask(), name="apply_mask")
if not pre_mask:
from nipype.interfaces.ants.utils import AI
from ..interfaces.nibabel import Binarize
bold_template = get_template(
"MNI152NLin2009cAsym", resolution=2, desc="fMRIPrep", suffix="boldref"
)
brain_mask = get_template(
"MNI152NLin2009cAsym", resolution=2, desc="brain", suffix="mask"
)
# Initialize transforms with antsAI
init_aff = pe.Node(
AI(
fixed_image=str(bold_template),
fixed_image_mask=str(brain_mask),
metric=("Mattes", 32, "Regular", 0.2),
transform=("Affine", 0.1),
search_factor=(20, 0.12),
principal_axes=False,
convergence=(10, 1e-6, 10),
verbose=True,
),
name="init_aff",
n_procs=omp_nthreads,
)
# Registration().version may be None
if parseversion(Registration().version or "0.0.0") > Version("2.2.0"):
init_aff.inputs.search_grid = (40, (0, 40, 40))
# Set up spatial normalization
norm = pe.Node(
Registration(
from_file=pkgr_fn("niworkflows.data", "epi_atlasbased_brainmask.json")
),
name="norm",
n_procs=omp_nthreads,
)
norm.inputs.fixed_image = str(bold_template)
map_brainmask = pe.Node(
ApplyTransforms(
interpolation="BSpline",
float=True,
# Use the higher resolution and probseg for numerical stability in rounding
input_image=str(
get_template(
"MNI152NLin2009cAsym",
resolution=1,
label="brain",
suffix="probseg",
)
),
),
name="map_brainmask",
)
binarize_mask = pe.Node(Binarize(thresh_low=brainmask_thresh), name="binarize_mask")
# fmt: off
workflow.connect([
(inputnode, init_aff, [("in_file", "moving_image")]),
(inputnode, map_brainmask, [("in_file", "reference_image")]),
(inputnode, norm, [("in_file", "moving_image")]),
(init_aff, norm, [("output_transform", "initial_moving_transform")]),
(norm, map_brainmask, [
("reverse_invert_flags", "invert_transform_flags"),
("reverse_transforms", "transforms"),
]),
(map_brainmask, binarize_mask, [("output_image", "in_file")]),
(binarize_mask, pre_dilate, [("out_mask", "in_file")]),
])
# fmt: on
else:
# fmt: off
workflow.connect([
(inputnode, pre_dilate, [("pre_mask", "in_file")]),
])
# fmt: on
# fmt: off
workflow.connect([
(inputnode, check_hdr, [("in_file", "reference")]),
(pre_dilate, check_hdr, [("out_file", "in_file")]),
(check_hdr, n4_correct, [("out_file", "mask_image")]),
(inputnode, n4_correct, [("in_file", "input_image")]),
(inputnode, fixhdr_unifize, [("in_file", "hdr_file")]),
(inputnode, fixhdr_skullstrip2, [("in_file", "hdr_file")]),
(n4_correct, skullstrip_first_pass, [("output_image", "in_file")]),
(skullstrip_first_pass, bet_dilate, [("mask_file", "in_file")]),
(bet_dilate, bet_mask, [("out_file", "mask_file")]),
(skullstrip_first_pass, bet_mask, [("out_file", "in_file")]),
(bet_mask, unifize, [("out_file", "in_file")]),
(unifize, fixhdr_unifize, [("out_file", "in_file")]),
(fixhdr_unifize, skullstrip_second_pass, [("out_file", "in_file")]),
(skullstrip_first_pass, combine_masks, [("mask_file", "in_file")]),
(skullstrip_second_pass, fixhdr_skullstrip2, [("out_file", "in_file")]),
(fixhdr_skullstrip2, combine_masks, [("out_file", "operand_file")]),
(fixhdr_unifize, apply_mask, [("out_file", "in_file")]),
(combine_masks, apply_mask, [("out_file", "mask_file")]),
(combine_masks, outputnode, [("out_file", "mask_file")]),
(apply_mask, outputnode, [("out_file", "skull_stripped_file")]),
(n4_correct, outputnode, [("output_image", "bias_corrected_file")]),
])
# fmt: on
return workflow
def init_skullstrip_bold_wf(name="skullstrip_bold_wf"):
"""
Apply skull-stripping to a BOLD image.
It is intended to be used on an image that has previously been
bias-corrected with
:py:func:`~niworkflows.func.util.init_enhance_and_skullstrip_bold_wf`
Workflow Graph
.. workflow ::
:graph2use: orig
:simple_form: yes
from aslprep.niworkflows.func.util import init_skullstrip_bold_wf
wf = init_skullstrip_bold_wf()
Inputs
------
in_file : str
BOLD image (single volume)
Outputs
-------
skull_stripped_file : str
the ``in_file`` after skull-stripping
mask_file : str
mask of the skull-stripped input file
out_report : str
reportlet for the skull-stripping
"""
workflow = Workflow(name=name)
inputnode = pe.Node(niu.IdentityInterface(fields=["in_file"]), name="inputnode")
outputnode = pe.Node(
niu.IdentityInterface(
fields=["mask_file", "skull_stripped_file", "out_report"]
),
name="outputnode",
)
skullstrip_first_pass = pe.Node(
fsl.BET(frac=0.2, mask=True), name="skullstrip_first_pass"
)
skullstrip_second_pass = pe.Node(
afni.Automask(dilate=1, outputtype="NIFTI_GZ"), name="skullstrip_second_pass"
)
combine_masks = pe.Node(fsl.BinaryMaths(operation="mul"), name="combine_masks")
apply_mask = pe.Node(fsl.ApplyMask(), name="apply_mask")
mask_reportlet = pe.Node(SimpleShowMaskRPT(), name="mask_reportlet")
# fmt: off
workflow.connect([
(inputnode, skullstrip_first_pass, [("in_file", "in_file")]),
(skullstrip_first_pass, skullstrip_second_pass, [("out_file", "in_file")]),
(skullstrip_first_pass, combine_masks, [("mask_file", "in_file")]),
(skullstrip_second_pass, combine_masks, [("out_file", "operand_file")]),
(combine_masks, outputnode, [("out_file", "mask_file")]),
# Masked file
(inputnode, apply_mask, [("in_file", "in_file")]),
(combine_masks, apply_mask, [("out_file", "mask_file")]),
(apply_mask, outputnode, [("out_file", "skull_stripped_file")]),
# Reportlet
(inputnode, mask_reportlet, [("in_file", "background_file")]),
(combine_masks, mask_reportlet, [("out_file", "mask_file")]),
(mask_reportlet, outputnode, [("out_report", "out_report")]),
])
# fmt: on
return workflow