@@ -54,24 +54,27 @@ Required arguments:
54
54
55
55
Optional arguments:
56
56
57
- -c: Tissue classification A k-means segmentation is run to find gray or white matter around
57
+ -c: Tissue classification A k-means segmentation is run to find gray or white matter around
58
58
the edge of the initial brain mask warped from the template.
59
59
This produces a segmentation image with K classes, ordered by mean
60
60
intensity in increasing order. With this option, you can control
61
- K and tell the script which classes represent CSF, gray and white matter.
61
+ K and tell the script which classes represent CSF, gray and white matter.
62
62
Format (\"KxcsfLabelxgmLabelxwmLabel\")
63
- Examples:
63
+ Examples:
64
64
-c 3x1x2x3 for T1 with K=3, CSF=1, GM=2, WM=3 (default)
65
65
-c 3x3x2x1 for T2 with K=3, CSF=3, GM=2, WM=1
66
66
-c 3x1x3x2 for FLAIR with K=3, CSF=1 GM=3, WM=2
67
67
-c 4x4x2x3 uses K=4, CSF=4, GM=2, WM=3
68
68
69
69
-f: Brain extraction registration mask Mask used for registration to limit the metric computation to
70
70
a specific region.
71
- -s: image file suffix Any of the standard ITK IO formats e.g. nrrd, nii.gz (default), mhd
72
- -u: use random seeding Use random number generated from system clock in Atropos (default = 1)
73
- -k: keep temporary files Keep brain extraction/segmentation warps, etc (default = false).
74
- -q: use floating point precision Use antsRegistration with floating point precision.
71
+ -r: Initial moving transform An ITK affine transform (eg, from antsAI or ITK-SNAP) for the moving image.
72
+ Without this option, this script calls antsAI to search for a good initial moving
73
+ transform.
74
+ -s: Image file suffix Any of the standard ITK IO formats e.g. nrrd, nii.gz (default), mhd
75
+ -u: Use random seeding Use random number generated from system clock in Atropos (default = 1)
76
+ -k: Keep temporary files Keep brain extraction/segmentation warps, etc (default = false).
77
+ -q: Use floating point precision Use antsRegistration with floating point precision.
75
78
76
79
-z: Test / debug mode If > 0, runs a faster version of the script. Only for debugging, results will not be good.
77
80
@@ -201,11 +204,14 @@ N4_BSPLINE_PARAMS="[ 200 ]"
201
204
202
205
USE_FLOAT_PRECISION=0
203
206
207
+ # Intial affine supplied on command line
208
+ USER_INITIAL_AFFINE=" "
209
+
204
210
if [[ $# -lt 3 ]] ; then
205
211
Usage >&2
206
212
exit 1
207
213
else
208
- while getopts " a:c:d:e:f:h:k:m:o:q:s:u:z:" OPT
214
+ while getopts " a:c:d:e:f:h:k:m:o:q:r: s:u:z:" OPT
209
215
do
210
216
case $OPT in
211
217
d) # dimensions
@@ -225,11 +231,11 @@ else
225
231
;;
226
232
c) # k-means segmentation params
227
233
# Check conventional ANTs vector designation (i.e., 'x')
228
- kmeansParamsArr=(${OPTARG// x/ } )
234
+ kmeansParamsArr=(${OPTARG// x/ } )
229
235
if [[ ${# kmeansParamsArr[@]} -ne 4 ]];
230
236
then
231
237
# Check alternative form
232
- kmeansParamsArr=(${OPTARG// ,/ } )
238
+ kmeansParamsArr=(${OPTARG// ,/ } )
233
239
if [[ ${# kmeansParamsArr[@]} -ne 4 ]];
234
240
then
235
241
echo " ERROR: unrecognized kmeans option (-c)."
239
245
ATROPOS_NUM_CLASSES=${kmeansParamsArr[0]}
240
246
ATROPOS_BRAIN_EXTRACTION_INITIALIZATION=" kmeans[ ${ATROPOS_NUM_CLASSES} ]"
241
247
ATROPOS_CSF_CLASS_LABEL=${kmeansParamsArr[1]}
242
- ATROPOS_GM_CLASS_LABEL=${kmeansParamsArr[2]}
248
+ ATROPOS_GM_CLASS_LABEL=${kmeansParamsArr[2]}
243
249
ATROPOS_WM_CLASS_LABEL=${kmeansParamsArr[3]}
244
250
;;
245
251
k) # keep tmp images
259
265
;;
260
266
q)
261
267
USE_FLOAT_PRECISION=$OPTARG
268
+ ;;
269
+ r)
270
+ USER_INITIAL_AFFINE=$OPTARG
262
271
;;
263
272
s) # output suffix
264
273
OUTPUT_SUFFIX=$OPTARG
@@ -292,7 +301,7 @@ if [[ -z "$ATROPOS_SEGMENTATION_MRF" ]];
292
301
fi
293
302
fi
294
303
295
- echo "
304
+ echo "
296
305
Will run Atropos segmentation with K=${ATROPOS_NUM_CLASSES} . Classes labeled in order of mean intensity. Assuming CSF=${ATROPOS_CSF_CLASS_LABEL} , GM=${ATROPOS_GM_CLASS_LABEL} , WM=${ATROPOS_WM_CLASS_LABEL}
297
306
"
298
307
@@ -423,7 +432,7 @@ if [[ ! -f ${EXTRACTION_MASK} || ! -f ${EXTRACTION_WM} ]];
423
432
# # check if output was produced
424
433
if [[ ! -f ${N4_CORRECTED_IMAGES[0]} ]];
425
434
then
426
- echo " Expected output was not produce . The N4 corrected image doesn't exist:"
435
+ echo " Expected output was not produced . The N4 corrected image doesn't exist:"
427
436
echo " ${N4_CORRECTED_IMAGES[0]} "
428
437
exit 1
429
438
fi
@@ -454,29 +463,33 @@ if [[ ! -f ${EXTRACTION_MASK} || ! -f ${EXTRACTION_WM} ]];
454
463
echo
455
464
456
465
# # Step 1 ##
457
- logCmd ${ANTSPATH} /ResampleImageBySpacing ${DIMENSION} ${EXTRACTION_TEMPLATE} ${EXTRACTION_INITIAL_AFFINE_FIXED} 4 4 4 1
458
- logCmd ${ANTSPATH} /ResampleImageBySpacing ${DIMENSION} ${N4_CORRECTED_IMAGES[0]} ${EXTRACTION_INITIAL_AFFINE_MOVING} 4 4 4 1
459
-
460
466
logCmd ${ANTSPATH} /ImageMath ${DIMENSION} ${EXTRACTION_LAPLACIAN} Laplacian ${N4_CORRECTED_IMAGES[0]} 1.5 1
461
467
logCmd ${ANTSPATH} /ImageMath ${DIMENSION} ${EXTRACTION_TEMPLATE_LAPLACIAN} Laplacian ${EXTRACTION_TEMPLATE} 1.5 1
462
468
463
- # exe_initial_align="${ANTSPATH}/antsAffineInitializer ${DIMENSION} ${EXTRACTION_INITIAL_AFFINE_FIXED} ${EXTRACTION_INITIAL_AFFINE_MOVING} ${EXTRACTION_INITIAL_AFFINE} 15 0.1 0 10"
464
- exe_initial_align=" ${ANTSPATH} /antsAI -d ${DIMENSION} -v 1"
465
- exe_initial_align=" ${exe_initial_align} -m Mattes[ ${EXTRACTION_INITIAL_AFFINE_FIXED} ,${EXTRACTION_INITIAL_AFFINE_MOVING} ,32,Regular,0.2 ]"
466
- exe_initial_align=" ${exe_initial_align} -t Affine[ 0.1 ]"
467
- exe_initial_align=" ${exe_initial_align} -s [ 20,0.12 ]"
468
- exe_initial_align=" ${exe_initial_align} -g [ 40,0x40x40 ]"
469
- exe_initial_align=" ${exe_initial_align} -p 0"
470
- exe_initial_align=" ${exe_initial_align} -c 10"
471
- exe_initial_align=" ${exe_initial_align} -o ${EXTRACTION_INITIAL_AFFINE} "
472
-
473
- if [[ -f ${EXTRACTION_REGISTRATION_MASK} ]];
469
+ if [[ ! -f " ${USER_INITIAL_AFFINE} " ]]
474
470
then
475
- # exe_initial_align="${exe_initial_align} ${EXTRACTION_REGISTRATION_MASK}"
476
- exe_initial_align=" ${exe_initial_align} -x ${EXTRACTION_REGISTRATION_MASK} "
477
- fi
478
471
479
- logCmd $exe_initial_align
472
+ logCmd ${ANTSPATH} /ResampleImageBySpacing ${DIMENSION} ${EXTRACTION_TEMPLATE} ${EXTRACTION_INITIAL_AFFINE_FIXED} 4 4 4 1
473
+ logCmd ${ANTSPATH} /ResampleImageBySpacing ${DIMENSION} ${N4_CORRECTED_IMAGES[0]} ${EXTRACTION_INITIAL_AFFINE_MOVING} 4 4 4 1
474
+
475
+ exe_initial_align=" ${ANTSPATH} /antsAI -d ${DIMENSION} -v 1"
476
+ exe_initial_align=" ${exe_initial_align} -m Mattes[ ${EXTRACTION_INITIAL_AFFINE_FIXED} ,${EXTRACTION_INITIAL_AFFINE_MOVING} ,32,Regular,0.2 ]"
477
+ exe_initial_align=" ${exe_initial_align} -t Affine[ 0.1 ]"
478
+ exe_initial_align=" ${exe_initial_align} -s [ 20,0.12 ]"
479
+ exe_initial_align=" ${exe_initial_align} -g [ 40,0x40x40 ]"
480
+ exe_initial_align=" ${exe_initial_align} -p 0"
481
+ exe_initial_align=" ${exe_initial_align} -c 10"
482
+ exe_initial_align=" ${exe_initial_align} -o ${EXTRACTION_INITIAL_AFFINE} "
483
+
484
+ if [[ -f ${EXTRACTION_REGISTRATION_MASK} ]];
485
+ then
486
+ exe_initial_align=" ${exe_initial_align} -x ${EXTRACTION_REGISTRATION_MASK} "
487
+ fi
488
+
489
+ logCmd $exe_initial_align
490
+ else
491
+ ${ANTSPATH} /antsApplyTransforms -d ${DIMENSION} -t ${USER_INITIAL_AFFINE} -o Linear[ ${EXTRACTION_INITIAL_AFFINE} , 0 ]
492
+ fi
480
493
481
494
basecall=" ${ANTS} -d ${DIMENSION} -u 1 -w [ 0.025,0.975 ] -o ${EXTRACTION_WARP_OUTPUT_PREFIX} -r ${EXTRACTION_INITIAL_AFFINE} -z 1 --float ${USE_FLOAT_PRECISION} --verbose 1"
482
495
if [[ -f ${EXTRACTION_REGISTRATION_MASK} ]];
@@ -507,8 +520,8 @@ if [[ ! -f ${EXTRACTION_MASK} || ! -f ${EXTRACTION_WM} ]];
507
520
fi
508
521
509
522
fi
510
-
511
- if [[ ! -f ${EXTRACTION_SEGMENTATION} ]];
523
+
524
+ if [[ ! -f ${EXTRACTION_SEGMENTATION} ]];
512
525
then
513
526
514
527
# # Step 2 ##
@@ -530,8 +543,8 @@ if [[ ! -f ${EXTRACTION_MASK} || ! -f ${EXTRACTION_WM} ]];
530
543
531
544
exe_brain_extraction_3=" ${ATROPOS} -d ${DIMENSION} -o ${EXTRACTION_SEGMENTATION} ${ATROPOS_ANATOMICAL_IMAGES_COMMAND_LINE} -x ${EXTRACTION_MASK} -i ${ATROPOS_BRAIN_EXTRACTION_INITIALIZATION} -c ${ATROPOS_BRAIN_EXTRACTION_CONVERGENCE} -m ${ATROPOS_BRAIN_EXTRACTION_MRF} -k ${ATROPOS_BRAIN_EXTRACTION_LIKELIHOOD} -r ${USE_RANDOM_SEEDING} --verbose 1"
532
545
logCmd $exe_brain_extraction_3
533
- fi
534
-
546
+ fi
547
+
535
548
# Pad image here to avoid errors from dilating into the edge of the image
536
549
padVoxels=10
537
550
@@ -541,7 +554,7 @@ if [[ ! -f ${EXTRACTION_MASK} || ! -f ${EXTRACTION_WM} ]];
541
554
logCmd ${ANTSPATH} /ThresholdImage ${DIMENSION} ${EXTRACTION_SEGMENTATION} ${EXTRACTION_WM} ${ATROPOS_WM_CLASS_LABEL} ${ATROPOS_WM_CLASS_LABEL} 1 0
542
555
logCmd ${ANTSPATH} /ThresholdImage ${DIMENSION} ${EXTRACTION_SEGMENTATION} ${EXTRACTION_GM} ${ATROPOS_GM_CLASS_LABEL} ${ATROPOS_GM_CLASS_LABEL} 1 0
543
556
logCmd ${ANTSPATH} /ThresholdImage ${DIMENSION} ${EXTRACTION_SEGMENTATION} ${EXTRACTION_CSF} ${ATROPOS_CSF_CLASS_LABEL} ${ATROPOS_CSF_CLASS_LABEL} 1 0
544
-
557
+
545
558
logCmd ${ANTSPATH} /ImageMath ${DIMENSION} ${EXTRACTION_WM} GetLargestComponent ${EXTRACTION_WM}
546
559
logCmd ${ANTSPATH} /ImageMath ${DIMENSION} ${EXTRACTION_GM} GetLargestComponent ${EXTRACTION_GM}
547
560
@@ -573,13 +586,13 @@ if [[ ! -f ${EXTRACTION_MASK} || ! -f ${EXTRACTION_WM} ]];
573
586
logCmd ${ANTSPATH} /ImageMath ${DIMENSION} ${img} PadImage ${img} -$padVoxels
574
587
done
575
588
576
-
589
+
577
590
logCmd ${ANTSPATH} /MultiplyImages ${DIMENSION} ${N4_CORRECTED_IMAGES[0]} ${EXTRACTION_MASK} ${EXTRACTION_BRAIN}
578
591
579
592
# Copy header information from original image into output
580
593
logCmd ${ANTSPATH} /CopyImageHeaderInformation ${ANATOMICAL_IMAGES[0]} ${EXTRACTION_BRAIN} ${EXTRACTION_BRAIN} 1 1 1 0
581
594
logCmd ${ANTSPATH} /CopyImageHeaderInformation ${ANATOMICAL_IMAGES[0]} ${EXTRACTION_MASK} ${EXTRACTION_MASK} 1 1 1 0
582
-
595
+
583
596
584
597
if [[ ! -f ${EXTRACTION_MASK} ]];
585
598
then
0 commit comments