Skip to content

Commit ee9bed5

Browse files
committed
rf(brain_extraction): Remove duplicated nodes, simplify branching
1 parent 6bec246 commit ee9bed5

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

niworkflows/anat/ants.py

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,8 @@ def init_brain_extraction_wf(
261261
)
262262
res_target = pe.Node(RegridToZooms(zooms=(4, 4, 4), smooth=True), name='res_target')
263263

264-
lap_tmpl = pe.Node(
265-
ImageMath(operation='Laplacian', op2='1.5 1', copy_header=True), name='lap_tmpl'
266-
)
267-
lap_tmpl.inputs.op1 = tpl_target_path
268-
lap_target = pe.Node(
269-
ImageMath(operation='Laplacian', op2='1.5 1', copy_header=True),
270-
name='lap_target',
271-
)
264+
# Template and target inputs contain anatomical images
265+
# If Laplacians are enabled, they will be concatenated
272266
mrg_tmpl = pe.Node(niu.Merge(2), name='mrg_tmpl')
273267
mrg_tmpl.inputs.in1 = tpl_target_path
274268
mrg_target = pe.Node(niu.Merge(2), name='mrg_target')
@@ -340,6 +334,9 @@ def init_brain_extraction_wf(
340334
(inputnode, norm, [('in_mask', fixed_mask_trait)]),
341335
(inputnode, map_brainmask, [(('in_files', _pop), 'reference_image')]),
342336
(trunc, inu_n4, [('output_image', 'input_image')]),
337+
(inu_n4, mrg_target, [('output_image', 'in1')]),
338+
(mrg_tmpl, norm, [('out', 'fixed_image')]),
339+
(mrg_target, norm, [('out', 'moving_image')]),
343340
(inu_n4, res_target, [(('output_image', _pop), 'in_file')]),
344341
(res_tmpl, init_aff, [('out_file', 'fixed_image')]),
345342
(res_target, init_aff, [('out_file', 'moving_image')]),
@@ -379,30 +376,18 @@ def init_brain_extraction_wf(
379376

380377
if use_laplacian:
381378
lap_tmpl = pe.Node(
382-
ImageMath(operation='Laplacian', op2='1.5 1', copy_header=True),
379+
ImageMath(operation='Laplacian', op1=tpl_target_path, op2='1.5 1', copy_header=True),
383380
name='lap_tmpl',
384381
)
385-
lap_tmpl.inputs.op1 = tpl_target_path
386382
lap_target = pe.Node(
387383
ImageMath(operation='Laplacian', op2='1.5 1', copy_header=True),
388384
name='lap_target',
389385
)
390-
mrg_tmpl = pe.Node(niu.Merge(2), name='mrg_tmpl')
391-
mrg_tmpl.inputs.in1 = tpl_target_path
392-
mrg_target = pe.Node(niu.Merge(2), name='mrg_target')
386+
393387
wf.connect([
394388
(inu_n4, lap_target, [(('output_image', _pop), 'op1')]),
395389
(lap_tmpl, mrg_tmpl, [('output_image', 'in2')]),
396-
(inu_n4, mrg_target, [('output_image', 'in1')]),
397390
(lap_target, mrg_target, [('output_image', 'in2')]),
398-
(mrg_tmpl, norm, [('out', 'fixed_image')]),
399-
(mrg_target, norm, [('out', 'moving_image')]),
400-
]) # fmt:skip
401-
402-
else:
403-
norm.inputs.fixed_image = tpl_target_path
404-
wf.connect([
405-
(inu_n4, norm, [(('output_image', _pop), 'moving_image')]),
406391
]) # fmt:skip
407392

408393
if atropos_refine:

0 commit comments

Comments
 (0)