-
Notifications
You must be signed in to change notification settings - Fork 3
/
fill_nw
executable file
·70 lines (58 loc) · 1.94 KB
/
fill_nw
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
#!/bin/sh
Usage() {
cat <<EOF
fill_nw - Fills enclosed portions of a mask. Iteratively dilates and masks until convergence.
For research purposes only! Please see LICENSE.txt
Nate Wetter <[email protected]>
Brad Sutton <[email protected]>
Magnetic Resonance Functional Imaging Lab <mrfil.bioen.illinois.edu>
University of Illinois at Urbana-Champaign <illinois.edu>
Use: fill_nw <in> <mask> <out>
Required parameters:
<in> : Input image to be dilated.
<mask> : Mask with enclosed portions to be filled. Masks <in> every iteration.
<out> : Output file name.
Last updated: September 24, 2014
EOF
exit 1
}
[ -z "$3" ] && Usage
in=`remove_ext $1`
mask=`remove_ext $2`
out=`remove_ext $3`
failed=0
# verify validity of input images
if [ `imtest $in` = 0 ]; then
echo "ERROR: $in (input image) is not a valid image"
failed=1
fi
if [ `imtest $mask` = 0 ]; then
echo "ERROR: $mask (mask image) is not a valid image"
failed=1
fi
if [ "$failed" = 1 ]; then
echo "Exiting"
exit 1
fi
# begin computation
cluster --in=${mask} --thresh=0.5 -o ${mask}_cluster --no_table
index_max=$(fslstats ${mask}_cluster -R | cut -d' ' -f2 | cut -d'.' -f1)
index_cur=1
while [ $index_cur -le $index_max ]
do
echo $index_cur
index_prev=`expr $index_cur - 1`
fslmaths ${mask}_cluster -thr ${index_prev}.5 -uthr ${index_cur}.5 cluster_current
fslmaths cluster_current -mas $in cluster_current_masked
if [ $(fslstats cluster_current_masked -R | cut -d' ' -f2 | cut -d'.' -f1) -eq 0 ]; then
# remove cluster
#fslmaths cluster_current -binv cluster_current_inv
#fslmaths ${mask}_cluster -mas cluster_current_inv ${mask}_cluster
fslmaths ${mask}_cluster -sub cluster_current ${mask}_cluster
echo "cluster rejected $(fslstats cluster_current -R | cut -d' ' -f2 | cut -d'.' -f1) = $index_cur"
else
echo "cluster retained"
fi
index_cur=`expr $index_cur + 1`
done
immv ${mask}_cluster $out