forked from ANTsX/ANTs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathantsaffine.sh
executable file
·85 lines (67 loc) · 1.99 KB
/
antsaffine.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
#!/bin/bash
if [[ -z ${ANTSPATH} ]] ; then
echo "Environment variable ANTSPATH must be defined"
exit 1
fi
if [[ ! -f "${ANTSPATH}/ANTS" ]] ; then
echo "Cannot find the ANTS program. Please \(re\)define \$ANTSPATH in your environment."
exit 1
fi
NUMPARAMS=$#
if [ $NUMPARAMS -lt 3 ]
then
echo " USAGE :: "
echo " sh antsaffine.sh ImageDimension fixed.ext moving.ext OPTIONAL-OUTPREFIX PURELY-RIGID "
echo " be sure to set ANTSPATH environment variable "
echo " affine only registration "
exit
fi
#ANTSPATH=YOURANTSPATH
if [ ${#ANTSPATH} -le 0 ]
then
echo " Please set ANTSPATH=LocationOfYourAntsBinaries "
echo " Either set this in your profile or directly, here in the script. "
echo " For example : "
echo $ANTSPATH
echo " ANTSPATH=/home/yourname/bin/ants/ "
exit
else
echo " ANTSPATH is $ANTSPATH "
fi
#initialization, here, is unbiased
DIM=$1
if [ ${#DIM} -gt 1 ]
then
echo " Problem with specified ImageDimension => User Specified Value = $DIM "
exit
fi
FIXED=$2
if [ ${#FIXED} -lt 1 -o ! -f $FIXED ]
then
echo " Problem with specified Fixed Image => User Specified Value = $FIXED "
exit
fi
MOVING=$3
if [ ${#MOVING} -lt 1 -o ! -f $MOVING ]
then
echo " Problem with specified Moving Image => User Specified Value = $MOVING "
exit
fi
OUTPUTNAME=` echo $MOVING | cut -d '.' -f 1 `
if [ $NUMPARAMS -gt 3 ]
then
OUTPUTNAME=${4}
fi
RIGID=" --rigid-affine false "
if [ $NUMPARAMS -gt 4 ]
then
RIGID=" --rigid-affine true --affine-gradient-descent-option 0.5x0.95x1.e-4x1.e-4 "
fi
echo " Will this mapping be purely rigid? $RIGID "
echo " ANTSPATH is $ANTSPATH "
#below, some affine options
#--MI-option 16x8000 #-a InitAffine.txt --continue-affine 0
exe=" ${ANTSPATH}/ANTS $DIM -m MI[ ${FIXED},${MOVING},1,32 ] -o ${OUTPUTNAME} -i 0 --use-Histogram-Matching --number-of-affine-iterations 10000x10000x10000x10000x10000 $RIGID "
echo " $exe "
$exe
${ANTSPATH}/WarpImageMultiTransform $DIM $MOVING ${OUTPUTNAME}deformed.nii.gz ${OUTPUTNAME}Affine.txt -R ${FIXED}