]> Creatis software - clitk.git/blob - scripts/calculate_contour_stats.sh
using get_dicom_field_value in midp scripts
[clitk.git] / scripts / calculate_contour_stats.sh
1 #! /bin/bash +x 
2
3 source `dirname $0`/midp_common.sh
4
5
6 ############# main 
7
8 if echo $* | grep "\-h"; then
9   echo Usage: calculate_motion_amplitude.sh { REFERENCE_IMAGE RTSTRUCT_FILE [ RTSTRUCT_ROI | --gui ] } | --gui 
10   echo "  RTSTRUCT_REF_IMAGE: mhd of the reference image used in the contour delineation"
11   echo "  RTSTRUCT_FILE: dicom with contours"
12   echo "  RTSTRUCT_ROI: number of the contour whose motion to analyze"
13   echo "  --gui: use GUI to select files"
14   exit 0
15 fi
16
17
18 rtstruct_roi=
19
20 if echo $* | grep "\-\-gui" > /dev/null 2>&1; then
21   gui_mode=1
22   if [ $# = 1 ]; then
23     rtstruct_ref_image=`zenity --file-selection --title="Select Reference Image."`
24     rtstruct_file=`zenity --file-selection --title="Select RT Struct file."`
25     select_roi
26   elif [ $# = 3 ]; then
27     rtstruct_ref_image=$1
28     rtstruct_file=$2
29     select_roi
30   else
31     echo Invalid arguments. Type \'`basename $0` -h\' for help
32     exit -1
33   fi
34
35 else
36   gui_mode=0
37   rtstruct_ref_image=$1
38   rtstruct_file=$2
39   if [ $# = 2 ]; then
40     select_roi
41   elif [ $# = 3 ]; then
42     rtstruct_roi=$3
43     rtstruct_roi_name=$rtstruct_roi
44   else
45     echo Invalid arguments. Type \'`basename $0` -h\' for help
46     exit -1
47   fi
48
49 fi
50
51
52 #echo "Processing \"${rtstruct_roi_list[$roi_struct]}\"..."
53 # create ROI mask from rtstruct
54 roi_mask=roi_${rtstruct_roi_name}.mhd
55 clitkDicomRTStruct2Image -i ${rtstruct_file} -o ${roi_mask} -j ${rtstruct_ref_image} -r ${rtstruct_roi} 2> /tmp/err.txt
56 if cat /tmp/err.txt | grep -q "No ROI"; then
57   echo Invalid contour number.
58   exit -3
59 fi
60
61 # guarantees the same sampling for roi mask and vector image
62 roi_mask2=resampled_${roi_mask}
63 clitkResampleImage -i ${roi_mask} -o ${roi_mask2} --like ${rtstruct_ref_image}
64
65 # calculate stats
66 clitkImageStatistics -i ${rtstruct_ref_image} -m ${roi_mask2} --verbose 2> /dev/null | tail -n 8 > /tmp/result.txt
67
68 if [ $gui_mode = 1 ]; then
69   cat /tmp/result.txt | zenity --text-info --title "Restuls for \"${rtstruct_roi_name}\""
70 else
71   echo "Restuls for \"${rtstruct_roi_name}\""
72   cat /tmp/result.txt 
73 fi
74
75 rm `basename $roi_mask .mhd`.{mhd,raw}
76 rm `basename $roi_mask2 .mhd`.{mhd,raw}
77 rm /tmp/err.txt
78 rm /tmp/result.txt