|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# coding: utf-8 |
| 3 | +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- |
| 4 | +# vi: set ft=python sts=4 ts=4 sw=4 et: |
| 5 | + |
| 6 | +from ....pipeline import engine as pe |
| 7 | +from ....interfaces import utility as niu |
| 8 | +from ....interfaces import dtitk |
| 9 | + |
| 10 | + |
| 11 | +def affine_tensor_pipeline(name='AffTen'): |
| 12 | + |
| 13 | + """ |
| 14 | + Workflow that performs a linear registration |
| 15 | + (Rigid followed by Affine) |
| 16 | +
|
| 17 | + Example |
| 18 | + ------- |
| 19 | +
|
| 20 | + >>> from nipype.workflows.dmri.dtitk.tensor_registration import |
| 21 | + affine_tensor_pipeline |
| 22 | + >>> affine = affine_tensor_pipeline() |
| 23 | + >>> affine.inputs.inputnode.fixed_file = 'im1.nii' |
| 24 | + >>> affine.inputs.inputnode.moving_file = 'im2.nii' |
| 25 | + >>> affine.run() # doctest: +SKIP |
| 26 | +
|
| 27 | +
|
| 28 | + """ |
| 29 | + inputnode = pe.Node(niu.IdentityInterface( |
| 30 | + fields=['fixed_file', 'moving_file']), |
| 31 | + name='inputnode') |
| 32 | + outputnode = pe.Node(niu.IdentityInterface( |
| 33 | + fields=['out_file', 'out_file_xfm']), |
| 34 | + name='outputnode') |
| 35 | + |
| 36 | + rigid_node = pe.Node(dtitk.Rigid(), name='rigid_node') |
| 37 | + affine_node = pe.Node(dtitk.Affine(), name='affine_node') |
| 38 | + |
| 39 | + wf = pe.Workflow(name=name) |
| 40 | + |
| 41 | + wf.connect(inputnode, 'fixed_file', rigid_node, 'fixed_file') |
| 42 | + wf.connect(inputnode, 'moving_file', rigid_node, 'moving_file') |
| 43 | + wf.connect(rigid_node, 'out_file_xfm', affine_node, 'initialize_xfm') |
| 44 | + wf.connect(inputnode, 'fixed_file', affine_node, 'fixed_file') |
| 45 | + wf.connect(inputnode, 'moving_file', affine_node, 'moving_file') |
| 46 | + wf.connect(affine_node, 'out_file', outputnode, 'out_file') |
| 47 | + wf.connect(affine_node, 'out_file_xfm', outputnode, 'out_file_xfm') |
| 48 | + |
| 49 | + return wf |
| 50 | + |
| 51 | + |
| 52 | +def diffeomorphic_tensor_pipeline(name='DiffeoTen', |
| 53 | + params={'array_size': (128, 128, 64)}): |
| 54 | + """ |
| 55 | + Workflow that performs a diffeomorphic registration |
| 56 | + (Rigid and Affine follwed by Diffeomorphic) |
| 57 | + Note: the requirements for a diffeomorphic registration specify that |
| 58 | + the dimension 0 is a power of 2 so images are resliced prior to |
| 59 | + registration |
| 60 | +
|
| 61 | + Example |
| 62 | + ------- |
| 63 | +
|
| 64 | + >>> from nipype.workflows.dmri.dtitk.tensor_registration import |
| 65 | + diffeomorphic_tensor_pipeline |
| 66 | + >>> diffeo = diffeomorphic_tensor_pipeline() |
| 67 | + >>> diffeo.inputs.inputnode.fixed_file = 'im1.nii' |
| 68 | + >>> diffeo.inputs.inputnode.moving_file = 'im2.nii' |
| 69 | + >>> diffeo.run() # doctest: +SKIP |
| 70 | +
|
| 71 | +
|
| 72 | + """ |
| 73 | + inputnode = pe.Node(niu.IdentityInterface( |
| 74 | + fields=['fixed_file', 'moving_file']), |
| 75 | + name='inputnode') |
| 76 | + outputnode = pe.Node(niu.IdentityInterface( |
| 77 | + fields=['out_file', 'out_file_xfm']), |
| 78 | + name='outputnode') |
| 79 | + |
| 80 | + reslice_node_pow2 = pe.Node(dtitk.TVResample( |
| 81 | + origin=(0, 0, 0), |
| 82 | + array_size=params['array_size']), |
| 83 | + name='reslice_node_pow2') |
| 84 | + reslice_node_moving = pe.Node(dtitk.TVResample(), |
| 85 | + name='reslice_node_moving') |
| 86 | + mask_node = pe.Node(dtitk.BinThresh(lower_bound=0.01, upper_bound=100, |
| 87 | + inside_value=1, outside_value=0), |
| 88 | + name='mask_node') |
| 89 | + rigid_node = pe.Node(dtitk.Rigid(), name='rigid_node') |
| 90 | + affine_node = pe.Node(dtitk.Affine(), name='affine_node') |
| 91 | + diffeo_node = pe.Node(dtitk.Diffeo(n_iters=6, ftol=0.002), |
| 92 | + name='diffeo_node') |
| 93 | + compose_xfm_node = pe.Node(dtitk.ComposeXfm(), name='compose_xfm_node') |
| 94 | + apply_xfm_node = pe.Node(dtitk.DiffeoSymTensor3DVol(), |
| 95 | + name='apply_xfm_node') |
| 96 | + |
| 97 | + wf = pe.Workflow(name=name) |
| 98 | + |
| 99 | + # Reslice input images |
| 100 | + wf.connect(inputnode, 'fixed_file', reslice_node_pow2, 'in_file') |
| 101 | + wf.connect(reslice_node_pow2, 'out_file', |
| 102 | + reslice_node_moving, 'target_file') |
| 103 | + wf.connect(inputnode, 'moving_file', reslice_node_moving, 'in_file') |
| 104 | + # Rigid registration |
| 105 | + wf.connect(reslice_node_pow2, 'out_file', rigid_node, 'fixed_file') |
| 106 | + wf.connect(reslice_node_moving, 'out_file', rigid_node, 'moving_file') |
| 107 | + # Affine registration |
| 108 | + wf.connect(rigid_node, 'out_file_xfm', affine_node, 'initialize_xfm') |
| 109 | + wf.connect(reslice_node_pow2, 'out_file', affine_node, 'fixed_file') |
| 110 | + wf.connect(reslice_node_moving, 'out_file', affine_node, 'moving_file') |
| 111 | + # Diffeo registration |
| 112 | + wf.connect(reslice_node_pow2, 'out_file', mask_node, 'in_file') |
| 113 | + wf.connect(reslice_node_pow2, 'out_file', diffeo_node, 'fixed_file') |
| 114 | + wf.connect(affine_node, 'out_file', diffeo_node, 'moving_file') |
| 115 | + wf.connect(mask_node, 'out_file', diffeo_node, 'mask_file') |
| 116 | + # Compose transform |
| 117 | + wf.connect(diffeo_node, 'out_file_xfm', compose_xfm_node, 'in_df') |
| 118 | + wf.connect(affine_node, 'out_file_xfm', compose_xfm_node, 'in_aff') |
| 119 | + # Apply transform |
| 120 | + wf.connect(reslice_node_moving, 'out_file', apply_xfm_node, 'in_file') |
| 121 | + wf.connect(compose_xfm_node, 'out_file', apply_xfm_node, 'transform') |
| 122 | + # Send to output |
| 123 | + wf.connect(apply_xfm_node, 'out_file', outputnode, 'out_file') |
| 124 | + wf.connect(compose_xfm_node, 'out_file', outputnode, 'out_file_xfm') |
| 125 | + |
| 126 | + return wf |
0 commit comments