-
Notifications
You must be signed in to change notification settings - Fork 1
/
antsCorticalThickness_k9.sh
1352 lines (1131 loc) · 54.7 KB
/
antsCorticalThickness_k9.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
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
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
VERSION="0.0"
# Check dependencies
PROGRAM_DEPENDENCIES=( 'antsRegistration' 'antsApplyTransforms' 'N4BiasFieldCorrection' 'Atropos' 'KellyKapowski' )
SCRIPTS_DEPENDENCIES=( 'antsBrainExtraction.sh' 'antsAtroposN4.sh' )
for D in ${PROGRAM_DEPENDENCIES[@]};
do
if [[ ! -s ${ANTSPATH}/${D} ]];
then
echo "Error: we can't find the $D program."
echo "Perhaps you need to \(re\)define \$ANTSPATH in your environment."
exit
fi
done
for D in ${SCRIPT_DEPENDENCIES[@]};
do
if [[ ! -s ${ANTSPATH}/${D} ]];
then
echo "We can't find the $D script."
echo "Perhaps you need to \(re\)define \$ANTSPATH in your environment."
exit
fi
done
function Usage {
cat <<USAGE
`basename $0` performs T1 anatomical brain processing where the following steps are currently applied:
1. Brain extraction
2. Brain n-tissue segmentation
3. Cortical thickness
4. (Optional) registration to a template
Usage:
`basename $0` -d imageDimension
-a anatomicalImage
-e brainTemplate
-m brainExtractionProbabilityMask
-p brainSegmentationPriors
<OPTARGS>
-o outputPrefix
Example:
bash $0 -d 3 -a t1.nii.gz -e brainWithSkullTemplate.nii.gz -m brainPrior.nii.gz -p segmentationPriors%d.nii.gz -o output
Required arguments:
We use *intensity* to denote the original anatomical image of the brain.
We use *probability* to denote a probability image with values in range 0 to 1.
We use *label* to denote a label image with values in range 0 to N.
-d: Image dimension 2 or 3 (for 2- or 3-dimensional image)
-a: Anatomical image Structural *intensity* image, typically T1. If more than one
anatomical image is specified, subsequently specified
images are used during the segmentation process. However,
only the first image is used in the registration of priors.
Our suggestion would be to specify the T1 as the first image.
-e: Brain template Anatomical *intensity* template (possibly created using a population
data set with buildtemplateparallel.sh in ANTs). This template is
*not* skull-stripped.
-m: Brain extraction probability mask Brain *probability* mask created using e.g. LPBA40 labels which
have brain masks defined, and warped to anatomical template and
averaged resulting in a probability image.
-p: Brain segmentation priors Tissue *probability* priors corresponding to the image specified
with the -e option. Specified using c-style formatting, e.g.
-p labelsPriors%02d.nii.gz. We assume that the first four priors
are ordered as follows
1: csf
2: cortical gm
3: wm
4: deep gm
-o: Output prefix The following images are created:
* ${OUTPUT_PREFIX}BrainExtractionMask.${OUTPUT_SUFFIX}
* ${OUTPUT_PREFIX}BrainSegmentation.${OUTPUT_SUFFIX}
* ${OUTPUT_PREFIX}BrainSegmentation*N4.${OUTPUT_SUFFIX} One for each anatomical input
* ${OUTPUT_PREFIX}BrainSegmentationPosteriors*1.${OUTPUT_SUFFIX} CSF
* ${OUTPUT_PREFIX}BrainSegmentationPosteriors*2.${OUTPUT_SUFFIX} GM
* ${OUTPUT_PREFIX}BrainSegmentationPosteriors*3.${OUTPUT_SUFFIX} WM
* ${OUTPUT_PREFIX}BrainSegmentationPosteriors*4.${OUTPUT_SUFFIX} DEEP GM
* ...
* ${OUTPUT_PREFIX}BrainSegmentationPosteriors*N.${OUTPUT_SUFFIX} where there are N priors
* Number formatting of posteriors matches that of the priors.
* ${OUTPUT_PREFIX}CorticalThickness.${OUTPUT_SUFFIX}
Optional arguments:
-s: image file suffix Any of the standard ITK IO formats e.g. nrrd, nii.gz (default), mhd
-t: template for t1 registration Anatomical *intensity* template (assumed to be skull-stripped). A common
use case would be where this would be the same template as specified in the
-e option which is not skull stripped.
We perform the registration (fixed image = individual subject
and moving image = template) to produce the files.
The output from this step is
* ${OUTPUT_PREFIX}TemplateToSubject0GenericAffine.mat
* ${OUTPUT_PREFIX}TemplateToSubject1Warp.${OUTPUT_SUFFIX}
* ${OUTPUT_PREFIX}TemplateToSubject1InverseWarp.${OUTPUT_SUFFIX}
* ${OUTPUT_PREFIX}TemplateToSubjectLogJacobian.${OUTPUT_SUFFIX}
-f: extraction registration mask Mask (defined in the template space) used during registration
for brain extraction.
-k: keep temporary files Keep brain extraction/segmentation warps, etc (default = 0).
-i: max iterations for registration ANTS registration max iterations (default = 100x100x70x20)
-w: Atropos prior segmentation weight Atropos spatial prior *probability* weight for the segmentation (default = 0.25)
-n: number of segmentation iterations N4 -> Atropos -> N4 iterations during segmentation (default = 3)
-b: posterior formulation Atropos posterior formulation and whether or not to use mixture model proportions.
e.g 'Socrates[1]' (default) or 'Aristotle[1]'. Choose the latter if you
want use the distance priors (see also the -l option for label propagation
control).
-j: use floating-point precision Use floating point precision in registrations (default = 0)
-u: use random seeding Use random number generated from system clock in Atropos (default = 1)
-v: use b-spline smoothing Use B-spline SyN for registrations and B-spline exponential mapping in DiReCT.
-r: cortical label image Cortical ROI labels to use as a prior for ATITH.
-l: label propagation Incorporate a distance prior one the posterior formulation. Should be
of the form 'label[lambda,boundaryProbability]' where label is a value
of 1,2,3,... denoting label ID. The label probability for anything
outside the current label
= boundaryProbability * exp( -lambda * distanceFromBoundary )
Intuitively, smaller lambda values will increase the spatial capture
range of the distance prior. To apply to all label values, simply omit
specifying the label, i.e. -l [lambda,boundaryProbability].
-c Add prior combination to combined gray and white matters. For example,
when calling KK for normal subjects, we combine the deep gray matter
segmentation/posteriors with the white matter segmentation/posteriors.
An additional example would be performing cortical thickness in the presence
of white matter lesions. We can accommodate this by specifying a lesion mask
posterior as an additional posterior (suppose label '7'), and then combine
this with white matter by specifying '-c WM[7]' or '-c 3[7]'.
-q: Use quick registration parameters If = 1, use antsRegistrationSyNQuick.sh as the basis for registration
during brain extraction, brain segmentation, and (optional) normalization
to a template. Otherwise use antsRegistrationSyN.sh (default = 0).
-z: Test / debug mode If > 0, runs a faster version of the script. Only for testing. Implies -u 0.
Requires single thread computation for complete reproducibility.
USAGE
exit 1
}
# Check outputs exist, runs at the end of the script
# List of outputs is taken from the usage
function checkOutputExists() {
singleOutputs=( ${OUTPUT_PREFIX}BrainExtractionMask.${OUTPUT_SUFFIX} ${OUTPUT_PREFIX}BrainSegmentation.${OUTPUT_SUFFIX} ${OUTPUT_PREFIX}CorticalThickness.${OUTPUT_SUFFIX} )
singleOutputs=( ${singleOutputs[@]} ${OUTPUT_PREFIX}BrainSegmentationTiledMosaic.png ${OUTPUT_PREFIX}CorticalThicknessTiledMosaic.png )
if [[ -f ${REGISTRATION_TEMPLATE} ]];
then
singleOutputs=( ${singleOutputs[@]} ${REGISTRATION_TEMPLATE_OUTPUT_PREFIX}0GenericAffine.mat ${REGISTRATION_TEMPLATE_OUTPUT_PREFIX}1Warp.${OUTPUT_SUFFIX} ${REGISTRATION_TEMPLATE_OUTPUT_PREFIX}1InverseWarp.${OUTPUT_SUFFIX} ${REGISTRATION_TEMPLATE_OUTPUT_PREFIX}LogJacobian.${OUTPUT_SUFFIX} )
fi
missingOutput=0
for img in $singleOutputs;
do
if [[ ! -f $img ]];
then
echo "Missing output image $img"
missingOutput=1
fi
done
# Now check numbered output, numbers based on images
for (( i = 0; i < ${#ANATOMICAL_IMAGES[@]}; i++ ))
do
if [[ ! -f ${OUTPUT_PREFIX}BrainSegmentation${i}N4.${OUTPUT_SUFFIX} ]];
then
echo "Missing output image ${OUTPUT_PREFIX}BrainSegmentation${i}N4.${OUTPUT_SUFFIX}"
missingOutput=1
fi
done
# Segmentation output depends on the number of priors and the numbering format
segNumWidth=${#GRAY_MATTER_LABEL_FORMAT}
for (( j = 1; j <= ${NUMBER_OF_PRIOR_IMAGES}; j++ ));
do
num=$(printf "%0${segNumWidth}d" $j)
if [[ ! -f ${OUTPUT_PREFIX}BrainSegmentationPosteriors${num}.${OUTPUT_SUFFIX} ]];
then
echo "Missing output image ${OUTPUT_PREFIX}BrainSegmentationPosteriors${num}.${OUTPUT_SUFFIX}"
missingOutput=1
fi
done
if [[ $missingOutput -gt 0 ]];
then
echo "Some of the output does not exist"
return 1
fi
return 0
}
echoParameters() {
cat <<PARAMETERS
Using antsCorticalThickness with the following arguments:
image dimension = ${DIMENSION}
anatomical image = ${ANATOMICAL_IMAGES[@]}
brain template = ${BRAIN_TEMPLATE}
extraction prior = ${EXTRACTION_PRIOR}
extraction reg. mask = ${EXTRACTION_REGISTRATION_MASK}
segmentation prior = ${SEGMENTATION_PRIOR}
output prefix = ${OUTPUT_PREFIX}
output image suffix = ${OUTPUT_SUFFIX}
registration template = ${REGISTRATION_TEMPLATE}
ANTs parameters:
metric = ${ANTS_METRIC}[fixedImage,movingImage,${ANTS_METRIC_PARAMS}]
regularization = ${ANTS_REGULARIZATION}
transformation = ${ANTS_TRANSFORMATION}
max iterations = ${ANTS_MAX_ITERATIONS}
DiReCT parameters:
convergence = ${DIRECT_CONVERGENCE}
thickness prior = ${DIRECT_THICKNESS_PRIOR}
gradient step size = ${DIRECT_GRAD_STEP_SIZE}
smoothing sigma = ${DIRECT_SMOOTHING_PARAMETER}
Other parameters:
run quick = ${RUN_QUICK}
debug mode = ${DEBUG_MODE}
float precision = ${USE_FLOAT_PRECISION}
use random seeding = ${USE_RANDOM_SEEDING}
prior combinations = ${PRIOR_COMBINATIONS[@]}
PARAMETERS
}
# Echos a command to stdout, then runs it
# Will immediately exit on error unless you set debug flag here
DEBUG_MODE=0
function logCmd() {
cmd="$*"
echo "BEGIN >>>>>>>>>>>>>>>>>>>>"
echo $cmd
$cmd
cmdExit=$?
if [[ $cmdExit -gt 0 ]];
then
echo "ERROR: command exited with nonzero status $cmdExit"
echo "Command: $cmd"
echo
if [[ ! $DEBUG_MODE -gt 0 ]];
then
exit 1
fi
fi
echo "END <<<<<<<<<<<<<<<<<<<<"
echo
echo
return $cmdExit
}
################################################################################
#
# Main routine
#
################################################################################
HOSTNAME=`hostname`
DATE=`date`
CURRENT_DIR=`pwd`/
OUTPUT_DIR=${CURRENT_DIR}/tmp$RANDOM/
OUTPUT_PREFIX=${OUTPUT_DIR}/tmp
OUTPUT_SUFFIX="nii.gz"
KEEP_TMP_IMAGES=0
DIMENSION=3
ANATOMICAL_IMAGES=()
REGISTRATION_TEMPLATE=""
DO_REGISTRATION_TO_TEMPLATE=0
USE_RANDOM_SEEDING=1
RUN_QUICK=0
BRAIN_TEMPLATE=""
EXTRACTION_PRIOR=""
EXTRACTION_REGISTRATION_MASK=""
SEGMENTATION_PRIOR=""
CORTICAL_LABEL_IMAGE=""
CSF_MATTER_LABEL=1
GRAY_MATTER_LABEL=2
WHITE_MATTER_LABEL=3
DEEP_GRAY_MATTER_LABEL=4
ATROPOS_SEGMENTATION_PRIOR_WEIGHT=0.25
################################################################################
#
# Programs and their parameters
#
################################################################################
ANTS=${ANTSPATH}/antsRegistration
ANTS_MAX_ITERATIONS="100x100x70x20"
ANTS_TRANSFORMATION="SyN[0.1,3,0]"
ANTS_LINEAR_METRIC_PARAMS="1,32,Regular,0.25"
ANTS_LINEAR_CONVERGENCE="[1000x500x250x100,1e-8,10]"
ANTS_METRIC="CC"
ANTS_METRIC_PARAMS="1,4"
WARP=${ANTSPATH}/antsApplyTransforms
N4=${ANTSPATH}/N4BiasFieldCorrection
N4_CONVERGENCE_1="[50x50x50x50,0.0000001]"
N4_CONVERGENCE_2="[50x50x50x50,0.0000001]"
N4_SHRINK_FACTOR_1=4
N4_SHRINK_FACTOR_2=2
N4_BSPLINE_PARAMS="[200]"
ATROPOS=${ANTSPATH}/Atropos
ATROPOS_SEGMENTATION_INITIALIZATION="PriorProbabilityImages"
ATROPOS_SEGMENTATION_LIKELIHOOD="Gaussian"
ATROPOS_SEGMENTATION_CONVERGENCE="[5,0.0]"
ATROPOS_SEGMENTATION_POSTERIOR_FORMULATION="Socrates[1]"
ATROPOS_SEGMENTATION_NUMBER_OF_ITERATIONS=3
ATROPOS_SEGMENTATION_LABEL_PROPAGATION=()
DIRECT=${ANTSPATH}/KellyKapowski
DIRECT_CONVERGENCE="[45,0.0,10]"
DIRECT_THICKNESS_PRIOR="10"
DIRECT_GRAD_STEP_SIZE="0.025"
DIRECT_SMOOTHING_PARAMETER="1.5"
DIRECT_NUMBER_OF_DIFF_COMPOSITIONS="10"
PRIOR_COMBINATIONS=( 'WM[4]' )
USE_FLOAT_PRECISION=0
USE_BSPLINE_SMOOTHING=0
if [[ $# -lt 3 ]] ; then
Usage >&2
exit 1
else
while getopts "a:b:c:d:e:f:h:i:j:k:l:m:n:o:p:q:r:s:t:u:v:w:z:" OPT
do
case $OPT in
a) #anatomical t1 image
ANATOMICAL_IMAGES[${#ANATOMICAL_IMAGES[@]}]=$OPTARG
;;
b) # posterior formulation
ATROPOS_SEGMENTATION_POSTERIOR_FORMULATION=$OPTARG
;;
c) # prior combinations
PRIOR_COMBINATIONS[${#PRIOR_COMBINATIONS[@]}]=$OPTARG
;;
d) #dimensions
DIMENSION=$OPTARG
if [[ ${DIMENSION} -gt 3 || ${DIMENSION} -lt 2 ]];
then
echo " Error: ImageDimension must be 2 or 3 "
exit 1
fi
;;
e) #brain extraction anatomical image
BRAIN_TEMPLATE=$OPTARG
;;
f) #brain extraction registration mask
EXTRACTION_REGISTRATION_MASK=$OPTARG
;;
h) #help
Usage >&2
exit 0
;;
i) #max_iterations
ANTS_MAX_ITERATIONS=$OPTARG
;;
j) #use floating point precision
USE_FLOAT_PRECISION=$OPTARG
;;
k) #keep tmp images
KEEP_TMP_IMAGES=$OPTARG
;;
l)
ATROPOS_SEGMENTATION_LABEL_PROPAGATION[${#ATROPOS_SEGMENTATION_LABEL_PROPAGATION[@]}]=$OPTARG
;;
m) #brain extraction prior probability mask
EXTRACTION_PRIOR=$OPTARG
;;
n) #atropos segmentation iterations
ATROPOS_SEGMENTATION_NUMBER_OF_ITERATIONS=$OPTARG
;;
o) #output prefix
OUTPUT_PREFIX=$OPTARG
;;
p) #brain segmentation label prior image
SEGMENTATION_PRIOR=$OPTARG
;;
q) # run quick
RUN_QUICK=$OPTARG
;;
r) #cortical label image
CORTICAL_LABEL_IMAGE=$OPTARG
;;
s) #output suffix
OUTPUT_SUFFIX=$OPTARG
;;
t) #template registration image
REGISTRATION_TEMPLATE=$OPTARG
DO_REGISTRATION_TO_TEMPLATE=1
;;
u) #use random seeding
USE_RANDOM_SEEDING=$OPTARG
;;
v) #use b-spline smoothing in registration and direct
USE_BSPLINE_SMOOTHING=$OPTARG
;;
w) #atropos prior weight
ATROPOS_SEGMENTATION_PRIOR_WEIGHT=$OPTARG
;;
z) #debug mode
DEBUG_MODE=$OPTARG
;;
*) # getopts issues an error message
echo "ERROR: unrecognized option -$OPT $OPTARG"
exit 1
;;
esac
done
fi
if [[ $USE_BSPLINE_SMOOTHING -ne 0 ]];
then
ANTS_TRANSFORMATION="BSplineSyN[0.1,26,0,3]"
DIRECT_SMOOTHING_PARAMETER="5.75"
fi
if [[ $DEBUG_MODE -gt 0 ]];
then
echo " WARNING - Running in test / debug mode. Results will be suboptimal "
OUTPUT_PREFIX="${OUTPUT_PREFIX}testMode_"
# Speed up by doing fewer its. Careful about changing this because
# certain things are hard coded elsewhere, eg number of levels
ANTS_MAX_ITERATIONS="40x40x20x0"
ANTS_LINEAR_CONVERGENCE="[100x100x50x0,1e-8,10]"
ANTS_METRIC_PARAMS="1,2"
# I think this is the number of times we run the whole N4 / Atropos thing, at the cost of about 10 minutes a time
ATROPOS_SEGMENTATION_NUMBER_OF_ITERATIONS=1
DIRECT_CONVERGENCE="[5,0.0,10]"
# Fix random seed to replicate exact results on each run
USE_RANDOM_SEEDING=0
fi
################################################################################
#
# Preliminaries:
# 1. Check existence of inputs
# 2. Figure out output directory and mkdir if necessary
# 3. See if $REGISTRATION_TEMPLATE is the same as $BRAIN_TEMPLATE
#
################################################################################
for (( i = 0; i < ${#ANATOMICAL_IMAGES[@]}; i++ ))
do
if [[ ! -f ${ANATOMICAL_IMAGES[$i]} ]];
then
echo "The specified image \"${ANATOMICAL_IMAGES[$i]}\" does not exist."
exit 1
fi
done
if [[ ! -f ${BRAIN_TEMPLATE} ]];
then
echo "The extraction template doesn't exist:"
echo " $BRAIN_TEMPLATE"
exit 1
fi
if [[ ! -f ${EXTRACTION_PRIOR} ]];
then
echo "The brain extraction prior doesn't exist:"
echo " $EXTRACTION_PRIOR"
exit 1
fi
FORMAT=${SEGMENTATION_PRIOR}
PREFORMAT=${FORMAT%%\%*}
POSTFORMAT=${FORMAT##*d}
FORMAT=${FORMAT#*\%}
FORMAT=${FORMAT%%d*}
REPCHARACTER=''
TOTAL_LENGTH=0
if [ ${#FORMAT} -eq 2 ]
then
REPCHARACTER=${FORMAT:0:1}
TOTAL_LENGTH=${FORMAT:1:1}
fi
# MAXNUMBER=$(( 10 ** $TOTAL_LENGTH ))
MAXNUMBER=1000
PRIOR_IMAGE_FILENAMES=()
WARPED_PRIOR_IMAGE_FILENAMES=()
BRAIN_SEGMENTATION_OUTPUT=${OUTPUT_PREFIX}BrainSegmentation
SEGMENTATION_WARP_OUTPUT_PREFIX=${BRAIN_SEGMENTATION_OUTPUT}Prior
SEGMENTATION_PRIOR_WARPED=${SEGMENTATION_WARP_OUTPUT_PREFIX}Warped
for (( i = 1; i < $MAXNUMBER; i++ ))
do
NUMBER_OF_REPS=$(( $TOTAL_LENGTH - ${#i} ))
ROOT='';
for(( j=0; j < $NUMBER_OF_REPS; j++ ))
do
ROOT=${ROOT}${REPCHARACTER}
done
FILENAME=${PREFORMAT}${ROOT}${i}${POSTFORMAT}
WARPED_FILENAME=${SEGMENTATION_PRIOR_WARPED}${ROOT}${i}.${OUTPUT_SUFFIX}
if [[ -f $FILENAME ]];
then
PRIOR_IMAGE_FILENAMES=( ${PRIOR_IMAGE_FILENAMES[@]} $FILENAME )
WARPED_PRIOR_IMAGE_FILENAMES=( ${WARPED_PRIOR_IMAGE_FILENAMES[@]} $WARPED_FILENAME )
else
break 1
fi
done
NUMBER_OF_REPS=$(( $TOTAL_LENGTH - ${#DEEP_GRAY_MATTER_LABEL} ))
ROOT='';
for(( j=0; j < $NUMBER_OF_REPS; j++ ))
do
ROOT=${ROOT}${REPCHARACTER}
done
DEEP_GRAY_MATTER_LABEL_FORMAT=${ROOT}${DEEP_GRAY_MATTER_LABEL}
NUMBER_OF_REPS=$(( $TOTAL_LENGTH - ${#WHITE_MATTER_LABEL} ))
ROOT='';
for(( j=0; j < $NUMBER_OF_REPS; j++ ))
do
ROOT=${ROOT}${REPCHARACTER}
done
WHITE_MATTER_LABEL_FORMAT=${ROOT}${WHITE_MATTER_LABEL}
NUMBER_OF_REPS=$(( $TOTAL_LENGTH - ${#GRAY_MATTER_LABEL} ))
ROOT='';
for(( j=0; j < $NUMBER_OF_REPS; j++ ))
do
ROOT=${ROOT}${REPCHARACTER}
done
GRAY_MATTER_LABEL_FORMAT=${ROOT}${GRAY_MATTER_LABEL}
NUMBER_OF_REPS=$(( $TOTAL_LENGTH - ${#CSF_MATTER_LABEL} ))
ROOT='';
for(( j=0; j < $NUMBER_OF_REPS; j++ ))
do
ROOT=${ROOT}${REPCHARACTER}
done
CSF_MATTER_LABEL_FORMAT=${ROOT}${CSF_MATTER_LABEL}
SEGMENTATION_PRIOR_WARPED=${SEGMENTATION_PRIOR_WARPED}\%${FORMAT}d.${OUTPUT_SUFFIX}
NUMBER_OF_PRIOR_IMAGES=${#WARPED_PRIOR_IMAGE_FILENAMES[*]}
if [[ ${NUMBER_OF_PRIOR_IMAGES} -lt 4 ]];
then
echo "Expected at least 4 prior images (${NUMBER_OF_PRIOR_IMAGES} are specified). Check the command line specification."
exit 1
fi
for(( j=0; j < $NUMBER_OF_PRIOR_IMAGES; j++ ))
do
if [[ ! -f ${PRIOR_IMAGE_FILENAMES[$j]} ]];
then
echo "Prior image $j ${PRIOR_IMAGE_FILENAMES[$j]} does not exist."
exit 1
fi
done
# These arrays contain the formatted labels that will be used to combine with the white
# and gray matter posteriors for the cortical thickness section.
CORTICAL_THICKNESS_WHITE_MATTER_OTHER_LABELS=()
CORTICAL_THICKNESS_GRAY_MATTER_OTHER_LABELS=()
for(( j=0; j < ${#PRIOR_COMBINATIONS[@]}; j++ ))
do
echo ${PRIOR_COMBINATIONS[$j]}
COMBINATION=( $( echo ${PRIOR_COMBINATIONS[$j]} | tr "[]," "\n" ) )
echo ${COMBINATION[@]}
if [[ ${COMBINATION[0]} == ${WHITE_MATTER_LABEL} || ${COMBINATION[0]} == 'WM' ]];
then
for(( k=1; k < ${#COMBINATION[@]}; k++ ))
do
OTHER_LABEL=${COMBINATION[$k]}
CORTICAL_THICKNESS_WHITE_MATTER_OTHER_LABELS[${#CORTICAL_THICKNESS_WHITE_MATTER_OTHER_LABELS[@]}]=${OTHER_LABEL}
done
elif [[ ${COMBINATION[0]} == ${GRAY_MATTER_LABEL} || ${COMBINATION[0]} == 'GM' ]];
then
for(( k=1; k < ${#COMBINATION[@]}; k++ ))
do
OTHER_LABEL=${COMBINATION[$k]}
CORTICAL_THICKNESS_GRAY_MATTER_OTHER_LABELS[${#CORTICAL_THICKNESS_GRAY_MATTER_OTHER_LABELS[@]}]=${OTHER_LABEL}
done
else
echo "We only combine with the gray matter or the white matter."
echo "The label ${COMBINATION[0]} does not correspond to the gray or white matters."
exit 1
fi
done
CORTICAL_THICKNESS_GRAY_MATTER_OTHER_LABELS_FORMAT=( $( echo "${CORTICAL_THICKNESS_GRAY_MATTER_OTHER_LABELS_FORMAT[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ' ) )
CORTICAL_THICKNESS_WHITE_MATTER_OTHER_LABELS_FORMAT=( $( echo "${CORTICAL_THICKNESS_WHITE_MATTER_OTHER_LABELS_FORMAT[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ' ) )
if [[ $DO_REGISTRATION_TO_TEMPLATE -eq 1 ]];
then
if [[ ! -f ${REGISTRATION_TEMPLATE} ]]
then
echo "Template for registration, ${REGISTRATION_TEMPLATE}, does not exist."
exit 1
fi
fi
OUTPUT_DIR=${OUTPUT_PREFIX%\/*}
if [[ ! -d $OUTPUT_DIR ]];
then
echo "The output directory \"$OUTPUT_DIR\" does not exist. Making it."
mkdir -p $OUTPUT_DIR
fi
echoParameters >&2
echo "--------------------- Running `basename $0` on $HOSTNAME ---------------------"
time_start=`date +%s`
################################################################################
#
# Output images
#
################################################################################
BRAIN_EXTRACTION_MASK=${OUTPUT_PREFIX}BrainExtractionMask.${OUTPUT_SUFFIX}
BRAIN_SEGMENTATION=${OUTPUT_PREFIX}BrainSegmentation.${OUTPUT_SUFFIX}
CORTICAL_THICKNESS_IMAGE=${OUTPUT_PREFIX}CorticalThickness.${OUTPUT_SUFFIX}
################################################################################
#
# Brain extraction
#
################################################################################
# CELS edits
if [[ ! -f ${BRAIN_EXTRACTION_MASK} ]];
then
if [[ -f ${EXTRACTION_REGISTRATION_MASK} ]]
then
logCmd /mnt/starkdata1/head_dog/BIDS/code/antsBrainExtraction_k9.sh \
-d ${DIMENSION} \
-a ${ANATOMICAL_IMAGES[0]} \
-e ${BRAIN_TEMPLATE} \
-f ${EXTRACTION_REGISTRATION_MASK} \
-m ${EXTRACTION_PRIOR} \
-o ${OUTPUT_PREFIX} \
-k ${KEEP_TMP_IMAGES} \
-s ${OUTPUT_SUFFIX} \
-q ${USE_FLOAT_PRECISION} \
-u ${USE_RANDOM_SEEDING} \
-z ${DEBUG_MODE}
else
logCmd /mnt/starkdata1/head_dog/BIDS/code/antsBrainExtraction_k9.sh \
-d ${DIMENSION} \
-a ${ANATOMICAL_IMAGES[0]} \
-e ${BRAIN_TEMPLATE} \
-m ${EXTRACTION_PRIOR} \
-o ${OUTPUT_PREFIX} \
-k ${KEEP_TMP_IMAGES} \
-s ${OUTPUT_SUFFIX} \
-q ${USE_FLOAT_PRECISION} \
-u ${USE_RANDOM_SEEDING} \
-z ${DEBUG_MODE}
fi
fi
EXTRACTED_SEGMENTATION_BRAIN=${OUTPUT_PREFIX}BrainExtractionBrain.${OUTPUT_SUFFIX}
if [[ ! -f ${EXTRACTED_SEGMENTATION_BRAIN} ]];
then
logCmd ${ANTSPATH}/ImageMath ${DIMENSION} ${EXTRACTED_SEGMENTATION_BRAIN} m ${ANATOMICAL_IMAGES[0]} ${BRAIN_EXTRACTION_MASK}
fi
EXTRACTION_GENERIC_AFFINE=${OUTPUT_PREFIX}BrainExtractionPrior0GenericAffine.mat
EXTRACTED_BRAIN_TEMPLATE=${OUTPUT_PREFIX}ExtractedTemplateBrain.${OUTPUT_SUFFIX}
if [[ ! -f ${EXTRACTED_BRAIN_TEMPLATE} ]];
then
logCmd ${ANTSPATH}/ThresholdImage ${DIMENSION} ${EXTRACTION_PRIOR} ${EXTRACTED_BRAIN_TEMPLATE} 0.1 1.01 1 0
logCmd ${ANTSPATH}/ImageMath ${DIMENSION} ${EXTRACTED_BRAIN_TEMPLATE} m ${BRAIN_TEMPLATE} ${EXTRACTED_BRAIN_TEMPLATE}
fi
################################################################################
#
# Brain segmentation
#
################################################################################
SEGMENTATION_WARP=${SEGMENTATION_WARP_OUTPUT_PREFIX}1Warp.nii.gz
SEGMENTATION_INVERSE_WARP=${SEGMENTATION_WARP_OUTPUT_PREFIX}1InverseWarp.nii.gz
SEGMENTATION_GENERIC_AFFINE=${SEGMENTATION_WARP_OUTPUT_PREFIX}0GenericAffine.mat
SEGMENTATION_MASK_DILATED=${BRAIN_SEGMENTATION_OUTPUT}MaskDilated.nii.gz
SEGMENTATION_CONVERGENCE_FILE=${BRAIN_SEGMENTATION_OUTPUT}Convergence.txt
if [[ ! -f ${BRAIN_SEGMENTATION} ]];
then
echo
echo "--------------------------------------------------------------------------------------"
echo " Brain segmentation using the following steps:"
echo " 1) Register ${EXTRACTED_BRAIN_TEMPLATE} and ${SEGMENTATION_PRIOR} to ${ANATOMICAL_IMAGES[0]}"
echo " 2) Warp priors to ${ANATOMICAL_IMAGES[0]}"
echo " 3) N-tissue segmentation using Atropos and N4"
echo "--------------------------------------------------------------------------------------"
echo
# Check inputs
if [[ ! -f ${EXTRACTED_BRAIN_TEMPLATE} ]];
then
echo "The segmentation template doesn't exist:"
echo " ${EXTRACTED_BRAIN_TEMPLATE}"
exit 1
fi
if [[ ! -f ${EXTRACTED_SEGMENTATION_BRAIN} ]];
then
echo "The extracted brain doesn't exist:"
echo " ${EXTRACTED_SEGMENTATION_BRAIN}"
exit 1
fi
time_start_brain_segmentation=`date +%s`
TMP_FILES=()
## Step 1 ##
if [[ ! -f ${SEGMENTATION_WARP} ]];
then
logCmd ${ANTSPATH}/ImageMath ${DIMENSION} ${SEGMENTATION_MASK_DILATED} MD ${BRAIN_EXTRACTION_MASK} 20
basecall=''
if [[ ${RUN_QUICK} -ne 0 ]];
then
TMP_FILES=( ${TMP_FILES[@]} "${SEGMENTATION_WARP_OUTPUT_PREFIX}Warped.nii.gz" )
basecall="${ANTSPATH}/antsRegistrationSyNQuick.sh -d ${DIMENSION} -f ${EXTRACTED_SEGMENTATION_BRAIN}"
basecall="${basecall} -m ${EXTRACTED_BRAIN_TEMPLATE} -o ${SEGMENTATION_WARP_OUTPUT_PREFIX} -j 1"
if [[ ${USE_FLOAT_PRECISION} -ne 0 ]];
then
basecall="${basecall} -p f"
fi
else
basecall="${ANTS} -d ${DIMENSION} -u 1 -w [0.01,0.99] -o ${SEGMENTATION_WARP_OUTPUT_PREFIX} --float ${USE_FLOAT_PRECISION}"
IMAGES="${EXTRACTED_SEGMENTATION_BRAIN},${EXTRACTED_BRAIN_TEMPLATE}"
if [[ -f ${EXTRACTION_GENERIC_AFFINE} ]];
then
basecall="${basecall} -r [${EXTRACTION_GENERIC_AFFINE},1]"
else
basecall="${basecall} -r [${IMAGES},1]"
fi
basecall="${basecall} -x [${SEGMENTATION_MASK_DILATED}]"
stage1="-m MI[${IMAGES},${ANTS_LINEAR_METRIC_PARAMS}] -c ${ANTS_LINEAR_CONVERGENCE} -t Affine[0.1] -f 8x4x2x1 -s 4x2x1x0"
stage2="-m CC[${IMAGES},1,4] -c [${ANTS_MAX_ITERATIONS},1e-9,15] -t ${ANTS_TRANSFORMATION} -f 6x4x2x1 -s 3x2x1x0"
basecall="${basecall} ${stage1} ${stage2}"
fi
exe_brain_segmentation_1=${basecall}
# Precision errors in .nii (which stores things as float) headers can cause problems, so attempt to make everything consistent.
# Won't be perfectly consistent because we don't change ${ANATOMICAL_IMAGES[0]} and CopyImageHeaderInformation does not make
# a perfect copy. But hopefully close enough
for img in ${BRAIN_EXTRACTION_MASK} ${EXTRACTED_SEGMENTATION_BRAIN} ${SEGMENTATION_MASK_DILATED};
do
logCmd ${ANTSPATH}/CopyImageHeaderInformation ${ANATOMICAL_IMAGES[0]} ${img} ${img} 1 1 1
done
logCmd $exe_brain_segmentation_1
fi
## check to see if the output registration transforms exist
if [[ ! -f ${SEGMENTATION_GENERIC_AFFINE} ]];
then
echo "The registration component of the segmentation step didn't complete properly."
echo "The transform file ${SEGMENTATION_GENERIC_AFFINE} does not exist."
exit 1
fi
if [[ ! -f ${SEGMENTATION_WARP} ]];
then
echo "The registration component of the segmentation step didn't complete properly."
echo "The transform file ${SEGMENTATION_WARP} does not exist."
exit 1
fi
## Step 2 ##
for (( i = 0; i < ${NUMBER_OF_PRIOR_IMAGES}; i++ ))
do
if [[ ! -f ${PRIOR_IMAGE_FILENAMES[$i]} ]];
then
echo "The prior image file name does not exist:"
echo " ${PRIOR_IMAGE_FILENAMES[$i]}"
exit 1
fi
exe_brain_segmentation_2="${WARP} -d ${DIMENSION} -i ${PRIOR_IMAGE_FILENAMES[$i]} -o ${WARPED_PRIOR_IMAGE_FILENAMES[$i]} -r ${ANATOMICAL_IMAGES[0]} -n Gaussian -t ${SEGMENTATION_WARP} -t ${SEGMENTATION_GENERIC_AFFINE} --float ${USE_FLOAT_PRECISION}"
logCmd $exe_brain_segmentation_2
done
# We do two stages of antsAtroposN4. The first stage is to get a good N4
# bias corrected image(s). This bias corrected image(s) is used as input to the
# second stage where we only do 2 iterations.
ATROPOS_ANATOMICAL_IMAGES_COMMAND_LINE='';
for (( j = 0; j < ${#ANATOMICAL_IMAGES[@]}; j++ ))
do
ATROPOS_ANATOMICAL_IMAGES_COMMAND_LINE="${ATROPOS_ANATOMICAL_IMAGES_COMMAND_LINE} -a ${ANATOMICAL_IMAGES[$j]}"
done
ATROPOS_LABEL_PROPAGATION_COMMAND_LINE=''
for (( j = 0; j < ${#ATROPOS_SEGMENTATION_LABEL_PROPAGATION[@]}; j++ ))
do
ATROPOS_LABEL_PROPAGATION_COMMAND_LINE="${ATROPOS_LABEL_PROPAGATION_COMMAND_LINE} -l ${ATROPOS_SEGMENTATION_LABEL_PROPAGATION[$j]}";
done
# include everything but the csf
N4_INCLUDE_PRIORS_COMMAND_LINE=''
for (( j = 2; j <= ${NUMBER_OF_PRIOR_IMAGES}; j++ ))
do
N4_INCLUDE_PRIORS_COMMAND_LINE="${N4_INCLUDE_PRIORS_COMMAND_LINE} -y $j";
done
logCmd ${ANTSPATH}/antsAtroposN4.sh \
-d ${DIMENSION} \
-b ${ATROPOS_SEGMENTATION_POSTERIOR_FORMULATION} \
${ATROPOS_ANATOMICAL_IMAGES_COMMAND_LINE} \
${ATROPOS_LABEL_PROPAGATION_COMMAND_LINE} \
-x ${BRAIN_EXTRACTION_MASK} \
-m ${ATROPOS_SEGMENTATION_NUMBER_OF_ITERATIONS} \
-n 5 \
-c ${NUMBER_OF_PRIOR_IMAGES} \
${N4_INCLUDE_PRIORS_COMMAND_LINE} \
-p ${SEGMENTATION_PRIOR_WARPED} \
-w ${ATROPOS_SEGMENTATION_PRIOR_WEIGHT} \
-o ${OUTPUT_PREFIX}Brain \
-u ${USE_RANDOM_SEEDING} \
-k ${KEEP_TMP_IMAGES} \
-s ${OUTPUT_SUFFIX} \
-z ${DEBUG_MODE}
ATROPOS_ANATOMICAL_IMAGES_COMMAND_LINE=''
for (( j = 0; j < ${#ANATOMICAL_IMAGES[@]}; j++ ))
do
ATROPOS_ANATOMICAL_IMAGES_COMMAND_LINE="${ATROPOS_ANATOMICAL_IMAGES_COMMAND_LINE} -a ${OUTPUT_PREFIX}BrainSegmentation${j}N4.${OUTPUT_SUFFIX}";
done
logCmd ${ANTSPATH}/antsAtroposN4.sh \
-d ${DIMENSION} \
-b ${ATROPOS_SEGMENTATION_POSTERIOR_FORMULATION} \
${ATROPOS_ANATOMICAL_IMAGES_COMMAND_LINE} \
${ATROPOS_LABEL_PROPAGATION_COMMAND_LINE} \
-x ${BRAIN_EXTRACTION_MASK} \
-m 2 \
-n 5 \
-c ${NUMBER_OF_PRIOR_IMAGES} \
${N4_INCLUDE_PRIORS_COMMAND_LINE} \
-p ${SEGMENTATION_PRIOR_WARPED} \
-w ${ATROPOS_SEGMENTATION_PRIOR_WEIGHT} \
-o ${OUTPUT_PREFIX}Brain \
-u ${USE_RANDOM_SEEDING} \
-k ${KEEP_TMP_IMAGES} \
-s ${OUTPUT_SUFFIX} \
-z ${DEBUG_MODE}
## Step 3 ###
TMP_FILES=( ${TMP_FILES[@]} $EXTRACTION_GENERIC_AFFINE $EXTRACTED_SEGMENTATION_BRAIN $SEGMENTATION_MASK_DILATED $EXTRACTED_BRAIN_TEMPLATE )
TMP_FILES=( ${TMP_FILES[@]} ${WARPED_PRIOR_IMAGE_FILENAMES[@]} )
if [[ $TEMPLATES_ARE_IDENTICAL -eq 0 ]];
then
TMP_FILES=( ${TMP_FILES[@]} $SEGMENTATION_WARP $SEGMENTATION_INVERSE_WARP $SEGMENTATION_GENERIC_AFFINE )
fi
if [[ $KEEP_TMP_IMAGES -eq 0 ]];
then
for f in ${TMP_FILES[@]}
do
if [[ -e $f ]];
then
logCmd rm $f
else
echo "WARNING: expected temp file doesn't exist: $f"
fi
done
fi
time_end_brain_segmentation=`date +%s`
time_elapsed_brain_segmentation=$((time_end_brain_segmentation - time_start_brain_segmentation))
echo
echo "--------------------------------------------------------------------------------------"
echo " Done with brain segmentation: $(( time_elapsed_brain_segmentation / 3600 ))h $(( time_elapsed_brain_segmentation %3600 / 60 ))m $(( time_elapsed_brain_segmentation % 60 ))s"
echo "--------------------------------------------------------------------------------------"
echo
fi
################################################################################
#
# Registration to a template
#
################################################################################
# These affect output; keep them consistent with usage and checkOutputExists function
REGISTRATION_TEMPLATE_OUTPUT_PREFIX=${OUTPUT_PREFIX}SubjectToTemplate
REGISTRATION_TEMPLATE_GENERIC_AFFINE=${REGISTRATION_TEMPLATE_OUTPUT_PREFIX}0GenericAffine.mat
REGISTRATION_TEMPLATE_WARP=${REGISTRATION_TEMPLATE_OUTPUT_PREFIX}1Warp.${OUTPUT_SUFFIX}
REGISTRATION_TEMPLATE_INVERSE_WARP=${REGISTRATION_TEMPLATE_OUTPUT_PREFIX}1InverseWarp.${OUTPUT_SUFFIX}
REGISTRATION_LOG_JACOBIAN=${REGISTRATION_TEMPLATE_OUTPUT_PREFIX}LogJacobian.${OUTPUT_SUFFIX}
# Want to have transforms for both directions
REGISTRATION_SUBJECT_OUTPUT_PREFIX=${OUTPUT_PREFIX}TemplateToSubject
REGISTRATION_SUBJECT_GENERIC_AFFINE=${REGISTRATION_SUBJECT_OUTPUT_PREFIX}1GenericAffine.mat
REGISTRATION_SUBJECT_WARP=${REGISTRATION_SUBJECT_OUTPUT_PREFIX}0Warp.${OUTPUT_SUFFIX}
if [[ -f ${REGISTRATION_TEMPLATE} ]] && [[ ! -f $REGISTRATION_LOG_JACOBIAN ]];
then
TMP_FILES=()
# Use first N4 corrected segmentation image, which we assume to be T1
HEAD_N4_IMAGE=${OUTPUT_PREFIX}BrainSegmentation0N4.${OUTPUT_SUFFIX}
echo
echo "--------------------------------------------------------------------------------------"
echo " Registration brain masked ${HEAD_N4_IMAGE} to ${REGISTRATION_TEMPLATE} "
echo "--------------------------------------------------------------------------------------"
echo
EXTRACTED_SEGMENTATION_BRAIN_N4_IMAGE=${OUTPUT_PREFIX}ExtractedBrain0N4.nii.gz
logCmd ${ANTSPATH}/ImageMath ${DIMENSION} ${EXTRACTED_SEGMENTATION_BRAIN_N4_IMAGE} m ${HEAD_N4_IMAGE} ${BRAIN_EXTRACTION_MASK}
TMP_FILES=( ${TMP_FILES[@]} ${EXTRACTED_SEGMENTATION_BRAIN_N4_IMAGE} )
time_start_template_registration=`date +%s`
basecall=''
if [[ ${RUN_QUICK} -ne 0 ]];
then
TMP_FILES=( ${TMP_FILES[@]} "${REGISTRATION_TEMPLATE_OUTPUT_PREFIX}Warped.nii.gz" )
basecall="${ANTSPATH}/antsRegistrationSyNQuick.sh -d ${DIMENSION} -f ${REGISTRATION_TEMPLATE}"
basecall="${basecall} -m ${EXTRACTED_SEGMENTATION_BRAIN_N4_IMAGE} -o ${REGISTRATION_TEMPLATE_OUTPUT_PREFIX} -j 1"
if [[ ${USE_FLOAT_PRECISION} -ne 0 ]];
then
basecall="${basecall} -p f"
fi
else
IMAGES="${REGISTRATION_TEMPLATE},${EXTRACTED_SEGMENTATION_BRAIN_N4_IMAGE}"
basecall="${ANTS} -d ${DIMENSION} -u 1 -w [0.01,0.99] -o ${REGISTRATION_TEMPLATE_OUTPUT_PREFIX} -r [${IMAGES},1] --float ${USE_FLOAT_PRECISION}"
stage1="-m MI[${IMAGES},${ANTS_LINEAR_METRIC_PARAMS}] -c ${ANTS_LINEAR_CONVERGENCE} -t Rigid[0.1] -f 8x4x2x1 -s 3x2x1x0"
stage2="-m MI[${IMAGES},${ANTS_LINEAR_METRIC_PARAMS}] -c ${ANTS_LINEAR_CONVERGENCE} -t Affine[0.1] -f 8x4x2x1 -s 3x2x1x0"
stage3="-m CC[${IMAGES},1,4] -c [${ANTS_MAX_ITERATIONS},1e-9,15] -t ${ANTS_TRANSFORMATION} -f 6x4x2x1 -s 3x2x1x0"
basecall="${basecall} ${stage1} ${stage2} ${stage3}"
fi
exe_template_registration_1="${basecall}"
if [[ ! -f ${REGISTRATION_TEMPLATE_WARP} ]];
then
logCmd $exe_template_registration_1