-
Notifications
You must be signed in to change notification settings - Fork 0
/
conformance.sh
executable file
·219 lines (199 loc) · 5.32 KB
/
conformance.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
#!/bin/bash
#on MacOS use -l for maximum memory details
#/usr/bin/time -l niimath test4D -add 0 tst
#refexe is reference executable, e.g. validated copy of fslmaths
# we assume it is in the users path
# however, this could be set explicitly, e.g.
# refexe="/Users/cr/fslmaths" batch.sh
refexe=${refexe:-fslmaths}
#newexe is new executable, e.g. we want to make sure if gives the same results as refexe
# this could also be set explicitly, e.g.
# refexe="/Users/cr/fslmaths" batch.sh
newexe=${newexe:-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 $refexe ||
{
echo >&2 "I require $refexe but it's not installed. Aborting."
exit 1
}
exists $newexe ||
{
echo >&2 "I require $newexe but it's not installed. Aborting."
exit 1
}
#folder paths
indir=${basedir}/In
newdir=${basedir}/New
refdir=${basedir}/Ref
if [ ! -d "$indir" ]; then
echo "Error: Unable to find $indir"
exit 1
fi
if [ ! -d "$refdir" ]; then
mkdir $refdir
fi
if [ ! -z "$(ls $refdir)" ]; then
echo "Cleaning output directory: $refdir"
rm $refdir/*
fi
if [ ! -d "$newdir" ]; then
mkdir $newdir
fi
if [ ! -z "$(ls $newdir)" ]; then
echo "Cleaning output directory: $newdir"
rm $newdir/*
fi
# Convert images.
refout="$refdir/ref"
newout="$newdir/new"
echo Testing Operation Comibinations: demean
# fslmaths 4D_inputVolume -Tmean -mul -1 -add 4D_inputVolume demeaned_4D_inputVolume
inimg="$indir/trick"
cmd="$refexe $inimg -Tmean -mul -1 -add $inimg $refout"
echo $cmd
$cmd
cmd="$newexe $inimg -Tmean -mul -1 -add $inimg $newout"
echo $cmd
$cmd
tst="$newexe $refout --compare $newout"
echo $tst
$tst
echo Testing Binary Operations: with fixed value
#ops="add sub mul div rem thr thrp thrP uthr uthrp uthrP max min"
ops="thrp thrP uthrp uthrP Tperc Xperc Yperc Zperc inm ing add sub mul div rem thr uthr max min"
inimg="$indir/trick"
for op in $ops; do
cmd="$refexe $inimg -$op 50 $refout"
echo $cmd
$cmd
cmd="$newexe $inimg -$op 50 $newout"
echo $cmd
$cmd
tst="$newexe $refout --compare $newout"
echo $tst
$tst
done
echo Testing Binary Operations: with fixed value with odd number of volumes
#ops="add sub mul div rem thr thrp thrP uthr uthrp uthrP max min"
ops="Tperc Xperc Yperc Zperc inm ing add sub mul div rem thr uthr max min"
inimg="$indir/3vols"
for op in $ops; do
cmd="$refexe $inimg -$op 50 $refout"
echo $cmd
$cmd
cmd="$newexe $inimg -$op 50 $newout"
echo $cmd
$cmd
tst="$newexe $refout --compare $newout"
echo $tst
$tst
done
ops="Tmedian Xmedian Zmedian"
echo Median with odd number of volumes
for op in $ops; do
inimg="$indir/3vols"
cmd="$refexe $inimg -$op $refout"
echo $cmd
$cmd
cmd="$newexe $inimg -$op $newout"
echo $cmd
$cmd
tst="$newexe $refout --compare $newout"
echo $tst
$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"
echo Testing Dimensionality reduction
for op in $ops; do
inimg="$indir/trick"
cmd="$refexe $inimg -$op $refout"
echo $cmd
$cmd
cmd="$newexe $inimg -$op $newout"
echo $cmd
$cmd
tst="$newexe $refout --compare $newout"
echo $tst
$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
for img in $rx; do
inimg="$indir/$img"
cmd="$refexe $inimg -roi 5 19 3 22 2 28 0 1 $refout"
echo $cmd
$cmd
cmd="$newexe $inimg -roi 5 19 3 22 2 28 0 1 $newout"
echo $cmd
$cmd
tst="$newexe $refout --compare $newout"
echo $tst
$tst
done
echo Testing Binary Operations: with 2nd image
#ops="add sub mul div rem thr thrp thrP uthr uthrp uthrP max min"
ops="add sub mul div max min rem"
inimg="$indir/trick"
modimg="$indir/trick3D"
for op in $ops; do
cmd="$refexe $inimg -$op $modimg $refout"
echo $cmd
$cmd
cmd="$newexe $inimg -$op $modimg $newout"
echo $cmd
$cmd
tst="$newexe $refout --compare $newout"
echo $tst
$tst
# reverse order: not all operations are commutative
cmd="$refexe $modimg -$op $inimg $refout"
echo $cmd
$cmd
cmd="$newexe $modimg -$op $inimg $newout"
echo $cmd
$cmd
tst="$newexe $refout --compare $newout"
echo $tst
$tst
done
echo Testing Basic unary operations
ops="exp log sin cos tan asin acos atan sqr sqrt recip abs bin binv fillh fillh26 index edge nan nanm"
inimg="trick"
for op in $ops; do
cmd="$refexe $indir/$inimg -$op $refout"
echo $cmd
$cmd
cmd="$newexe $indir/$inimg -$op $newout"
$cmd
tst="$newexe $refout --compare $newout"
$cmd
done
echo Spatial Filtering operations
ops="dilM dilD dilF dilall ero eroF eroF fmedian fmean fmeanu subsamp2offc"
inimg="trick3D"
for op in $ops; do
cmd="$refexe $indir/$inimg -$op $refout"
echo $cmd
$cmd
cmd="$newexe $indir/$inimg -$op $newout"
$cmd
tst="$newexe $refout --compare $newout"
$cmd
done
echo SUCCESS
exit 0