3 ###############################################################################
5 # FILE: registration.sh
6 # AUTHOR: RĂ´mulo Pinho 05/08/2011
8 # Helper file with registration functions using different methods.
9 # Each function receives a set of parameters that overall apply to any
10 # registration algorithm, as follows:
12 # reference=$1 : reference (fixed) image
13 # target=$2 : target (moving) image
14 # mask_ref=$3 : mask for the reference image
15 # mask_targ=$4 : mask for the moving image
16 # vf=$5 : output vector field representing the registration
17 # result=$6 : result image after applying the vector field
18 # nb_iter=$7 : maximum number of iterations
19 # nb_samples=$8 : number of image samples used in the metric calulcation
20 # sampling_algo=$9 : algorithm used in the selection of image samples
21 # hist_bins=${10} : number of histogram bins used in the metric calculation
22 # nb_levels=${11} : number of image resolutions
23 # spacing=${12} : spacing of the b-spline grid of the fines resolution
24 # metric=${13} : metric algorithm
25 # optimizer=${14} : optimizer
26 # interpolator=${15} : image interpolator
27 # log=${16} : log file
29 # New registration functions may be added to this file at any moment,
30 # respecting the interface defined above.
32 ###############################################################################
34 source `dirname $0`/midp_common.sh
37 ################# BLUTDIR #####################
38 registration_blutdir()
48 local sampling_algo=$9
54 local interpolator=${15}
57 local init_coeff=${18}
59 echo "Computing BLUTDIR $reference -> $target ..."
60 blutdir_params="--levels $nb_levels --metric $metric --optimizer $optimizer --samples $nb_samples --spacing $spacing,$spacing,$spacing --bins $hist_bins --maxIt $nb_iter --interp $interpolator --centre --verbose"
62 if [ -n "$coeff" ]; then
63 coeff="--coeff $coeff"
66 if [ -n "$init_coeff" ]; then
67 init_coeff="--initCoeff $init_coeff"
70 cmd="clitkBLUTDIR -r $reference -t $target -m $mask_ref --targetMask $mask_targ --vf $vf $coeff $init_coeff -o $result $blutdir_params"
73 abort_on_error registration_blutdir $? clean_up_registration
76 ################# ELASTIX #####################
77 registration_elastix()
95 ########## register in ##########
96 for reg_in in $reg_in_list
98 if [ ! -z `echo $reg_in | grep "_$phase"` ]
103 echo "Computing ELASTIX $reference -> $target ..."
104 exec_dir=`which elastix`
105 exec_dir=`dirname $exec_dir`
106 suffix=${nb_samples}_${nb_iter}_${nb_levels}
107 cat $exec_dir/params_BSpline.txt | sed -e "s+<NbIterations>+$nb_iter+" \
108 -e "s+<LabelsFile>++" \
109 -e "s+<HistBins>+$hist_bins+" \
110 -e "s+<Levels>+$nb_levels+" \
111 -e "s+<NbSamples>+$nb_samples+" \
112 -e "s+<SamplerType>+$sampling_algo+" \
113 -e "s+<Spacing>+$spacing+" > params_BSpline_${suffix}.txt
116 vf_base=`basename $vf .mhd`
117 result_dir=`dirname $result`
118 result_base=`basename $result .mhd`
121 cmd="elastix -f $reference -m $target -fMask $mask_ref -mMask $mask_targ -out $result_dir -p params_BSpline_${suffix}.txt"
123 abort_on_error registration_elastix $? clean_up_registration
125 # generate vector field
126 cmd="transformix -tp $result_dir/TransformParameters.0.txt -out $vf_dir -def all"
128 abort_on_error registration_elastix $? clean_up_registration
131 mv $vf_dir/deformationField.mhd $vf
132 mv $vf_dir/deformationField.raw `echo $vf | sed 's/mhd/raw/'`
133 sed -i "s+deformationField+$vf_base+" $vf
135 mv $result_dir/result.0.mhd $result
136 mv $result_dir/result.0.raw `echo $result | sed 's/mhd/raw/'`
137 sed -i "s+result.0+$result_base+" $result
139 mv $result_dir/elasitx.log $log
140 mv $result_dir/TransformParameters.0.txt $result_dir/${result_base}_TransformParameters.0.txt