5 if echo $* | grep "\-h"; then
6 echo Usage: calculate_motion_amplitude.sh VECTOR_FILE RTSTRUCT_FILE RTSTRUCT_ROI_NUMBER RTSTRUCT_REF_IMAGE
7 echo " VECTOR_FILE: mhd of the vector field from where to extract motion information (may also be 4D)"
8 echo " RTSTRUCT_FILE: dicom with contours"
9 echo " RTSTRUCT_ROI: number of the contour whose motion to analyze"
10 echo " RTSTRUCT_REF_IMAGE: mhd of the reference image used in the contour delineation"
16 echo Invalid arguments. Type \'`basename $0` -h\' for help
25 if ! cat $vector_file | grep -q "Channels = 3"; then
26 echo Vector file must have 3 channels.
30 # create ROI mask from rtstruct
31 roi_mask=roi_${rtstruct_roi}.mhd
32 clitkDicomRTStruct2BinaryImage -i ${rtstruct_file} -o ${roi_mask} -j ${rtstruct_ref_image} -r ${rtstruct_roi} 2> /tmp/err.txt
33 if cat /tmp/err.txt | grep -q "No ROI"; then
34 echo Invalid contour number.
38 # guarantees the same sampling for roi mask and vector image
39 roi_mask2=resampled_${roi_mask}
40 clitkResampleImage -i ${roi_mask} -o ${roi_mask2} --like ${vector_file}
42 # calculate motion amplitudes along the 3 image axes
43 dir=( sagittal coronal axial )
45 echo Motion along ${dir[$i]} direction
46 clitkImageStatistics -i ${vector_file} -m ${roi_mask2} -c $i --verbose 2> /dev/null | tail -n 8 | head -n 6 > /tmp/res.txt
47 min=`tail -n 2 /tmp/res.txt | head -n 1 | cut -f 2 -d ':'`
48 max=`tail -n 1 /tmp/res.txt | cut -f 2 -d ':'`
49 amp=`echo $max-$min | bc`
51 echo "Amplitude: $amp"
55 rm `basename $roi_mask .mhd`.{mhd,raw}
56 rm `basename $roi_mask2 .mhd`.{mhd,raw}