-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathlightbox.sh
executable file
·209 lines (154 loc) · 5.94 KB
/
lightbox.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
#!/bin/bash
overlay=""
overlay_args=""
flag=0
alpha=25.0
cmap=red-yellow
modulateMax=1.0
secondOverlayflag=0
secondOverlay=""
secondOverlayColor=""
secondOverlayAlpha=25.0
label_or_volume_first="volume"
label_or_volume_second="volume"
xlimit=10
ylimit=10
zlimit=10
brightness_var=49.152368365123955
contrast_var=49.90029860765409
while getopts ":o:a:p:s:h:i:j:k:x:y:z:b:c:" opt; do
case $opt in
o) #overlay file
overlay=$OPTARG
flag=1
;;
a) #overlay alpha value
alpha=$OPTARG
flag=1
;;
p) #overlay cmap value
cmap=$OPTARG
flag=1
;;
s)
secondOverlay=$OPTARG
secondOverlayflag=1
flag=1
;;
h)
secondOverlayColor=$OPTARG
secondOverlayflag=1
flag=1
;;
i)
secondOverlayAlpha=$OPTARG
secondOverlayflag=1
flag=1
;;
j)
label_or_volume_first=$OPTARG
flag=1
;;
k)
label_or_volume_second=$OPTARG
secondOverlayflag=1
flag=1
;;
b)
brightness_var=$OPTARG
;;
c)
contrast_var=$OPTARG
;;
x)
xlimit=$OPTARG
;;
y)
ylimit=$OPTARG
;;
z)
zlimit=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
shift "$((OPTIND-1))"
if [ "$flag" -eq "1" ]; then
if [ "$overlay" = "" ]; then
echo "ERROR: Overlay display options require overlay option and overlay argument (-o)." >&2
exit 1
fi
fi
if [ "$secondOverlayflag" -eq "1" ]; then
if [ "$secondOverlay" = "" ]; then
echo "ERROR: Second Overlay display options require overlay option and overlay argument (-o)." >&2
exit 1
fi
fi
underlay=$1
first_overlay_template=""
if [ "$label_or_volume_first" = "volume" ]; then
first_overlay_template="--overlayType volume --alpha $alpha --brightness 49.75000000000001 --contrast 49.90029860765409 --cmap $cmap --negativeCmap greyscale --gamma 0.0 --cmapResolution 256 --interpolation none --numSteps 100 --blendFactor 0.1 --smoothing 0 --resolution 100 --numInnerSteps 10 --clipMode intersection --volume 0"
else
first_overlay_template="--overlayType label --alpha $alpha --brightness 49.75000000000001 --contrast 49.90029860765409 --lut $cmap --outlineWidth 1 --volume 0"
fi
second_overlay_template=""
if [ "$label_or_volume_second" = "volume" ]; then
second_overlay_template="--overlayType volume --alpha $secondOverlayAlpha --brightness 49.75000000000001 --contrast 49.90029860765409 --cmap $secondOverlayColor --negativeCmap greyscale --gamma 0.0 --cmapResolution 256 --interpolation none --numSteps 100 --blendFactor 0.1 --smoothing 0 --resolution 100 --numInnerSteps 10 --clipMode intersection --volume 0"
else
second_overlay_template="--overlayType label --alpha $secondOverlayAlpha --brightness 49.75000000000001 --contrast 49.90029860765409 --lut $secondOverlayColor --outlineWidth 1 --volume 0"
fi
declare -a axisNames
axisNames[0]=sagittal
axisNames[1]=coronal
axisNames[2]=axial
subject_folder=$2
dim1=`${FSLDIR}/bin/fslval $subject_folder$underlay dim1`
dim2=`${FSLDIR}/bin/fslval $subject_folder$underlay dim2`
dim3=`${FSLDIR}/bin/fslval $subject_folder$underlay dim3`
pixdim1=`${FSLDIR}/bin/fslval $subject_folder$underlay pixdim1`
pixdim2=`${FSLDIR}/bin/fslval $subject_folder$underlay pixdim2`
pixdim3=`${FSLDIR}/bin/fslval $subject_folder$underlay pixdim3`
dim1=$(echo "scale=4;$dim1 * $pixdim1" | bc)
dim2=$(echo "scale=4;$dim2 * $pixdim2" | bc)
dim3=$(echo "scale=4;$dim3 * $pixdim3" | bc)
startingx=$(echo "scale=4;$dim1 * $xlimit/100" | bc) #`$(($dim1*$xlimit/100)) | bc` #10 #50
endingx=$(echo "scale=4;$dim1 * (100-$xlimit)/100" | bc) #$(($dim1*$((100-$xlimit))/100)) #95 #130
startingy=$(echo "scale=4;$dim2 * $ylimit/100" | bc) #$(($dim2*$ylimit/100)) #10 #75
endingy=$(echo "scale=4;$dim2 * (100-$ylimit)/100" | bc) #$(($dim2*$((100-$ylimit))/100)) #95 #160
startingz=$(echo "scale=4;$dim3 * $zlimit/100" | bc) #$(($dim3*$zlimit/100)) #10 #75
endingz=$(echo "scale=4;$dim3 * (100-$zlimit)/100" | bc) #$(($dim3*$((100-$zlimit))/100)) #65 #135
declare -a sliceSpacing
sliceSpacing[0]=$(echo "scale=4;($endingx-$startingx)/17 + 1" | bc)
sliceSpacing[1]=$(echo "scale=4;($endingy-$startingy)/17 + 1" | bc)
sliceSpacing[2]=$(echo "scale=4;($endingz-$startingz)/17 + 1" | bc)
sliceSpacing[0]=${sliceSpacing[0]%.*}
sliceSpacing[1]=${sliceSpacing[1]%.*}
sliceSpacing[2]=${sliceSpacing[2]%.*}
declare -a zrange
zrange[0]=${startingx%.*}
zrange[1]=${endingx%.*}
zrange[2]=${startingy%.*}
zrange[3]=${endingy%.*}
zrange[4]=${startingz%.*}
zrange[5]=${endingz%.*}
output_folder=$subject_folder/QC/images/$3
mkdir -p $output_folder
sub=$(basename $subject_folder)
if [ "$flag" -eq "1" ]; then
if [ "$secondOverlayflag" -eq "1" ]; then
overlay_args="$subject_folder$overlay --name "overlay" $first_overlay_template $subject_folder$secondOverlay --name "overlay1" $second_overlay_template"
else
overlay_args="$subject_folder$overlay --name "overlay" $first_overlay_template"
fi
fi
for ((i=0; i<3; i++)); do
${FSLDIR}/bin/fsleyes render --outfile $output_folder/$sub"_$3_"${axisNames[$i]}.png --crop 30 --size 6400 2400 --scene lightbox --displaySpace $subject_folder$underlay --zaxis $i --sliceSpacing ${sliceSpacing[$i]} --zrange ${zrange[2*$i]} ${zrange[2*$i+1]} --ncols 6 --nrows 3 --hideCursor --bgColour 0.0 0.0 0.0 --fgColour 1.0 1.0 1.0 --cursorColour 0.0 1.0 0.0 --colourBarLocation top --colourBarLabelSide top-left --colourBarSize 100.0 --labelSize 12 --performance 3 $subject_folder$underlay --name "underlay" --overlayType volume --alpha 100.0 --brightness $brightness_var --contrast $contrast_var --cmap greyscale --negativeCmap greyscale --gamma 0.0 --cmapResolution 256 --interpolation none --numSteps 100 --blendFactor 0.1 --smoothing 0 --resolution 100 --numInnerSteps 10 --clipMode intersection --volume 0 $overlay_args
done