forked from HBClab/RestingState
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfslreorient.sh
executable file
·213 lines (179 loc) · 2.96 KB
/
fslreorient.sh
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
#!/bin/bash
infile=$1
#Determine qform-orientation to properly reorient file to RPI (MNI) orientation
xorient=`fslhd ${infile} | grep "^qform_xorient" | awk '{print $2}' | cut -c1`
yorient=`fslhd ${infile} | grep "^qform_yorient" | awk '{print $2}' | cut -c1`
zorient=`fslhd ${infile} | grep "^qform_zorient" | awk '{print $2}' | cut -c1`
native_orient=${xorient}${yorient}${zorient}
echo "native orientation = ${native_orient}"
if [ "${native_orient}" != "RPI" ]; then
case ${native_orient} in
#L PA IS
LPI)
flipFlag="-x y z"
;;
LPS)
flipFlag="-x y -z"
;;
LAI)
flipFlag="-x -y z"
;;
LAS)
flipFlag="-x -y -z"
;;
#R PA IS
RPS)
flipFlag="x y -z"
;;
RAI)
flipFlag="x -y z"
;;
RAS)
flipFlag="x -y -z"
;;
#L IS PA
LIP)
flipFlag="-x z y"
;;
LIA)
flipFlag="-x -z y"
;;
LSP)
flipFlag="-x z -y"
;;
LSA)
flipFlag="-x -z -y"
;;
#R IS PA
RIP)
flipFlag="x z y"
;;
RIA)
flipFlag="x -z y"
;;
RSP)
flipFlag="x z -y"
;;
RSA)
flipFlag="x -z -y"
;;
#P IS LR
PIL)
flipFlag="-z x y"
;;
PIR)
flipFlag="z x y"
;;
PSL)
flipFlag="-z x -y"
;;
PSR)
flipFlag="z x -y"
;;
#A IS LR
AIL)
flipFlag="-z -x y"
;;
AIR)
flipFlag="z -x y"
;;
ASL)
flipFlag="-z -x -y"
;;
ASR)
flipFlag="z -x -y"
;;
#P LR IS
PLI)
flipFlag="-y x z"
;;
PLS)
flipFlag="-y x -z"
;;
PRI)
flipFlag="y x z"
;;
PRS)
flipFlag="y x -z"
;;
#A LR IS
ALI)
flipFlag="-y -x z"
;;
ALS)
flipFlag="-y -x -z"
;;
ARI)
flipFlag="y -x z"
;;
ARS)
flipFlag="y -x -z"
;;
#I LR PA
ILP)
flipFlag="-y z x"
;;
ILA)
flipFlag="-y -z x"
;;
IRP)
flipFlag="y z x"
;;
IRA)
flipFlag="y -z x"
;;
#S LR PA
SLP)
flipFlag="-y z -x"
;;
SLA)
flipFlag="-y -z -x"
;;
SRP)
flipFlag="y z -x"
;;
SRA)
flipFlag="y -z -x"
;;
#I PA LR
IPL)
flipFlag="-z y x"
;;
IPR)
flipFlag="z y x"
;;
IAL)
flipFlag="-z -y x"
;;
IAR)
flipFlag="z -y x"
;;
#S PA LR
SPL)
flipFlag="-z y -x"
;;
SPR)
flipFlag="z y -x"
;;
SAL)
flipFlag="-z -y -x"
;;
SAR)
flipFlag="z -y -x"
;;
esac
echo "flipping by ${flipFlag}"
#Reorienting image and checking for warning messages
warnFlag=`fslswapdim ${infile} ${flipFlag} ${infile%.nii.gz}_MNI.nii.gz`
warnFlagCut=`echo ${warnFlag} | awk -F":" '{print $1}'`
#Reorienting the file may require swapping out the flag orientation to match the .img block
if [[ $warnFlagCut == "WARNING" ]]; then
fslorient -swaporient ${infile%.nii.gz}_MNI.nii.gz
fi
else
echo "No need to reorient. Dataset already in RPI orientation."
if [ ! -e ${infile%.nii.gz}_MNI.nii.gz ]; then
cp ${infile} ${infile%.nii.gz}_MNI.nii.gz
fi
fi
#Output should now be in RPI orientation and ready for analysis