-
Notifications
You must be signed in to change notification settings - Fork 0
/
canonical_test.sh
executable file
·256 lines (229 loc) · 6.46 KB
/
canonical_test.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#!/bin/bash
#on MacOS use -l for maximum memory details
#/usr/bin/time -l niimath test4D -add 0 tst
#exe is executable, e.g. fslmaths or niimath
# we assume it is in the users path
# however, this could be set explicitly, e.g.
# exe="/Users/cr/fslmaths" canonical_test.sh
exe=${exe:-niimath}
#exe=${exe:-fslmaths}
#tstexe is executable with "compare" function, e.g. niimath
#n.b. fslmaths does not have this function
# we assume it is in the users path
# however, this could be set explicitly
tstexe=${tstexe:-niimath}
#basedir is folder with "In" subfolder.
# we assume it is the same same folder as the script
# however, this could be set explicitly, e.g.
# basedir="/Users/cr/niitest" batch.sh
if [ -z ${basedir:-} ]; then
basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
fi
#### no need to edit subsequent lines
# Fail if anything not planed to go wrong, goes wrong
set -eu
# Test if command exists.
exists() {
test -x "$(command -v "$1")"
}
# Check executables.
exists $exe ||
{
echo >&2 "I require $exe but it's not installed. Aborting."
exit 1
}
exists $tstexe ||
{
echo >&2 "I require $tstexe but it's not installed. Aborting."
exit 1
}
#folder paths
indir=${basedir}/In
outdir=${basedir}/New
refdir=${basedir}/Canonical
if [ ! -d "$indir" ]; then
echo "Error: Unable to find $indir"
exit 1
fi
if [ ! -d "$refdir" ]; then
echo "Error: Unable to find $refdir"
exit 1
fi
if [ ! -d "$outdir" ]; then
mkdir $outdir
fi
if [ ! -z "$(ls $outdir)" ]; then
echo "Cleaning output directory: $outdir"
rm $outdir/*
fi
refout="$refdir/"
newout="$outdir/"
inimg="$indir/trick"
op=demean
echo Testing ${op}
cmd="$exe $inimg -Tmean -mul -1 -add $inimg ${newout}${op}"
$cmd
tst="$tstexe ${refout}${op} --compare ${newout}${op}"
$tst
ops="thrp uthrp Tperc Xperc Yperc Zperc inm ing add sub mul div rem thr uthr max min"
inimg="$indir/trick"
family="BinaryEven"
for op in $ops; do
echo Creating ${op}${family}
cmd="$exe $inimg -$op 50 ${newout}${op}${family}"
$cmd
tst="$tstexe ${refout}${op}${family} --compare ${newout}${op}${family}"
$tst
done
ops="thrP uthrP"
inimg="$indir/trick"
family="BinaryPEven"
for op in $ops; do
echo Creating ${op}${family}
cmd="$exe $inimg -$op 50 ${newout}${op}${family}"
$cmd
tst="$tstexe ${refout}${op}${family} --compare ${newout}${op}${family}"
$tst
done
ops="Tperc Xperc Yperc Zperc inm ing add sub mul div rem thr uthr max min"
inimg="$indir/3vols"
family="BinaryOdd"
for op in $ops; do
echo Creating ${op}${family}
cmd="$exe $inimg -$op 50 ${newout}${op}${family}"
$cmd
tst="$tstexe ${refout}${op}${family} --compare ${newout}${op}${family}"
$tst
done
ops="Tmedian Xmedian Zmedian"
family="MedianOdd"
inimg="$indir/3vols"
for op in $ops; do
echo Creating ${op}${family}
cmd="$exe $inimg -$op ${newout}${op}${family}"
$cmd
tst="$tstexe ${refout}${op}${family} --compare ${newout}${op}${family}"
$tst
done
#ALMOST identical Xar1 Yar1 Zar1
ops="Tmedian Xmedian Zmedian Tar1 Tmean Tstd Tmax Tmaxn Tmin Tar1 Xmean Xstd Xmax Xmaxn Xmin Ymean Ystd Ymax Ymaxn Ymin Zmean Zstd Zmax Zmaxn Zmin"
family="ReduceEven"
inimg="$indir/trick"
for op in $ops; do
echo Creating ${op}${family}
cmd="$exe $inimg -$op ${newout}${op}${family}"
$cmd
tst="$tstexe ${refout}${op}${family} --compare ${newout}${op}${family}"
$tst
done
rx="AIL AIR ALI ALS ARI ARS ASL ASR IAL IAR ILA ILP IPL IPR IRA IRP LAI LAS LIA LIP LPI LPS LSA LSP PIL PIR PLI PLS PRI PRS PSL PSR RAI RAS RIA RIP RPI RPS RSA RSP SAL SAR SLA SLP SPL SPR SRA SRP"
## -roi <xmin> <xsize> <ymin> <ysize> <zmin> <zsize> <tmin> <tsize> zero outside roi
family="roi"
for op in $rx; do
inimg="$indir/$op"
echo Creating ${op}${family}
cmd="$exe $inimg -roi 5 19 3 22 2 28 0 1 ${newout}${op}${family}"
$cmd
tst="$tstexe ${refout}${op}${family} --compare ${newout}${op}${family}"
$tst
done
echo Testing Binary Operations: with 2nd image
ops="add sub mul div max min rem"
inimg="$indir/trick"
modimg="$indir/trick3D"
family="Binary2Img"
for op in $ops; do
echo Creating ${op}${family}
cmd="$exe $inimg -$op $modimg ${newout}${op}${family}"
$cmd
# reverse order: not all operations are commutative
cmd="$exe $modimg -$op $inimg ${newout}${op}${family}Rev"
$cmd
tst="$tstexe ${refout}${op}${family} --compare ${newout}${op}${family}"
$tst
done
ops="exp log sin cos tan asin acos atan sqr sqrt recip abs bin binv fillh fillh26 index nan nanm"
inimg="trick"
family="Unary"
for op in $ops; do
echo Creating ${op}${family}
cmd="$exe $indir/$inimg -$op ${newout}${op}${family}"
$cmd
tst="$tstexe ${refout}${op}${family} --compare ${newout}${op}${family}"
$tst
done
ops="dilM dilD dilF ero eroF eroF fmedian subsamp2offc"
inimg="trick3D"
family="Filter"
for op in $ops; do
echo Creating ${op}${family}
cmd="$exe $indir/$inimg -$op ${newout}${op}${family}"
$cmd
tst="$tstexe ${refout}${op}${family} --compare ${newout}${op}${family}"
$tst
done
ops="rank ranknorm"
inimg="$indir/no_ties"
for op in $ops; do
echo Creating ${op}
cmd="$exe $inimg -$op ${newout}${op}"
$cmd
tst="$tstexe ${refout}${op} --compare ${newout}${op}"
$tst
done
# band pass temporal filtering
inimg="$indir/rest4D"
echo "Creating bptf (tiny variations expected)"
op=bptfHighPass
thr=0.0001
cmd="$exe $inimg -bptf 25 -1 ${newout}${op}"
$cmd
tst="$tstexe ${refout}${op} --compare ${thr} ${newout}${op}"
$tst
op=bptfLowPass
cmd="$exe $inimg -bptf -1 5 ${newout}${op}"
$cmd
tst="$tstexe ${refout}${op} --compare ${thr} ${newout}${op}"
$tst
op=bptfBandPass
cmd="$exe $inimg -bptf 25 5 ${newout}${op}"
$cmd
tst="$tstexe ${refout}${op} --compare ${thr} ${newout}${op}"
$tst
#Most different voxel 396.58 vs 396.579 (difference 6.10352e-05) location 23x30x1
ops="edge"
inimg="trick"
family="Unary"
thr=0.0001
for op in $ops; do
echo Creating ${op}${family}
cmd="$exe $indir/$inimg -$op ${newout}${op}${family}"
$cmd
tst="$tstexe ${refout}${op}${family} --compare ${thr} ${newout}${op}${family}"
$tst
done
ops="fmean fmeanu"
inimg="trick3D"
family="Filter"
thr=0.0001
for op in $ops; do
echo Creating ${op}${family}
cmd="$exe $indir/$inimg -$op ${newout}${op}${family}"
$cmd
tst="$tstexe ${refout}${op}${family} --compare ${thr} ${newout}${op}${family}"
$tst
done
#Most different voxel 2.50056 vs 2.93827 (difference 0.437711) location 32x38x21
ops="dilall"
inimg="trick3D"
family="Filter"
thr=0.5
for op in $ops; do
echo Creating ${op}${family}
cmd="$exe $indir/$inimg -$op ${newout}${op}${family}"
$cmd
tst="$tstexe ${refout}${op}${family} --compare ${thr} ${newout}${op}${family}"
$tst
done
echo "$exe passed tests"
exit 0