@@ -104,8 +104,8 @@ def all_peb_pipeline(name='hmc_sdc_ecc',
104
104
inputnode = pe .Node (niu .IdentityInterface (fields = ['in_file' , 'in_bvec' , 'in_bval' ,
105
105
'alt_file' ]), name = 'inputnode' )
106
106
107
- outputnode = pe .Node (niu .IdentityInterface (fields = ['out_file' , 'out_mask' , 'out_bvec' ]),
108
- name = 'outputnode' )
107
+ outputnode = pe .Node (niu .IdentityInterface (fields = ['out_file' , 'out_mask' ,
108
+ 'out_bvec' ]), name = 'outputnode' )
109
109
110
110
avg_b0_0 = pe .Node (niu .Function (input_names = ['in_dwi' , 'in_bval' ],
111
111
output_names = ['out_file' ], function = b0_average ), name = 'b0_avg_pre' )
@@ -118,6 +118,8 @@ def all_peb_pipeline(name='hmc_sdc_ecc',
118
118
sdc = sdc_peb (epi_params = epi_params , altepi_params = altepi_params )
119
119
ecc = ecc_pipeline ()
120
120
121
+ unwarp = apply_all_corrections ()
122
+
121
123
wf = pe .Workflow ('dMRI_Artifacts' )
122
124
wf .connect ([
123
125
(inputnode , hmc , [('in_file' , 'inputnode.in_file' ),
@@ -137,8 +139,15 @@ def all_peb_pipeline(name='hmc_sdc_ecc',
137
139
,(ecc , avg_b0_1 , [('outputnode.out_file' , 'in_dwi' )])
138
140
,(inputnode , avg_b0_1 , [('in_bval' , 'in_bval' )])
139
141
,(avg_b0_1 , bet_dwi1 , [('out_file' ,'in_file' )])
140
- ,(ecc , outputnode , [('outputnode.out_file' , 'out_file' )])
142
+
143
+
144
+ ,(inputnode , unwarp , [('in_file' , 'inputnode.in_dwi' )])
145
+ ,(hmc , unwarp , [('outputnode.out_xfms' , 'inputnode.in_hmc' )])
146
+ ,(ecc , unwarp , [('outputnode.out_xfms' , 'inputnode.in_ecc' )])
147
+ ,(sdc , unwarp , [('outputnode.out_warp' , 'inputnode.in_sdc' )])
148
+
141
149
,(hmc , outputnode , [('outputnode.out_bvec' , 'out_bvec' )])
150
+ ,(unwarp , outputnode , [('outputnode.out_file' , 'out_file' )])
142
151
,(bet_dwi1 , outputnode , [('mask_file' , 'out_mask' )])
143
152
])
144
153
return wf
@@ -575,13 +584,16 @@ def sdc_peb(name='peb_correction',
575
584
enc_dir = 'y' ,
576
585
epi_factor = 1 )):
577
586
"""
578
- SDC stands for susceptibility distortion correction. PEB stands for phase-encoding-based.
579
-
580
- The phase-encoding-based (PEB) method implements SDC by acquiring diffusion images with
581
- two different enconding directions [Andersson2003]_. The most typical case is acquiring
582
- with opposed phase-gradient blips (e.g. *A>>>P* and *P>>>A*, or equivalently, *-y* and *y*)
583
- as in [Chiou2000]_, but it is also possible to use orthogonal configurations [Cordes2000]_
584
- (e.g. *A>>>P* and *L>>>R*, or equivalently *-y* and *x*).
587
+ SDC stands for susceptibility distortion correction. PEB stands for
588
+ phase-encoding-based.
589
+
590
+ The phase-encoding-based (PEB) method implements SDC by acquiring
591
+ diffusion images with two different enconding directions [Andersson2003]_.
592
+ The most typical case is acquiring with opposed phase-gradient blips
593
+ (e.g. *A>>>P* and *P>>>A*, or equivalently, *-y* and *y*)
594
+ as in [Chiou2000]_, but it is also possible to use orthogonal
595
+ configurations [Cordes2000]_ (e.g. *A>>>P* and *L>>>R*,
596
+ or equivalently *-y* and *x*).
585
597
This workflow uses the implementation of FSL
586
598
(`TOPUP <http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/TOPUP>`_).
587
599
@@ -597,39 +609,47 @@ def sdc_peb(name='peb_correction',
597
609
598
610
.. admonition:: References
599
611
600
- .. [Andersson2003] Andersson JL et al., `How to correct susceptibility distortions in
601
- spin-echo echo-planar images: application to diffusion tensor imaging
602
- <http://dx.doi.org/10.1016/S1053-8119(03)00336-7>`_.
612
+ .. [Andersson2003] Andersson JL et al., `How to correct susceptibility
613
+ distortions in spin-echo echo-planar images: application to diffusion
614
+ tensor imaging <http://dx.doi.org/10.1016/S1053-8119(03)00336-7>`_.
603
615
Neuroimage. 2003 Oct;20(2):870-88. doi: 10.1016/S1053-8119(03)00336-7
604
616
605
- .. [Cordes2000] Cordes D et al., Geometric distortion correction in EPI using two
606
- images with orthogonal phase-encoding directions, in Proc. ISMRM (8), p.1712,
607
- Denver, US, 2000.
617
+ .. [Cordes2000] Cordes D et al., Geometric distortion correction in EPI
618
+ using two images with orthogonal phase-encoding directions, in Proc.
619
+ ISMRM (8), p.1712, Denver, US, 2000.
608
620
609
- .. [Chiou2000] Chiou JY, and Nalcioglu O, A simple method to correct off-resonance
610
- related distortion in echo planar imaging, in Proc. ISMRM (8), p.1712, Denver, US,
611
- 2000.
621
+ .. [Chiou2000] Chiou JY, and Nalcioglu O, A simple method to correct
622
+ off-resonance related distortion in echo planar imaging, in Proc.
623
+ ISMRM (8), p.1712, Denver, US, 2000.
612
624
613
625
"""
614
626
615
- inputnode = pe .Node (niu .IdentityInterface (fields = ['in_file' , 'in_bval' , 'in_mask' ,
616
- 'alt_file' , 'ref_num' ]),
627
+ inputnode = pe .Node (niu .IdentityInterface (fields = ['in_file' , 'in_bval' ,
628
+ 'in_mask' , ' alt_file' , 'ref_num' ]),
617
629
name = 'inputnode' )
618
- outputnode = pe .Node (niu .IdentityInterface (fields = ['out_file' , 'out_vsm' ]) ,
619
- name = 'outputnode' )
630
+ outputnode = pe .Node (niu .IdentityInterface (fields = ['out_file' , 'out_vsm' ,
631
+ 'out_warp' ]), name = 'outputnode' )
620
632
621
633
b0_ref = pe .Node (fsl .ExtractROI (t_size = 1 ), name = 'b0_ref' )
622
634
b0_alt = pe .Node (fsl .ExtractROI (t_size = 1 ), name = 'b0_alt' )
623
635
b0_comb = pe .Node (niu .Merge (2 ), name = 'b0_list' )
624
636
b0_merge = pe .Node (fsl .Merge (dimension = 't' ), name = 'b0_merged' )
625
637
626
638
topup = pe .Node (fsl .TOPUP (), name = 'topup' )
627
- topup .inputs .encoding_direction = [epi_params ['enc_dir' ], altepi_params ['enc_dir' ]]
639
+ topup .inputs .encoding_direction = [epi_params ['enc_dir' ],
640
+ altepi_params ['enc_dir' ]]
628
641
topup .inputs .readout_times = [compute_readout (epi_params ),
629
642
compute_readout (altepi_params )]
630
643
631
644
unwarp = pe .Node (fsl .ApplyTOPUP (in_index = [1 ], method = 'jac' ), name = 'unwarp' )
632
645
646
+ scaling = pe .Node (niu .Function (input_names = ['in_file' , 'enc_dir' ],
647
+ output_names = ['factor' ], function = _get_zoom ),
648
+ name = 'GetZoom' )
649
+ scaling .inputs .enc_dir = epi_params ['enc_dir' ]
650
+ vsm2dfm = vsm2warp ()
651
+ vsm2dfm .inputs .inputnode .enc_dir = epi_params ['enc_dir' ]
652
+
633
653
wf = pe .Workflow (name = name )
634
654
wf .connect ([
635
655
(inputnode , b0_ref , [('in_file' , 'in_file' ),
@@ -645,6 +665,13 @@ def sdc_peb(name='peb_correction',
645
665
('out_enc_file' , 'encoding_file' )])
646
666
,(inputnode , unwarp , [('in_file' , 'in_files' )])
647
667
,(unwarp , outputnode , [('out_corrected' , 'out_file' )])
668
+
669
+ ,(b0_ref , scaling , [('roi_file' , 'in_file' )])
670
+ ,(b0_ref , vsm2dfm , [('roi_file' , 'inputnode.in_ref' )])
671
+ ,(scaling , vsm2dfm , [('factor' , 'inputnode.scaling' )])
672
+ ,(topup , vsm2dfm , [('out_field' , 'inputnode.in_vsm' )])
673
+ ,(topup , outputnode , [('out_field' , 'out_vsm' )])
674
+ ,(vsm2dfm , outputnode , [('outputnode.out_warp' , 'out_warp' )])
648
675
])
649
676
return wf
650
677
@@ -706,9 +733,25 @@ def _checkrnum(ref_num):
706
733
def _nonb0 (in_bval ):
707
734
import numpy as np
708
735
bvals = np .loadtxt (in_bval )
709
- return np .where (bvals != 0 )[0 ].tolist ()
736
+ return np .where (bvals != 0 )[0 ].tolist ()
737
+
710
738
711
739
def _xfm_jacobian (in_xfm ):
712
740
import numpy as np
713
741
from math import fabs
714
742
return [fabs (np .linalg .det (np .loadtxt (xfm ))) for xfm in in_xfm ]
743
+
744
+
745
+ def _get_zoom (in_file , enc_dir ):
746
+ import nibabel as nb
747
+
748
+ zooms = nb .load (in_file ).get_zooms ()
749
+
750
+ if 'y' in enc_dir :
751
+ return zooms [1 ]
752
+ elif 'x' in enc_dir :
753
+ return zooms [0 ]
754
+ elif 'z' in enc_dir :
755
+ return zooms [2 ]
756
+ else :
757
+ raise ValueError ('Wrong encoding direction string' )
0 commit comments