From 14ff5532bdc12aef0e710b204453199e6fb8402c Mon Sep 17 00:00:00 2001 From: Romulo Pinho Date: Thu, 8 Mar 2012 11:38:54 +0100 Subject: [PATCH] midp scripts with mask_type option - either mm, lungs, or patient for the moment --- scripts/create_midP-2.0.sh | 107 ++++++++++++++---- scripts/create_midP_masks-2.0.sh | 181 +++++++++++++++++++++++-------- scripts/midp_common.sh | 22 ++-- scripts/midp_template.conf | 9 ++ 4 files changed, 241 insertions(+), 78 deletions(-) diff --git a/scripts/create_midP-2.0.sh b/scripts/create_midP-2.0.sh index 7af8b09..8830a1b 100755 --- a/scripts/create_midP-2.0.sh +++ b/scripts/create_midP-2.0.sh @@ -19,7 +19,7 @@ ######################### includes -source `dirname $0`/create_midP_masks-2.0.sh using-as-lib 2 nn +source `dirname $0`/create_midP_masks-2.0.sh using-as-lib source `dirname $0`/registration.sh source `dirname $0`/midp_common.sh @@ -85,7 +85,7 @@ registration() registration_elastix $reference_out $target_out $mask_ref_out $mask_targ_out $vf_out $result_out $params $log_out fi - motion_mask=$mask_dir/mm_$phase_nb.mhd + motion_mask=$mask_dir/${mask_type}_$phase_nb.mhd # combine in and out results out_result=$output_dir/result_${ref_phase_nb}_$phase_nb.mhd @@ -122,7 +122,7 @@ registration() clitkZeroVF -i $vf_ref -o $vf_out abort_on_error registration $? clean_up_registration - motion_mask=$mask_dir/mm_${ref_phase_nb}.mhd + motion_mask=$mask_dir/${mask_type}_${ref_phase_nb}.mhd reference_in=$mask_dir/${banded}inside_${ref_phase_nb}.mhd reference_out=$mask_dir/${banded}outside_$ref_phase_nb.mhd out_result=$output_dir/result_${ref_phase_nb}_${ref_phase_nb}.mhd @@ -152,6 +152,77 @@ registration() echo } +registration_no_motion_mask() +{ + echo + echo "----------- Registration Without Motion Masks ------------" + start=`date` + echo "start: $start" + echo + + mkdir -p $vf_dir + mkdir -p $output_dir + + # banded images may be created as separate files, + # with the specified preffix, which is interesting for debugging. + # if blank, it means that the original images (those without bands) + # will be used (see create_midP_masks-2.0.sh for details). + banded="" + + # params read from conf file + use_coeffs=1 + params="$nb_iter $nb_samples $sampling_algo $nb_hist_bins $nb_levels $bspline_spacing $metric $optimizer $interpolator" + + # register all phases to the reference + for i in $( seq 0 $((${#phase_files[@]} - 1))); do + phase_file=${phase_files[$i]} + phase_nb=${phase_nbs[$i]} + + if [ "$phase_nb" != "$ref_phase_nb" ]; then + # params + reference=$mask_dir/patient_$ref_phase_nb.mhd + target=$mask_dir/patient_$phase_nb.mhd + mask_ref=$mask_dir/patient_mask_$ref_phase_nb.mhd + mask_targ=$mask_dir/patient_mask_$phase_nb.mhd + vf=$vf_dir/vf_${ref_phase_nb}_$phase_nb.mhd + result=$output_dir/result_${ref_phase_nb}_$phase_nb.mhd + log=$log_dir/log_${ref_phase_nb}_$phase_nb.log + if [ $use_coeffs = 1 ]; then + init_coeff=$coeff_in # empty at first iteration + coeff=$vf_dir/coeff_${ref_phase_nb}_$phase_nb.mhd + fi + + # registration + if [ "$method" == "blutdir" ]; then + registration_blutdir $reference $target $mask_ref $mask_targ $vf $result $params $log $coeff + elif [ "$method" == "elastix" ]; then + registration_elastix $reference $target $mask_ref $mask_targ $vf $result $params $log + fi + + # save for later... + vf_ref=$vf + fi + done + + clitkZeroVF -i $vf_ref -o $vf_dir/vf_${ref_phase_nb}_${ref_phase_nb}.mhd + + # create 4D vf + create_mhd_4D_pattern.sh $vf_dir/vf_${ref_phase_nb}_ + + # create 4D coeffs + create_mhd_4D_pattern.sh $vf_dir/coeff_${ref_phase_nb}_ _0 + + # create 4D result image + create_mhd_4D_pattern.sh $output_dir/result_${ref_phase_nb}_ + + echo + echo "-------- Registration done ! --------" + end=`date` + echo "start: $start" + echo "end: $end" + echo +} + midp() { echo @@ -250,20 +321,14 @@ midp_in_out() coeff_midp_in=$midp_dir/coeff_inside_midp_$phase_nb.mhd coeff_midp_out=$midp_dir/coeff_outside_midp_$phase_nb.mhd # average the vf's from reference phase to phase - # clitkAverageTemporalDimension -i $vf_dir/vf_inside_${ref_phase_nb}_4D.mhd -o $vf_midp_in - #clitkAverageTemporalDimension -i $vf_dir/coeff_inside_${ref_phase_nb}_4D_0.mhd -o $coeff_midp_in average_temporal_dimension $vf_dir/coeff_inside_${ref_phase_nb}_4D_0.mhd $coeff_midp_in abort_on_error midp $? clean_up_midp - # clitkAverageTemporalDimension -i $vf_dir/vf_outside_${ref_phase_nb}_4D.mhd -o $vf_midp_out - #clitkAverageTemporalDimension -i $vf_dir/coeff_outside_${ref_phase_nb}_4D_0.mhd -o $coeff_midp_out average_temporal_dimension $vf_dir/coeff_outside_${ref_phase_nb}_4D_0.mhd $coeff_midp_out abort_on_error midp $? clean_up_midp # invert the vf - # clitkInvertVF -i $vf_midp_in -o $vf_midp_in clitkInvertVF -i $coeff_midp_in -o $vf_midp_in --type 1 --like $ref_phase_file abort_on_error midp $? clean_up_midp - # clitkInvertVF -i $vf_midp_out -o $vf_midp_out clitkInvertVF -i $coeff_midp_out -o $vf_midp_out --type 1 --like $ref_phase_file abort_on_error midp $? clean_up_midp @@ -271,10 +336,8 @@ midp_in_out() ref_vf_midp_in=$vf_midp_in ref_vf_midp_out=$vf_midp_out vf_midp=$midp_dir/vf_midp_$phase_nb.mhd - #clitkCombineImage -i $vf_midp_in -j $vf_midp_out -o $vf_midp -m $mask_dir/mm_$phase_nb.mhd - combine_image $vf_midp_in $vf_midp_out $vf_midp $mask_dir/mm_$phase_nb.mhd + combine_image $vf_midp_in $vf_midp_out $vf_midp $mask_dir/${mask_type}_$phase_nb.mhd clitkZeroVF -i $vf_midp -o vf_zero.mhd - #clitkCombineImage -i $vf_midp -j vf_zero.mhd -o $vf_midp -m $mask_dir/patient_mask_$phase_nb.mhd combine_image $vf_midp vf_zero.mhd $vf_midp $mask_dir/patient_mask_$phase_nb.mhd # create the midp by warping the reference phase with the reference vf @@ -303,10 +366,8 @@ midp_in_out() # combine in and out VF's vf_midp=$midp_dir/vf_midp_$phase_nb.mhd - #clitkCombineImage -i $vf_midp_in -j $vf_midp_out -o $vf_midp -m $mask_dir/mm_$phase_nb.mhd - combine_image $vf_midp_in $vf_midp_out $vf_midp $mask_dir/mm_$phase_nb.mhd + combine_image $vf_midp_in $vf_midp_out $vf_midp $mask_dir/${mask_type}_$phase_nb.mhd clitkZeroVF -i $vf_midp -o vf_zero.mhd - #clitkCombineImage -i $vf_midp -j vf_zero.mhd -o $vf_midp -m $mask_dir/patient_mask_$phase_nb.mhd combine_image $vf_midp vf_zero.mhd $vf_midp $mask_dir/patient_mask_$phase_nb.mhd midp=$midp_dir/midp_$phase_nb.mhd @@ -327,7 +388,6 @@ midp_in_out() create_mhd_4D_pattern.sh $midp_dir/vf_outside_midp_ echo "Calculating midp_avg.mhd..." - #clitkAverageTemporalDimension -i $midp_dir/midp_4D.mhd -o $midp_dir/midp_avg.mhd average_temporal_dimension $midp_dir/midp_4D.mhd $midp_dir/midp_avg.mhd abort_on_error midp $? clean_up_midp @@ -335,9 +395,6 @@ midp_in_out() clitkMedianTemporalDimension -i $midp_dir/midp_4D.mhd -o $midp_dir/midp_med.mhd abort_on_error midp $? clean_up_midp - # clean-up - #rm $midp_dir/vf_* - echo echo "-------- Mid-position done ! --------" end=`date` @@ -374,14 +431,20 @@ mask_dir="MASK-${mask_interpolation_spacing}mm-$mask_interpolation_algorithm" extract_4d_phases_ref $mhd4d $ref_phase if [ "$step" == "mask" -o "$step" == "all" ]; then - motion_mask $mhd4d $mask_interpolation_spacing $mask_interpolation_algorithm + motion_mask $mhd4d $mask_type $mask_interpolation_spacing $mask_interpolation_algorithm fi if [ "$step" == "registration" -o "$step" == "all" ]; then - registration + if [ "$mask_type" == "mm" ]; then + registration + elif [ "$mask_type" == "lungs" ]; then + registration + elif [ "$mask_type" == "patient" ]; then + registration_no_motion_mask + midp_combined_vf=1 + fi fi -midp_combined_vf=0 if [ "$step" == "midp" -o "$step" == "all" ]; then if [ $midp_combined_vf = 0 ]; then midp_in_out diff --git a/scripts/create_midP_masks-2.0.sh b/scripts/create_midP_masks-2.0.sh index 292ff3c..6fa7476 100755 --- a/scripts/create_midP_masks-2.0.sh +++ b/scripts/create_midP_masks-2.0.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /bin/bash -x ############################################################################### # @@ -54,6 +54,7 @@ resample() 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 + clitkResampleImage -i $mask_dir_tmp/bones_$phase_nb.mhd -o $mask_dir_tmp/bones_$phase_nb.mhd --like $mask_dir_tmp/patient_$phase_nb.mhd } compute_motion_mask() @@ -65,7 +66,8 @@ 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 $MotionMaskOffsetDetect --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 + 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 --featureBones $mask_dir_tmp/bones_$phase_nb.mhd --fillingLevel $FillingLevel --offsetDetect $MotionMaskOffsetDetect --pad --writeFeature $mask_dir_tmp/feature_$phase_nb.mhd $MotionMaskExtra #--monitor=$mask_dir_tmp/monitor_$phase_nb.mhd } @@ -96,8 +98,8 @@ create_banded_mask() clitkImageArithm -i $input_mask -j $input_dir/band1_$input_base -o $output_mask -t 0 clitkImageArithm -i $output_mask -j $input_dir/band2_$input_base -o $output_mask -t 0 # combine bands with image - clitkCombineImage -i $input_dir/short_band1_$input_base -j $input -m $input_dir/band1_$input_base -o $output - clitkCombineImage -i $input_dir/short_band2_$input_base -j $output -m $input_dir/band2_$input_base -o $output + combine_image $input_dir/short_band1_$input_base $input $output $input_dir/band1_$input_base + combine_image $input_dir/short_band2_$input_base $output $output $input_dir/band2_$input_base # clean-up rm `echo $input_dir/extra?_$input_base | sed 's:.mhd:.*:g'` @@ -107,7 +109,30 @@ create_banded_mask() create_registration_masks() { - # extract inside and outside lung regions from the patient image, + # extract inside and outside regions from the patient image, + # using the motion mask computed previously + echo "$phase_file -> Setting Background..." + clitkSetBackground -i $mask_dir_tmp/patient_$phase_nb.mhd -o $mask_dir_tmp/inside_$phase_nb.mhd --mask $mask_dir_tmp/${mask_type}_$phase_nb.mhd --outsideValue -1200 + clitkSetBackground -i $mask_dir_tmp/patient_$phase_nb.mhd -o $mask_dir_tmp/outside_$phase_nb.mhd --mask $mask_dir_tmp/${mask_type}_$phase_nb.mhd --outsideValue -1200 --fg + + # the registration masks for inside (and outside) region correspond + # to the motion mask (and its complement) plus extra grey value bands, + # obtained with morphological dilations. + # + echo "$phase_file -> Creating registration masks..." + # inside + clitkMorphoMath -i $mask_dir_tmp/${mask_type}_$phase_nb.mhd -o $mask_dir_tmp/mask_inside_$phase_nb.mhd --type 1 --radius 8 + create_banded_mask $mask_dir_tmp/inside_$phase_nb.mhd $mask_dir_tmp/${mask_type}_$phase_nb.mhd $mask_dir_tmp/banded_inside_$phase_nb.mhd $mask_dir_tmp/banded_mask_inside_$phase_nb.mhd 4 + # outside + clitkBinarizeImage -i $mask_dir_tmp/outside_$phase_nb.mhd -o $mask_dir_tmp/${mask_type}_outside_$phase_nb.mhd -l -999 -u 4000 --mode both + #clitkExtractPatient -i $mask_dir_tmp/outside_$phase_nb.mhd -o $mask_dir_tmp/${mask_type}_outside_$phase_nb.mhd --noAutoCrop + clitkMorphoMath -i $mask_dir_tmp/${mask_type}_outside_$phase_nb.mhd -o $mask_dir_tmp/mask_outside_$phase_nb.mhd --type 1 --radius 8 + create_banded_mask $mask_dir_tmp/outside_$phase_nb.mhd $mask_dir_tmp/${mask_type}_outside_$phase_nb.mhd $mask_dir_tmp/banded_outside_$phase_nb.mhd $mask_dir_tmp/banded_mask_outside_$phase_nb.mhd 4 +} + +create_registration_motion_masks() +{ + # extract inside and outside regions from the patient image, # using the motion mask computed previously echo "$phase_file -> Setting Background..." clitkSetBackground -i $mask_dir_tmp/patient_$phase_nb.mhd -o $mask_dir_tmp/inside_$phase_nb.mhd --mask $mask_dir_tmp/mm_$phase_nb.mhd --outsideValue -1200 @@ -127,10 +152,32 @@ create_registration_masks() create_banded_mask $mask_dir_tmp/outside_$phase_nb.mhd $mask_dir_tmp/mm_outside_$phase_nb.mhd $mask_dir_tmp/banded_outside_$phase_nb.mhd $mask_dir_tmp/banded_mask_outside_$phase_nb.mhd 4 } +create_registration_lung_masks() +{ + # extract inside and outside lung regions from the patient image, + # using the motion mask computed previously + echo "$phase_file -> Setting Background..." + clitkSetBackground -i $mask_dir_tmp/patient_$phase_nb.mhd -o $mask_dir_tmp/inside_$phase_nb.mhd --mask $mask_dir_tmp/lungs_$phase_nb.mhd --outsideValue -1200 + clitkSetBackground -i $mask_dir_tmp/patient_$phase_nb.mhd -o $mask_dir_tmp/outside_$phase_nb.mhd --mask $mask_dir_tmp/lungs_$phase_nb.mhd --outsideValue -1200 --fg + + # the registration masks for inside (and outside) region correspond + # to the motion mask (and its complement) plus extra grey value bands, + # obtained with morphological dilations. + # + echo "$phase_file -> Creating registration masks..." + # inside + clitkMorphoMath -i $mask_dir_tmp/lungs_$phase_nb.mhd -o $mask_dir_tmp/mask_inside_$phase_nb.mhd --type 1 --radius 8 + create_banded_mask $mask_dir_tmp/inside_$phase_nb.mhd $mask_dir_tmp/lungs_$phase_nb.mhd $mask_dir_tmp/banded_inside_$phase_nb.mhd $mask_dir_tmp/banded_mask_inside_$phase_nb.mhd 4 + # outside + clitkBinarizeImage -i $mask_dir_tmp/outside_$phase_nb.mhd -o $mask_dir_tmp/lungs_outside_$phase_nb.mhd -l -999 -u 4000 --mode both + clitkMorphoMath -i $mask_dir_tmp/lungs_outside_$phase_nb.mhd -o $mask_dir_tmp/mask_outside_$phase_nb.mhd --type 1 --radius 8 + create_banded_mask $mask_dir_tmp/outside_$phase_nb.mhd $mask_dir_tmp/lungs_outside_$phase_nb.mhd $mask_dir_tmp/banded_outside_$phase_nb.mhd $mask_dir_tmp/banded_mask_outside_$phase_nb.mhd 4 +} + mm_preprocessing() { extract_patient - # extract_bones + extract_bones extract_lungs # remove_tmp_masks 1 if [ $resample_spacing -ne 0 ] ; then @@ -142,7 +189,13 @@ mm_postprocessing() { # remove_tmp_masks 2 # remove_tmp_masks 3 + create_registration_masks +# if [ "$mask_type" == "mm" ]; then +# create_registration_motion_masks +# elif [ "$mask_type" == "lungs" ]; then +# create_registration_lung_masks +# fi } wait_mm_creation() @@ -163,13 +216,42 @@ wait_mm_creation() # the check assumes that the inside and outside masks are the key files to exist. do_mm=0 nb_phases=${#phase_nbs[@]} - nb_in_masks=`ls $mask_dir/mask_in*.mhd | wc -l` - nb_out_masks=`ls $mask_dir/mask_out*.mhd | wc -l` - if [ $nb_in_masks != $nb_phases -o $nb_out_masks != $nb_phases ]; then - # if the mask dir is invalid, remove it and recreate all masks, just in case. - rm -fr $mask_dir 2> /dev/null - do_mm=1 + if [ "$mask_type" == "patient" ]; then + nb_masks=`ls $mask_dir/lungs_*.mhd | wc -l` + if [ $nb_masks != $nb_phases ]; then + # if the mask dir is invalid, remove it and recreate all masks, just in case. + rm -fr $mask_dir 2> /dev/null + do_mm=1 + fi + else + nb_mm_masks=`ls $mask_dir/${mask_type}_outside*.mhd | wc -l` + nb_in_masks=`ls $mask_dir/mask_in*.mhd | wc -l` + nb_out_masks=`ls $mask_dir/mask_out*.mhd | wc -l` + if [ $nb_mm_masks != $nb_phases -o $nb_in_masks != $nb_phases -o $nb_out_masks != $nb_phases ]; then + # if the mask dir is invalid, remove it and recreate all masks, just in case. + rm -fr $mask_dir 2> /dev/null + do_mm=1 + fi fi +# elif [ "$mask_type" == "lungs" ]; then +# nb_mm_masks=`ls $mask_dir/lungs_outside*.mhd | wc -l` +# nb_in_masks=`ls $mask_dir/mask_in*.mhd | wc -l` +# nb_out_masks=`ls $mask_dir/mask_out*.mhd | wc -l` +# if [ $nb_mm_masks != $nb_phases -o $nb_in_masks != $nb_phases -o $nb_out_masks != $nb_phases ]; then +# # if the mask dir is invalid, remove it and recreate all masks, just in case. +# rm -fr $mask_dir 2> /dev/null +# do_mm=1 +# fi +# elif [ "$mask_type" == "mm" ]; then +# nb_mm_masks=`ls $mask_dir/mm_outside*.mhd | wc -l` +# nb_in_masks=`ls $mask_dir/mask_in*.mhd | wc -l` +# nb_out_masks=`ls $mask_dir/mask_out*.mhd | wc -l` +# if [ $nb_mm_masks != $nb_phases -o $nb_in_masks != $nb_phases -o $nb_out_masks != $nb_phases ]; then +# # if the mask dir is invalid, remove it and recreate all masks, just in case. +# rm -fr $mask_dir 2> /dev/null +# do_mm=1 +# fi +# fi fi if [ $do_mm = 1 ]; then @@ -210,10 +292,11 @@ wait_mm_creation() motion_mask() { #set cmd line variables - mhd4d=`basename $1` - if [ $# -eq 3 ] ; then - resample_spacing=$2 - resample_algo=$3 + local mhd4d=`basename $1` + mask_type=$2 + if [ $# -eq 4 ] ; then + resample_spacing=$3 + resample_algo=$4 else resample_spacing=0 resample_algo=0 @@ -267,33 +350,36 @@ motion_mask() abort_on_error mm_preprocessing $ret clean_up_masks done - # single-threaded motion mask calc - for i in $( seq 0 $((${#phase_nbs[@]} - 1))); do - phase_nb=${phase_nbs[$i]} - phase_file=${phase_files[$i]} - - 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 + if [ "$mask_type" == "mm" ]; then + # single-threaded motion mask calc + for i in $( seq 0 $((${#phase_nbs[@]} - 1))); do + phase_nb=${phase_nbs[$i]} + phase_file=${phase_files[$i]} + + 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 + fi # 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 - + if [ "$mask_type" != "patient" ]; then + 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 + fi # rename tmp mask directory after mask creation check_threads 1 @@ -313,8 +399,9 @@ motion_mask() # main # ################# -if [ $# -ne 3 -a $# -ne 1 ]; then - echo "Usage: $0 CT_4D [RESAMPLE_SPACING RESAMPLE_ALGORITHM]" +if [ $# -ne 4 -a $# -ne 2 -a $# -ne 1 ]; then + echo "Usage: $0 CT_4D TYPE [RESAMPLE_SPACING RESAMPLE_ALGORITHM]" + echo " TYPE: \"motion\" (traditional motion masks); \"lungs\" (lung masks); \"patient\" (patient mask only)" exit -1 fi @@ -325,9 +412,11 @@ fi # if [ $1 != "using-as-lib" ]; then - if [ $# -eq 3 ] ; then - motion_mask $1 $2 $3 + if [ $# -eq 4 ] ; then + motion_mask $1 $2 $3 $4 + elif [ $# -eq 2 ] ; then + motion_mask $1 $2 else - motion_mask $1 + motion_mask $1 all fi fi diff --git a/scripts/midp_common.sh b/scripts/midp_common.sh index 16535a1..1ac9529 100755 --- a/scripts/midp_common.sh +++ b/scripts/midp_common.sh @@ -18,9 +18,9 @@ abort_on_error() { if [ $2 != 0 ]; then echo Aborted at $1 with code $2 - if [ $# = 3 ]; then - eval $3 - fi + #if [ $# = 3 ]; then + # eval $3 + #fi exit $2 fi @@ -179,12 +179,14 @@ extract_4d_phases_ref() combine_image() { # eg: -i $result_in -j $result_out -o $out_result -m $motion_mask + local tmp1=$RANDOM + local tmp2=$RANDOM - clitkSetBackground -i $1 -o temp1.mhd -m $4 - clitkSetBackground -i $2 -o temp2.mhd -m $4 --fg + clitkSetBackground -i $1 -o $tmp1.mhd -m $4 + clitkSetBackground -i $2 -o $tmp2.mhd -m $4 --fg - clitkImageArithm -i temp1.mhd -j temp2.mhd -o $3 - rm temp?.* + clitkImageArithm -i $tmp1.mhd -j $tmp2.mhd -o $3 + rm $tmp1.* $tmp2.* } # @@ -192,8 +194,8 @@ combine_image() average_temporal_dimension() { # eg: -i $midp_dir/midp_4D.mhd -o $midp_dir/midp_avg.mhd - - local tot=tot.mhd + local tmp=$RANDOM + local tot=$tmp.mhd local dir=`dirname $1` local first=`grep raw $1 | sed 's/raw/mhd/g' | head -n 1` @@ -205,5 +207,5 @@ average_temporal_dimension() done clitkImageArithm -i $tot -o $2 -t 11 -s $nbphases - rm tot.* + rm $tmp.* } diff --git a/scripts/midp_template.conf b/scripts/midp_template.conf index 8fde2c8..be3e0aa 100644 --- a/scripts/midp_template.conf +++ b/scripts/midp_template.conf @@ -18,6 +18,15 @@ log_dir="" # midp depends on registration, which depends on mask step="all" +# indicate if midp images are computed with the in and out +# VFs combined +midp_combined_vf=0 + +# indicate which masks are used in the registration (mm, lungs, patient). if +# "patient", only the patient mask is used, and midp_combined_vf is +# set to 1. +mask_type="" + # mask parameters # # interpolation algorithm for resampling (see clitkResampleImage) -- 2.47.1