forked from mrfil/lesion-mapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sienax_nw
executable file
·536 lines (465 loc) · 27.9 KB
/
sienax_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
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
#!/bin/sh
# sienax - Structural Image Evaluation, including Normalisation, of Atrophy (X-sectional)
#
# Stephen Smith, FMRIB Image Analysis Group
#
# Copyright (C) 1999-2007 University of Oxford
#
# Part of FSL - FMRIB's Software Library
# http://www.fmrib.ox.ac.uk/fsl
#
# Developed at FMRIB (Oxford Centre for Functional Magnetic Resonance
# Imaging of the Brain), Department of Clinical Neurology, Oxford
# University, Oxford, UK
#
#
# LICENCE
#
# FMRIB Software Library, Release 5.0 (c) 2012, The University of
# Oxford (the "Software")
#
# The Software remains the property of the University of Oxford ("the
# University").
#
# The Software is distributed "AS IS" under this Licence solely for
# non-commercial use in the hope that it will be useful, but in order
# that the University as a charitable foundation protects its assets for
# the benefit of its educational and research purposes, the University
# makes clear that no condition is made or to be implied, nor is any
# warranty given or to be implied, as to the accuracy of the Software,
# or that it will be suitable for any particular purpose or for use
# under any specific conditions. Furthermore, the University disclaims
# all responsibility for the use which is made of the Software. It
# further disclaims any liability for the outcomes arising from using
# the Software.
#
# The Licensee agrees to indemnify the University and hold the
# University harmless from and against any and all claims, damages and
# liabilities asserted by third parties (including claims for
# negligence) which arise directly or indirectly from the use of the
# Software or the sale of any products based on the Software.
#
# No part of the Software may be reproduced, modified, transmitted or
# transferred in any form or by any means, electronic or mechanical,
# without the express permission of the University. The permission of
# the University is not required if the said reproduction, modification,
# transmission or transference is done without financial return, the
# conditions of this Licence are imposed upon the receiver of the
# product, and all original and amended source code is included in any
# transmitted product. You may be held legally responsible for any
# copyright infringement that is caused or encouraged by your failure to
# abide by these terms and conditions.
#
# You are not permitted under this Licence to use this Software
# commercially. Use for which any financial return is received shall be
# defined as commercial use, and includes (1) integration of all or part
# of the source code or the Software into a product for sale or license
# by or on behalf of Licensee to third parties or (2) use of the
# Software or any derivative of it for research with the final aim of
# developing software products for sale or license to a third party or
# (3) use of the Software or any derivative of it for research with the
# final aim of developing non-software products for sale or license to a
# third party, or (4) use of the Software to provide any service to an
# external organisation for which payment is received. If you are
# interested in using the Software commercially, please contact Isis
# Innovation Limited ("Isis"), the technology transfer company of the
# University, to negotiate a licence. Contact details are:
# [email protected] quoting reference DE/9564.
Usage() {
cat <<EOF
sienax_nw - A modified version of FSL's sienax, updated to make use of multispectral images.
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>
Usage: sienax_nw <input> [options]
-o <output-dir> : set output directory (default output is <input>_sienax)
-d : debug (don't delete intermediate files)
-B "betopts" : options to pass to BET brain extraction (inside double-quotes), e.g. -B "-f 0.3"
-2 : two-class segmentation (don't segment grey and white matter separately)
-t2 : T2-weighted input image (default T1-weighted)
-t <t> : ignore from t (mm) upwards in MNI152/Talairach space
-b <b> : ignore from b (mm) downwards in MNI152/Talairach space (b should probably be negative)
-r : regional - use standard-space masks to give peripheral cortex GM volume (3-class segmentation only) and ventricular CSF volume
-lm <mask> : use lesion (or lesion+CSF) mask to remove incorrectly labelled "grey matter" voxels
-lmt2 <mask> : use this instead of -lm if lesion mask is in T2 image space
-S "segopts" : options to pass to FAST segmentation (inside double-quotes), e.g. -S "I 20"
-in2 <image> : secondary image for multispectral analysis (intended for a T2 image)--need to check compatibility with -lm
-nossm : do not apply standard space masking in addition to BET
-betdir <dir> : if BET was already run with proper options, provide the output directory here
Last updated: September 24, 2014
EOF
exit 1
}
[ _$1 = _ ] && Usage
Io=`${FSLDIR}/bin/remove_ext $1`;
#[ `${FSLDIR}/bin/imtest ${Io}` = 0 ] && Usage
if [ `${FSLDIR}/bin/imtest ${Io}` = 0 ]; then
echo "Input image $Io not a valid image"
Usage
fi
thecommand="sienax $@"
shift
outdir=${Io}_sienax
debug=0
regional=0
betopts=""
segopts=""
nseg=3
stdroi=""
origin3=37 # `fslval ${FSLDIR}/data/standard/MNI152_T1_2mm origin3`
pixdim3=2 # `fslval ${FSLDIR}/data/standard/MNI152_T1_2mm pixdim3`
imtype="-t 1"
IN2=""
SSM="1"
betdir=""
lm=""
lmt2=""
while [ _$1 != _ ] ; do
if [ $1 = -d ] ; then
debug=1
shift
elif [ $1 = -o ] ; then
outdir=$2
shift 2
elif [ $1 = -in2 ] ; then
IN2=$2
shift 2
elif [ $1 = -r ] ; then
regional=1
shift
elif [ $1 = -B ] ; then
betopts=$2
shift 2
elif [ $1 = -S ] ; then
segopts=$2
shift 2
elif [ $1 = -2 ] ; then
nseg=2
shift
elif [ $1 = -t2 ] ; then
imtype="-t 2"
shift
elif [ $1 = -t ] ; then
stdt=`echo $2 | sed 's/-/_/g'`
stdt=`echo "10 k $stdt $pixdim3 / $origin3 + p" | dc -`
stdroi="$stdroi -roi 0 1000000 0 1000000 0 $stdt 0 1"
shift 2
elif [ $1 = -b ] ; then
stdb=`echo $2 | sed 's/-/_/g'`
stdb=`echo "10 k $stdb $pixdim3 / $origin3 + p" | dc -`
stdroi="$stdroi -roi 0 1000000 0 1000000 $stdb 1000000 0 1"
shift 2
elif [ $1 = -lm ] ; then
lm=$2
shift 2
elif [ $1 = -lmt2 ] ; then
lmt2=$2
shift 2
elif [ $1 = -nossm ] ; then
ssm=0
shift
elif [ $1 = -betdir ] ; then
betdir=$2
shift 2
else
echo "Unrecognized parameter: $1"
Usage
fi
done
if [ $regional = 1 ] ; then
if [ $nseg = 2 ] ; then
echo "Can't do regional analysis with 2-class segmentation"
exit
fi
fi
# TODO input validation
mkdir -p $outdir
${FSLDIR}/bin/imcp $Io ${outdir}/I
# copy IN2 if needed
if [ _$IN2 != _ ] ; then
betopts="$betopts -IN2 I2"
${FSLDIR}/bin/imcp $IN2 ${outdir}/I2
fi
if [ _$lm != _ ] ; then
${FSLDIR}/bin/imcp $lm ${outdir}/lesion_mask
lm=lesion_mask
fi
if [ _$betdir != _ ] ; then
${FSLDIR}/bin/imcp ${betdir}/I_brain $outdir
${FSLDIR}/bin/imcp ${betdir}/I_brain_mask $outdir
${FSLDIR}/bin/imcp ${betdir}/I_brain_skull $outdir
if [ _$IN2 != _ ] ; then
${FSLDIR}/bin/imcp ${betdir}/I_brain_tmp_I2_brain $outdir
${FSLDIR}/bin/imcp ${betdir}/I_brain_tmp_I2_brain_mask $outdir
${FSLDIR}/bin/imcp ${betdir}/I_brain_tmp_I2_brain_skull $outdir
cp ${betdir}/I_brain_tmp_I2_to_I.mat $outdir
fi
fi
cd $outdir
I=I # This is dumb. TODO: get rid of it.
echo '<HTML><HEAD><link REL="stylesheet" TYPE="text/css" href="file:'${FSLDIR}'/doc/fsl.css"><TITLE>FSL</TITLE></HEAD><BODY><hr><TABLE BORDER=0 WIDTH="100%"><TR><TD ALIGN=CENTER><H1>SIENAX Report</H1>'${thecommand}'<TD ALIGN=RIGHT><a href="'${FSLDIR}'/doc/index.html"><IMG BORDER=0 SRC="'${FSLDIR}'/doc//images/fsl-logo.jpg"></a></TR></TABLE>' > report.html
echo "-----------------------------------------------------------------------" > report.sienax
echo "" >> report.sienax
echo " SIENA - Structural Image Evaluation, using Normalisation, of Atrophy" >> report.sienax
echo " part of FSL www.fmrib.ox.ac.uk/fsl" >> report.sienax
echo " running cross-sectional atrophy measurement: sienax version 2.6" >> report.sienax
echo " sienax $@" >> report.sienax
echo "" >> report.sienax
echo "---------- extract brain --------------------------------------------" >> report.sienax
if [ _$betdir = _ ] ; then
bet_nw $I ${I}_brain -d -s -m $betopts >> report.sienax
else
echo "Bet completed previously. Copying files from ${betdir} instead of running again." >> report.sienax
fi
if [ _$IN2 != _ ] ; then
${FSLDIR}/bin/immv ${I}_brain_tmp_I2_brain I2_brain
${FSLDIR}/bin/immv ${I}_brain_tmp_I2_brain_mask I2_brain_mask
${FSLDIR}/bin/immv ${I}_brain_tmp_I2_brain_skull I2_brain_skull
${FSLDIR}/bin/fslmaths I2_brain -sub `$FSLDIR/bin/fslstats I2_brain -p 0` -mas I2_brain_mask I2_brain -odt float
${FSLDIR}/bin/overlay 0 0 I2 -a I2_brain 1 `${FSLDIR}/bin/fslstats I2_brain -P 95` I2_brain_skull 0.9 1.1 I2_grot
${FSLDIR}/bin/slicer I2_grot -a I2_bet.png
${FSLDIR}/bin/imrm I2_grot
echo "<hr><p><b>BET secondary input brain extraction results</b><p><IMG BORDER=0 SRC=\"I2_bet.png\">" >> report.html
fi
${FSLDIR}/bin/fslmaths ${I}_brain -sub `$FSLDIR/bin/fslstats ${I}_brain -p 0` -mas ${I}_brain_mask ${I}_brain -odt float
${FSLDIR}/bin/overlay 0 0 $I -a ${I}_brain 1 `${FSLDIR}/bin/fslstats ${I}_brain -P 95` ${I}_brain_skull 0.9 1.1 ${I}_grot
${FSLDIR}/bin/slicer ${I}_grot -a ${I}_bet.png
${FSLDIR}/bin/imrm ${I}_grot
echo "<hr><p><b>BET brain extraction results</b><p><IMG BORDER=0 SRC=\"${I}_bet.png\">" >> report.html
echo "" >> report.sienax
echo "---------- register to standard space using brain and skull --------" >> report.sienax
echo "(do not worry about histogram warnings)" >> report.sienax
${FSLDIR}/bin/pairreg ${FSLDIR}/data/standard/MNI152_T1_2mm_brain ${I}_brain ${FSLDIR}/data/standard/MNI152_T1_2mm_skull ${I}_brain_skull ${I}2std.mat >> report.sienax 2>&1
${FSLDIR}/bin/avscale ${I}2std.mat ${FSLDIR}/data/standard/MNI152_T1_2mm > ${I}2std.avscale
xscale=`grep Scales ${I}2std.avscale | awk '{print $4}'`
yscale=`grep Scales ${I}2std.avscale | awk '{print $5}'`
zscale=`grep Scales ${I}2std.avscale | awk '{print $6}'`
vscale=`echo "10 k $xscale $yscale * $zscale * p"|dc -`
echo "VSCALING $vscale" >> report.sienax
${FSLDIR}/bin/flirt -in $I -ref ${FSLDIR}/data/standard/MNI152_T1_2mm_brain -o ${I}2std -applyxfm -init ${I}2std.mat
${FSLDIR}/bin/slicer ${I}2std ${FSLDIR}/data/standard/MNI152_T1_2mm_brain -a ${I}2std.png
${FSLDIR}/bin/imrm ${I}2std
echo "<hr><p><b>FLIRT standard space registration results</b><p><IMG BORDER=0 SRC=\"${I}2std.png\">" >> report.html
echo "" >> report.sienax
echo "---------- mask with std mask ---------------------------------------" >> report.sienax
if [ $ssm = 1 ] ; then
${FSLDIR}/bin/convert_xfm -inverse -omat ${I}2std_inv.mat ${I}2std.mat
MASK=${FSLDIR}/data/standard/MNI152_T1_2mm_brain_mask_dil
if [ "$stdroi" != "" ] ; then
${FSLDIR}/bin/fslmaths $MASK $stdroi ${I}_stdmaskroi
MASK=${I}_stdmaskroi
fi
${FSLDIR}/bin/flirt -in $MASK -ref ${I}_brain -out ${I}_stdmask -applyxfm -init ${I}2std_inv.mat
${FSLDIR}/bin/fslmaths ${I}_stdmask -thr 0.5 -bin ${I}_stdmask
${FSLDIR}/bin/fslmaths ${I}_brain -mas ${I}_stdmask ${I}_stdmaskbrain
${FSLDIR}/bin/overlay 0 0 -c $I -a ${I}_stdmask 0.9 3 ${I}_brain_mask 0.9 1.1 ${I}_grot
${FSLDIR}/bin/slicer ${I}_grot -a ${I}_masks.png
${FSLDIR}/bin/imrm ${I}_grot
echo "<hr><p><b>Field-of-view and standard space masking</b><br>Red shows the standard-space-based brain mask combined with the field-of-view mask (if used). Blue shows the original BET-derived brain mask. Green shows the intersection of the two.<p><IMG BORDER=0 SRC=\"${I}_masks.png\">" >> report.html
if [ $regional = 1 ] ; then
${FSLDIR}/bin/flirt -in ${FSLDIR}/data/standard/MNI152_T1_2mm_strucseg_periph -ref ${I}_brain -out ${I}_stdmask_segperiph -applyxfm -init ${I}2std_inv.mat
${FSLDIR}/bin/fslmaths ${I}_stdmask_segperiph -thr 0.5 -bin ${I}_stdmask_segperiph
${FSLDIR}/bin/fslmaths ${FSLDIR}/data/standard/MNI152_T1_2mm_strucseg -thr 4.5 -bin ${I}_tmpmask
${FSLDIR}/bin/flirt -in ${I}_tmpmask -ref ${I}_brain -out ${I}_stdmask_segvent -applyxfm -init ${I}2std_inv.mat
${FSLDIR}/bin/fslmaths ${I}_stdmask_segvent -thr 0.5 -bin ${I}_stdmask_segvent
/bin/rm ${I}_tmpmask*
fi
else
echo "This step was skipped because sienax was run with option -nossm" >> report.sienax
${FSLDIR}/bin/imcp ${I}_brain ${I}_stdmaskbrain
fi
echo "" >> report.sienax
echo "---------- segment tissue into types --------------------------------" >> report.sienax
if [ $nseg = 2 ] ; then
${FSLDIR}/bin/fast -g -n 2 $imtype $segopts ${I}_stdmaskbrain >> report.sienax 2>&1
echo "" >> report.sienax
echo "---------- convert brain volume into normalised volume --------------" >> report.sienax
echo "" >> report.sienax
echo " volume unnormalised-volume" >> report.sienax
S=`${FSLDIR}/bin/fslstats ${I}_stdmaskbrain_pve_1 -m -v`
xa=`echo $S | awk '{print $1}'`
xb=`echo $S | awk '{print $3}'`
ubrain=`echo "2 k $xa $xb * 1 / p" | dc -`
nbrain=`echo "2 k $xa $xb * $vscale * 1 / p" | dc -`
else
if [ _$lmt2 != _ ] ; then
${FSLDIR}/bin/flirt -in $lmt2 -ref I -applyxfm -init I_brain_tmp_I2_to_I.mat -out lesion_mask
lm=lesion_mask
fi
if [ _$lm != _ ] ; then
${FSLDIR}/bin/fslmaths $lm -bin -mul -1 -add 1 -mul ${I}_stdmaskbrain ${I}_stdmaskbrain -odt float
fi
${FSLDIR}/bin/fast -g $imtype $segopts ${I}_stdmaskbrain >> report.sienax 2>&1 #TODO -N -p
if [ _$IN2 != _ ] ; then # TODO: check compatibility with lesion mask option
# register I2 brain to I1 space
${FSLDIR}/bin/flirt -in I2_brain -ref I -applyxfm -init I_brain_tmp_I2_to_I.mat -out I2_brain_in_I
if [ _$lm != _ ] ; then
${FSLDIR}/bin/fslmaths $lm -bin -mul -1 -add 1 -mul I2_brain_in_I I2_brain_in_I -odt float
fi
# do multispectral segmentation -- TODO would t2 only be better?
${FSLDIR}/bin/fast -n 2 -S 2 -g --nopve $segopts -o multispec I2_brain_in_I I_stdmaskbrain >> report.sienax 2>&1 #TODO -N -p
# multispectral segmentation results in false nonbrain in pallidum and cerebellum white matter
# fill in cerebellum with -fillh TODO may not be needed after adding pallidum code below
fslmaths multispec_seg_1 -fillh multispec_seg_brain_mask # fills in cerebellum
# pallidum is more complex because it is contiguous with csf so -fillh will not work
# start with T1 white matter mask. Mask this with an eroded standard space brain mask to eliminate dura. Add this to multispectral brain mask.
# generate eroted standard space brain mask
if [ ! -e "I2std_inv.mat" ]; then
${FSLDIR}/bin/convert_xfm -inverse -omat ${I}2std_inv.mat ${I}2std.mat
fi
MASK=${FSLDIR}/data/standard/MNI152_T1_2mm_brain_mask
${FSLDIR}/bin/flirt -in $MASK -ref ${I}_brain -out ${I}_stdmask_ero -applyxfm -init ${I}2std_inv.mat
${FSLDIR}/bin/fslmaths ${I}_stdmask_ero -thr 0.5 -bin ${I}_stdmask_ero
fslmaths I_stdmask_ero -fillh -ero -ero -ero -ero I_stdmask_ero
# continue as explained above
fslmaths I_stdmaskbrain_seg_2 -mas I_stdmask_ero -add multispec_seg_brain_mask multispec_seg_brain_mask
#use mask generated above to trim away nonbrain from T1 segmentation - TODO some of these will not actually be needed
fslmaths I_stdmaskbrain_seg -mas multispec_seg_brain_mask I_stdmaskbrain_seg # composite segmentation
fslmaths I_stdmaskbrain_seg_1 -mas multispec_seg_brain_mask I_stdmaskbrain_seg_1 # gray matter
fslmaths I_stdmaskbrain_pve_1 -mas multispec_seg_brain_mask I_stdmaskbrain_pve_1
fslmaths I_stdmaskbrain_seg_2 -mas multispec_seg_brain_mask I_stdmaskbrain_seg_2 # white matter
fslmaths I_stdmaskbrain_pve_2 -mas multispec_seg_brain_mask I_stdmaskbrain_pve_2
fi
if [ _$lm != _ ] ; then
${FSLDIR}/bin/fslmaths $lm -bin -max ${I}_stdmaskbrain_pve_2 ${I}_stdmaskbrain_pve_2 -odt float
${FSLDIR}/bin/fslmaths $lm -bin -mul 3 -max ${I}_stdmaskbrain_seg ${I}_stdmaskbrain_seg -odt int
fi
echo "" >> report.sienax
echo "---------- convert brain volume into normalised volume --------------" >> report.sienax
echo "" >> report.sienax
echo "tissue volume unnormalised-volume" >> report.sienax
if [ $regional = 1 ] ; then
${FSLDIR}/bin/fslmaths ${I}_stdmaskbrain_pve_1 -mas ${I}_stdmask_segperiph ${I}_stdmaskbrain_pve_1_segperiph -odt float
S=`${FSLDIR}/bin/fslstats ${I}_stdmaskbrain_pve_1_segperiph -m -v`
xa=`echo $S | awk '{print $1}'`
xb=`echo $S | awk '{print $3}'`
uxg=`echo "2 k $xa $xb * 1 / p" | dc -`
xg=`echo "2 k $xa $xb * $vscale * 1 / p" | dc -`
echo "pgrey $xg $uxg (peripheral grey)" >> report.sienax
${FSLDIR}/bin/fslmaths ${I}_stdmaskbrain_pve_0 -mas ${I}_stdmask_segvent ${I}_stdmaskbrain_pve_0_segvent -odt float
S=`${FSLDIR}/bin/fslstats ${I}_stdmaskbrain_pve_0_segvent -m -v`
xa=`echo $S | awk '{print $1}'`
xb=`echo $S | awk '{print $3}'`
uxg=`echo "2 k $xa $xb * 1 / p" | dc -`
xg=`echo "2 k $xa $xb * $vscale * 1 / p" | dc -`
echo "vcsf $xg $uxg (ventricular CSF)" >> report.sienax
fi
S=`${FSLDIR}/bin/fslstats ${I}_stdmaskbrain_pve_1 -m -v`
xa=`echo $S | awk '{print $1}'`
xb=`echo $S | awk '{print $3}'`
ugrey=`echo "2 k $xa $xb * 1 / p" | dc -`
ngrey=`echo "2 k $xa $xb * $vscale * 1 / p" | dc -`
echo "GREY $ngrey $ugrey" >> report.sienax
S=`${FSLDIR}/bin/fslstats ${I}_stdmaskbrain_pve_2 -m -v`
xa=`echo $S | awk '{print $1}'`
xb=`echo $S | awk '{print $3}'`
uwhite=`echo "2 k $xa $xb * 1 / p" | dc -`
nwhite=`echo "2 k $xa $xb * $vscale * 1 / p" | dc -`
echo "WHITE $nwhite $uwhite" >> report.sienax
ubrain=`echo "2 k $uwhite $ugrey + 1 / p" | dc -`
nbrain=`echo "2 k $nwhite $ngrey + 1 / p" | dc -`
fi
echo "BRAIN $nbrain $ubrain" >> report.sienax
# put volumes into a separate text file for easy collection
echo -e "tissue\tvolume(normalized)\tvolume(unnormalized)" >> volumes.txt
echo -e "grey\t$ngrey\t$ugrey" >> volumes.txt
echo -e "white\t$nwhite\t$uwhite" >> volumes.txt
echo -e "brain\t$nbrain\t$ubrain" >> volumes.txt
echo -e "\nvscale\t$vscale" >> volumes.txt
${FSLDIR}/bin/overlay 1 1 -c ${I} -a ${I}_stdmaskbrain_seg 1.9 5 ${I}_render
${FSLDIR}/bin/slicer ${I}_render -s 1 -x 0.4 gr${I}a.png -x 0.5 gr${I}b.png -x 0.6 gr${I}c.png -y 0.4 gr${I}d.png -y 0.5 gr${I}e.png -y 0.6 gr${I}f.png -z 0.4 gr${I}g.png -z 0.5 gr${I}h.png -z 0.6 gr${I}i.png
${FSLDIR}/bin/pngappend gr${I}a.png + gr${I}b.png + gr${I}c.png + gr${I}d.png + gr${I}e.png + gr${I}f.png + gr${I}g.png + gr${I}h.png + gr${I}i.png ${I}_render.png
${FSLDIR}/bin/slicer I2_brain_in_I -s 1 -x 0.4 gr${I}a.png -x 0.5 gr${I}b.png -x 0.6 gr${I}c.png -y 0.4 gr${I}d.png -y 0.5 gr${I}e.png -y 0.6 gr${I}f.png -z 0.4 gr${I}g.png -z 0.5 gr${I}h.png -z 0.6 gr${I}i.png
${FSLDIR}/bin/pngappend gr${I}a.png + gr${I}b.png + gr${I}c.png + gr${I}d.png + gr${I}e.png + gr${I}f.png + gr${I}g.png + gr${I}h.png + gr${I}i.png ${I}_render2.png
${FSLDIR}/bin/slicer ${I} -s 1 -x 0.4 gr${I}a.png -x 0.5 gr${I}b.png -x 0.6 gr${I}c.png -y 0.4 gr${I}d.png -y 0.5 gr${I}e.png -y 0.6 gr${I}f.png -z 0.4 gr${I}g.png -z 0.5 gr${I}h.png -z 0.6 gr${I}i.png
${FSLDIR}/bin/pngappend gr${I}a.png + gr${I}b.png + gr${I}c.png + gr${I}d.png + gr${I}e.png + gr${I}f.png + gr${I}g.png + gr${I}h.png + gr${I}i.png ${I}_render3.png
${FSLDIR}/bin/slicer ${I}_stdmaskbrain_seg -s 1 -x 0.4 gr${I}a.png -x 0.5 gr${I}b.png -x 0.6 gr${I}c.png -y 0.4 gr${I}d.png -y 0.5 gr${I}e.png -y 0.6 gr${I}f.png -z 0.4 gr${I}g.png -z 0.5 gr${I}h.png -z 0.6 gr${I}i.png
${FSLDIR}/bin/pngappend gr${I}a.png + gr${I}b.png + gr${I}c.png + gr${I}d.png + gr${I}e.png + gr${I}f.png + gr${I}g.png + gr${I}h.png + gr${I}i.png ${I}_render4.png
${FSLDIR}/bin/overlay 0 0 $I -a ${I}_brain 1 `${FSLDIR}/bin/fslstats ${I}_brain -P 95` ${I}_brain_skull 0.9 1.1 ${I}_grot
${FSLDIR}/bin/slicer ${I}_grot -s 1 -x 0.4 gr${I}a.png -x 0.5 gr${I}b.png -x 0.6 gr${I}c.png -y 0.4 gr${I}d.png -y 0.5 gr${I}e.png -y 0.6 gr${I}f.png -z 0.4 gr${I}g.png -z 0.5 gr${I}h.png -z 0.6 gr${I}i.png
${FSLDIR}/bin/pngappend gr${I}a.png + gr${I}b.png + gr${I}c.png + gr${I}d.png + gr${I}e.png + gr${I}f.png + gr${I}g.png + gr${I}h.png + gr${I}i.png ${I}_render5.png
/bin/rm ${I}_grot
${FSLDIR}/bin/slicer ${I}_stdmaskbrain_seg_backup -s 1 -x 0.4 gr${I}a.png -x 0.5 gr${I}b.png -x 0.6 gr${I}c.png -y 0.4 gr${I}d.png -y 0.5 gr${I}e.png -y 0.6 gr${I}f.png -z 0.4 gr${I}g.png -z 0.5 gr${I}h.png -z 0.6 gr${I}i.png
${FSLDIR}/bin/pngappend gr${I}a.png + gr${I}b.png + gr${I}c.png + gr${I}d.png + gr${I}e.png + gr${I}f.png + gr${I}g.png + gr${I}h.png + gr${I}i.png ${I}_render6.png
${FSLDIR}/bin/slicer multispec_seg -s 1 -x 0.4 gr${I}a.png -x 0.5 gr${I}b.png -x 0.6 gr${I}c.png -y 0.4 gr${I}d.png -y 0.5 gr${I}e.png -y 0.6 gr${I}f.png -z 0.4 gr${I}g.png -z 0.5 gr${I}h.png -z 0.6 gr${I}i.png
${FSLDIR}/bin/pngappend gr${I}a.png + gr${I}b.png + gr${I}c.png + gr${I}d.png + gr${I}e.png + gr${I}f.png + gr${I}g.png + gr${I}h.png + gr${I}i.png ${I}_render7.png
${FSLDIR}/bin/overlay 1 1 -c I2_brain_in_I -a errormask 0.9 1.1 I_stdmaskbrain_seg_2 0.9 1.1 ${I}_render_error
${FSLDIR}/bin/slicer ${I}_render_error -s 1 -x 0.4 gr${I}a.png -x 0.5 gr${I}b.png -x 0.6 gr${I}c.png -y 0.4 gr${I}d.png -y 0.5 gr${I}e.png -y 0.6 gr${I}f.png -z 0.4 gr${I}g.png -z 0.5 gr${I}h.png -z 0.6 gr${I}i.png
${FSLDIR}/bin/pngappend gr${I}a.png + gr${I}b.png + gr${I}c.png + gr${I}d.png + gr${I}e.png + gr${I}f.png + gr${I}g.png + gr${I}h.png + gr${I}i.png ${I}_render8.png
${FSLDIR}/bin/overlay 1 1 -c I -a $lm 0.9 1.1 I_stdmaskbrain_seg_2 0.9 1.1 ${I}_render_lm
${FSLDIR}/bin/slicer ${I}_render_lm -s 1 -x 0.4 gr${I}a.png -x 0.5 gr${I}b.png -x 0.6 gr${I}c.png -y 0.4 gr${I}d.png -y 0.5 gr${I}e.png -y 0.6 gr${I}f.png -z 0.4 gr${I}g.png -z 0.5 gr${I}h.png -z 0.6 gr${I}i.png
${FSLDIR}/bin/pngappend gr${I}a.png + gr${I}b.png + gr${I}c.png + gr${I}d.png + gr${I}e.png + gr${I}f.png + gr${I}g.png + gr${I}h.png + gr${I}i.png ${I}_render9.png
/bin/rm gr${I}?.???
echo "<hr><p><b>Final SIENAX segmentation results</b><p>Whole-brain segmentation<br><IMG BORDER=0 SRC=\"${I}_render.png\">" >> report.html
echo "<br><IMG BORDER=0 SRC=\"${I}_render2.png\">" >> report.html
echo "<br><IMG BORDER=0 SRC=\"${I}_render3.png\">" >> report.html
echo "<br><IMG BORDER=0 SRC=\"${I}_render4.png\">" >> report.html
echo "<br><IMG BORDER=0 SRC=\"${I}_render5.png\">" >> report.html
echo "<br><IMG BORDER=0 SRC=\"${I}_render6.png\">" >> report.html
echo "<br><IMG BORDER=0 SRC=\"${I}_render7.png\">" >> report.html
echo "<br><IMG BORDER=0 SRC=\"${I}_render8.png\">" >> report.html
echo "<br><IMG BORDER=0 SRC=\"${I}_render9.png\">" >> report.html
if [ $regional = 1 ] ; then
${FSLDIR}/bin/overlay 0 1 -c ${I} -a ${I}_stdmaskbrain_pve_1_segperiph 0.3 0.7 ${I}_periph_render
${FSLDIR}/bin/overlay 0 1 -c ${I} -a ${I}_stdmaskbrain_pve_0_segvent 0.3 0.7 ${I}_vent_render
${FSLDIR}/bin/slicer ${I}_periph_render -s 1 -x 0.4 gr${I}a.png -x 0.5 gr${I}b.png -x 0.6 gr${I}c.png -y 0.4 gr${I}d.png -y 0.5 gr${I}e.png -y 0.6 gr${I}f.png -z 0.4 gr${I}g.png -z 0.5 gr${I}h.png -z 0.6 gr${I}i.png
${FSLDIR}/bin/pngappend gr${I}a.png + gr${I}b.png + gr${I}c.png + gr${I}d.png + gr${I}e.png + gr${I}f.png + gr${I}g.png + gr${I}h.png + gr${I}i.png ${I}_periph_render.png
${FSLDIR}/bin/slicer ${I}_vent_render -s 1 -x 0.4 gr${I}a.png -x 0.5 gr${I}b.png -x 0.6 gr${I}c.png -y 0.4 gr${I}d.png -y 0.5 gr${I}e.png -y 0.6 gr${I}f.png -z 0.4 gr${I}g.png -z 0.5 gr${I}h.png -z 0.6 gr${I}i.png
${FSLDIR}/bin/pngappend gr${I}a.png + gr${I}b.png + gr${I}c.png + gr${I}d.png + gr${I}e.png + gr${I}f.png + gr${I}g.png + gr${I}h.png + gr${I}i.png ${I}_vent_render.png
/bin/rm gr${I}?.???
echo "<p>Peripheral cortex masked segmentation<br><IMG BORDER=0 SRC=\"${I}_periph_render.png\"><p>Ventricle masked segmentation<br><IMG BORDER=0 SRC=\"${I}_vent_render.png\">" >> report.html
fi
if [ $debug = 0 ] ; then
/bin/rm -f `$FSLDIR/bin/imglob -extensions ${I}_brain* ${I}_stdmask*`
/bin/rm -f ${I}2std.avscale ${I}2std_inv.mat
fi
echo "<p>Estimated volumes:<br><pre>" >> report.html
${FSLDIR}/bin/extracttxt unnormalised report.sienax >> report.html
echo "</pre>" >> report.html
echo ""
echo "Finished. The SIENAX report can be viewed by pointing your web browser at:"
echo file:`pwd`/report.html
echo "Estimated normalised brain volume (NBV) ="
echo "$nbrain"
echo ""
cat >> report.html <<EOF
<hr><p><b>SIENAX Methods</b>
<p>Brain tissue volume, normalised for subject head size, was
estimated with SIENAX [Smith 2001, Smith 2002], part of FSL [Smith
2004]. SIENAX starts by extracting brain and skull images from the
single whole-head input data [Smith 2002b]. The brain image is then
affine-registered to MNI152 space [Jenkinson 2001, Jenkinson 2002]
(using the skull image to determine the registration scaling); this is
primarily in order to obtain the volumetric scaling factor, to be used
as a normalisation for head size. Next, tissue-type segmentation with
partial volume estimation is carried out [Zhang 2001] in order to
calculate total volume of brain tissue (including separate estimates
of volumes of grey matter, white matter, peripheral grey matter and
ventricular CSF).
<font size=-1><em>
<P>[Smith 2001] S.M. Smith, N. De Stefano, M. Jenkinson, and P.M. Matthews.
<BR> Normalised accurate measurement of longitudinal brain change.
<BR> Journal of Computer Assisted Tomography, 25(3):466-475, May/June 2001.
<P>[Smith 2002] S.M. Smith, Y. Zhang, M. Jenkinson, J. Chen, P.M. Matthews, A. Federico, and N. De Stefano.
<BR> Accurate, robust and automated longitudinal and cross-sectional brain change analysis.
<BR> NeuroImage, 17(1):479-489, 2002.
<P>[Smith 2004] S.M. Smith, M. Jenkinson, M.W. Woolrich, C.F. Beckmann, T.E.J. Behrens, H. Johansen-Berg, P.R. Bannister, M. De Luca, I. Drobnjak, D.E. Flitney, R. Niazy, J. Saunders, J. Vickers, Y. Zhang, N. De Stefano, J.M. Brady, and P.M. Matthews.
<BR> Advances in functional and structural MR image analysis and
implementation as FSL.
<BR> NeuroImage, 23(S1):208-219, 2004.
<P>[Smith 2002b] S.M. Smith.
<BR> Fast robust automated brain extraction.
<BR> Human Brain Mapping, 17(3):143-155, November 2002.
<P>[Jenkinson 2001] M. Jenkinson and S.M. Smith.
<BR> A global optimisation method for robust affine registration of brain images.
<BR> Medical Image Analysis, 5(2):143-156, June 2001.
<P>[Jenkinson 2002] M. Jenkinson, P.R. Bannister, J.M. Brady, and S.M. Smith.
<BR> Improved optimisation for the robust and accurate linear registration and motion correction of brain images.
<BR> NeuroImage, 17(2):825-841, 2002.
<P>[Zhang 2001] Y. Zhang, M. Brady, and S. Smith.
<BR> Segmentation of brain MR images through a hidden Markov random field model and the expectation maximization algorithm.
<BR> IEEE Trans. on Medical Imaging, 20(1):45-57, 2001.
EOF