-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdemo_hardiprep.py
More file actions
180 lines (130 loc) · 5.28 KB
/
demo_hardiprep.py
File metadata and controls
180 lines (130 loc) · 5.28 KB
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
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 10 09:44:46 2015
@author: Shireen Elhabian
Objective:
this script shows how to use the hardiprep pipeline on a single subject dataset
Input:
DWI nrrd file
output directory
"""
from __future__ import division
import os
import glob
import numpy as np
import ntpath
import time
import hardi.nrrd
import hardi.io as hardiIO
import hardi.qc as hardiQC
# the nrrdfilename to be processed
nrrdfilename = 'SAMPLE_DATA/5624895_DSI.nrrd'
# where to put the processing output
outDir = 'SAMPLE_DATA'
"""
---------------------------------------------------------------------------------
STEP Zero
---------------------------------------------------------------------------------
(1) create hardi QC directories and copy the original nrrd
(2) fix the dimension and thickness of the given nrrd files
(3) convert them to nifti and generate the btable for dsi_studio visualization
"""
#prepDir = hardiQC.PrepareQCsession(nrrdfilename, outDir)
prepDir = os.path.join(outDir, 'HARDIprep_QC')
"""
---------------------------------------------------------------------------------
STEP ONE
---------------------------------------------------------------------------------
OBJECTIVE:
dtiprep without motion correction
check the quality of the individual directions, e.g. missing slices, intensity artifacts, Venetian blind
"""
xmlfilename = os.path.join('PROTOCOLS/protocol_DTIPrep1.2.3_DSI.xml')
#hardiQC.RunDTIPrepStage(nrrdfilename, prepDir, xmlfilename)
"""
---------------------------------------------------------------------------------
STEP TWO
---------------------------------------------------------------------------------
OBJECTIVE:
quantify fast bulk motion within each gradient to exclude those having intra-scan
motion (see Benner et al (2011) - Diffusion imaging with prospective motion correction and reacquisition)
here we have zero tolerance, any gradient having at least one slice with signal drop out will be excluded
"""
hardiQC.PerformWithinGradientMotionQC(nrrdfilename, prepDir)
"""
---------------------------------------------------------------------------------
STEP TRHEE
---------------------------------------------------------------------------------
Assumptions:
(1) WithinGradientMotionQC has been performed
(2) DTIPrep (without motion) has been performed
"""
hardiQC.ExtractBaselineAndBrainMask(nrrdfilename, prepDir)
"""
---------------------------------------------------------------------------------
STEP FOUR
---------------------------------------------------------------------------------
OBJECTIVE:
resample the corrupted slices (detected via DTIPrep and within-gradient motion) Qc
in the q-space plus gradient-wise denoising
"""
hardiQC.PerformResampleCorruptedSlicesInQspaceAndGradientDenoise(nrrdfilename, prepDir)
"""
---------------------------------------------------------------------------------
STEP FIVE
---------------------------------------------------------------------------------
OBJECTIVE:
construct the reference volume for each data set using Qball-FMAM
we will use fit model to all measurements since the phantom data would have the
minimal motion yet when move to infants we will need to implement a restore-like modelbased motion correction
"""
hardiQC.ComputeModelBasedReference_FMAM(nrrdfilename, prepDir)
"""
---------------------------------------------------------------------------------
STEP SIX
---------------------------------------------------------------------------------
OBJECTIVE:
correct for motion the DTIPrep QCed sequences where slice-wise/gradient-wise denoising already
been carried out, as such we can use standard interpolation
"""
hardiQC.PerformModelBasedReferenceMotionCorrectionMCFLIRT12DOF(nrrdfilename, prepDir)
"""
---------------------------------------------------------------------------------
STEP SEVEN
---------------------------------------------------------------------------------
OBJECTIVE:
brain mask the motion corrected datasets
"""
hardiQC.BrainMaskModelBasedMotionCorrectedDWI(nrrdfilename, prepDir)
"""
---------------------------------------------------------------------------------
STEP EIGHT
---------------------------------------------------------------------------------
OBJECTIVE:
compute the bias field based on the baseline and apply it on the other gradients
"""
hardiQC.PerformBiasFieldCorrection(nrrdfilename, prepDir)
"""
---------------------------------------------------------------------------------
STEP NINE
---------------------------------------------------------------------------------
OBJECTIVE:
jointly denoise the bias field corrected data
"""
hardiQC.PerformJointLMMSEDenoising(nrrdfilename, prepDir)
"""
---------------------------------------------------------------------------------
STEP TEN
---------------------------------------------------------------------------------
OBJECTIVE:
reconstruction of fiber ODFs in subject space
"""
hardiQC.ReconstructFODFs(nrrdfilename, prepDir)
"""
---------------------------------------------------------------------------------
STEP ELEVEN
---------------------------------------------------------------------------------
OBJECTIVE:
full brain tractography in subject space
"""
hardiQC.PerformFullBrainTractography(nrrdfilename, prepDir)