X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=scripts%2Fcreate_midP_masks-2.0.sh;h=eb5983af70ab378ec4b97ae4a887273ce92109cf;hb=72f539dfd51bc89c1002adb705d592878f911167;hp=68560cae1c76750fbe9319f95dc224d53c5fa6eb;hpb=66d21002b1ea9e439731fa624836705f8bc34847;p=clitk.git diff --git a/scripts/create_midP_masks-2.0.sh b/scripts/create_midP_masks-2.0.sh index 68560ca..eb5983a 100755 --- a/scripts/create_midP_masks-2.0.sh +++ b/scripts/create_midP_masks-2.0.sh @@ -1,5 +1,5 @@ -#! /bin/bash -x - +#! /bin/bash + ############################################################################### # # FILE: create_midP-2.0.sh @@ -21,7 +21,10 @@ extract_patient() { echo "$phase_file -> Extracting patient..." clitkExtractPatient -i $phase_file -o $mask_dir_tmp/patient_mask_$phase_nb.mhd --noAutoCrop -a $afdb_file $ExtractPatientExtra +# abort_on_error clitkExtractPatient $? + clitkSetBackground -i $phase_file -o $mask_dir_tmp/patient_$phase_nb.mhd --mask $mask_dir_tmp/patient_mask_$phase_nb.mhd --outsideValue -1000 +# abort_on_error clitkSetBackground $? } extract_bones() @@ -39,15 +42,17 @@ extract_bones() extract_lungs() { - echo "$phase_file -> Extracting lungs..." - clitkExtractLung -i $phase_file -o $mask_dir_tmp/lungs_$phase_nb.mhd -a $afdb_file --noAutoCrop + echo "$phase_file -> Extracting lungs..." + clitkExtractLung -i $phase_file -o $mask_dir_tmp/lungs_$phase_nb.mhd -a $afdb_file --noAutoCrop --doNotSeparateLungs --type 1 } + + resample() { echo "$phase_file -> Resampling..." clitkResampleImage -i $mask_dir_tmp/patient_$phase_nb.mhd -o $mask_dir_tmp/patient_$phase_nb.mhd --spacing $resample_spacing --interp $resample_algo - + clitkResampleImage -i $mask_dir_tmp/patient_mask_$phase_nb.mhd -o $mask_dir_tmp/patient_mask_$phase_nb.mhd --spacing $resample_spacing --interp $resample_algo clitkResampleImage -i $mask_dir_tmp/lungs_$phase_nb.mhd -o $mask_dir_tmp/lungs_$phase_nb.mhd --like $mask_dir_tmp/patient_$phase_nb.mhd } @@ -60,7 +65,7 @@ compute_motion_mask() FillingLevel=94 fi - clitkMotionMask -i $mask_dir_tmp/patient_$phase_nb.mhd -o $mask_dir_tmp/mm_$phase_nb.mhd --featureLungs $mask_dir_tmp/lungs_$phase_nb.mhd --upperThresholdLungs -400 --fillingLevel $FillingLevel --offsetDetect 0,-5,0 --pad --writeFeature=$mask_dir_tmp/feature_$phase_nb.mhd $MotionMaskExtra + clitkMotionMask -i $mask_dir_tmp/patient_$phase_nb.mhd -o $mask_dir_tmp/mm_$phase_nb.mhd --featureLungs $mask_dir_tmp/lungs_$phase_nb.mhd --upperThresholdLungs -400 --fillingLevel $FillingLevel --offsetDetect $MotionMaskOffsetDetect --pad --writeFeature=$mask_dir_tmp/feature_$phase_nb.mhd $MotionMaskExtra #--monitor=$mask_dir_tmp/monitor_$phase_nb.mhd } @@ -126,7 +131,9 @@ mm_preprocessing() # extract_bones extract_lungs # remove_tmp_masks 1 - resample + if [ $resample_spacing -ne 0 ] ; then + resample + fi } mm_postprocessing() @@ -139,18 +146,29 @@ mm_postprocessing() motion_mask() { #set cmd line variables - mhd4d=$1 - resample_spacing=$2 - resample_algo=$3 - - # import variables specific to each patient - source variables + mhd4d=`basename $1` + if [ $# -eq 3 ] ; then + resample_spacing=$2 + resample_algo=$3 + else + resample_spacing=0 + resample_algo=0 + fi dir=`dirname $1` cd $dir + # import variables specific to each patient + if test -e ./variables; then + source ./variables + fi + #set other global variables - mask_dir="MASK-${resample_spacing}mm-$resample_algo" + if [ $resample_spacing -ne 0 ] ; then + mask_dir="MASK-${resample_spacing}mm-$resample_algo" + else + mask_dir="MASK" + fi mask_dir_tmp="tmp.$mask_dir" extract_4d_phases $mhd4d @@ -196,6 +214,7 @@ motion_mask() mkdir -p $mask_log_dir # multi-threaded pre-processing for motion mask calcs + pids=( ) for i in $( seq 0 $((${#phase_nbs[@]} - 1))); do phase_nb=${phase_nbs[$i]} phase_file=${phase_files[$i]} @@ -203,6 +222,12 @@ motion_mask() check_threads $MAX_THREADS mm_preprocessing & + pids=( "${pids[@]}" "$!" ) + done + + wait_pids ${pids[@]} + for ret in $ret_codes; do + abort_on_error mm_preprocessing $ret clean_up_masks done # single-threaded motion mask calc @@ -213,17 +238,26 @@ motion_mask() check_threads 1 echo "$phase_file -> Computing motion mask..." compute_motion_mask > $mask_log_dir/motion_mask_$phase_file.log + abort_on_error compute_motion_mask $? clean_up_masks done # multi-threaded post-processing of motion mask calcs + pids=( ) for i in $( seq 0 $((${#phase_nbs[@]} - 1))); do phase_nb=${phase_nbs[$i]} phase_file=${phase_files[$i]} check_threads $MAX_THREADS mm_postprocessing & + pids=( "${pids[@]}" "$!" ) + done + + wait_pids ${pids[@]} + for ret in $ret_codes; do + abort_on_error mm_postprocessing $ret clean_up_masks done + # rename tmp mask directory after mask creation check_threads 1 mv -f $mask_dir_tmp $mask_dir @@ -242,8 +276,8 @@ motion_mask() # main # ################# -if [ $# != 3 ]; then - echo "Usage: $0 CT_4D RESAMPLE_SPACING RESAMPLE_ALGORITHM" +if [ $# -ne 3 -a $# -ne 1 ]; then + echo "Usage: $0 CT_4D [RESAMPLE_SPACING RESAMPLE_ALGORITHM]" exit -1 fi @@ -254,5 +288,9 @@ fi # if [ $1 != "using-as-lib" ]; then - motion_mask $1 $2 $3 + if [ $# -eq 3 ] ; then + motion_mask $1 $2 $3 + else + motion_mask $1 + fi fi