3 source `dirname $0`/midp_common.sh
8 # calculate motion amplitudes along the 3 image axes
9 rm /tmp/result.txt 2> /dev/null
10 dir=( "\"left-right\"" "\"anterior-posterior\"" "\"cranio-caudal\"" )
13 if [ $gui_mode = 1 ]; then
14 echo "${pct[$i]}"; echo "# Calculating motion along ${dir[$i]} direction.."
16 echo "Calculating motion along ${dir[$i]} direction.."
19 echo "Motion along ${dir[$i]} direction" >> /tmp/result.txt
20 clitkImageStatistics -i ${vector_file} -m ${roi_mask2} -c $i --verbose 2> /dev/null | tail -n 8 | head -n 6 >> /tmp/result.txt
21 min=`tail -n 2 /tmp/result.txt | head -n 1 | cut -f 2 -d ':'`
22 max=`tail -n 1 /tmp/result.txt | cut -f 2 -d ':'`
23 amp=`echo $max-$min | bc`
25 echo "Amplitude: $amp" >> /tmp/result.txt
26 echo "" >> /tmp/result.txt
32 if echo $* | grep "\-h"; then
33 echo "Usage: calculate_motion_amplitude.sh { VECTOR_FILE RTSTRUCT_REF_IMAGE RTSTRUCT_FILE [ RTSTRUCT_ROI_NUMBER | --gui ] } | --gui "
34 echo " VECTOR_FILE: mhd of the vector field from where to extract motion information (may also be 4D)"
35 echo " RTSTRUCT_REF_IMAGE: mhd of the reference image used in the contour delineation"
36 echo " RTSTRUCT_FILE: dicom with contours"
37 echo " RTSTRUCT_ROI: number of the contour whose motion to analyze"
38 echo " --gui: use GUI to select files"
42 if echo $* | grep "\-\-gui" > /dev/null 2>&1; then
45 vector_file=`zenity --file-selection --title="Select 4D Vector Field file."`
46 rtstruct_ref_image=`zenity --file-selection --title="Select Reference Image."`
47 rtstruct_file=`zenity --file-selection --title="Select RT Struct file."`
55 echo Invalid arguments. Type \'`basename $0` -h\' for help
65 rtstruct_roi_name=$rtstruct_roi
69 echo Invalid arguments. Type \'`basename $0` -h\' for help
74 if ! cat $vector_file | grep -q "Channels = 3"; then
75 echo Vector file must have 3 channels.
79 # create ROI mask from rtstruct
80 roi_mask=roi_${rtstruct_roi}.mhd
81 clitkDicomRTStruct2Image -i ${rtstruct_file} -o ${roi_mask} -j ${rtstruct_ref_image} -r ${rtstruct_roi} 2> /tmp/err.txt
82 if cat /tmp/err.txt | grep -q "No ROI"; then
83 echo Invalid contour number.
87 # guarantees the same sampling for roi mask and vector image
88 roi_mask2=resampled_${roi_mask}
89 clitkResampleImage -i ${roi_mask} -o ${roi_mask2} --like ${vector_file}
91 if [ $gui_mode = 1 ]; then
92 calculate_motion | zenity --progress --auto-close --percentage=0 --text=""
97 if [ $gui_mode = 1 ]; then
98 cat /tmp/result.txt | zenity --text-info --title "Restuls for \"${rtstruct_roi_name}\""
100 echo "Restuls for \"${rtstruct_roi_name}\""
104 rm `basename $roi_mask .mhd`.{mhd,raw}
105 rm `basename $roi_mask2 .mhd`.{mhd,raw}