From: Romulo Pinho Date: Tue, 21 Jun 2011 14:00:31 +0000 (+0200) Subject: moved $CLITK3/vv/scripts to $CLITK3/scripts X-Git-Tag: v1.3.0~317 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=70807bce501741d4a89c1b4e4eebb62706c4d893;p=clitk.git moved $CLITK3/vv/scripts to $CLITK3/scripts - added create_midP_masks.sh --- diff --git a/vv/scripts/create_mhd_4D.sh b/scripts/create_mhd_4D.sh similarity index 86% rename from vv/scripts/create_mhd_4D.sh rename to scripts/create_mhd_4D.sh index b0503c9..00df85c 100755 --- a/vv/scripts/create_mhd_4D.sh +++ b/scripts/create_mhd_4D.sh @@ -28,7 +28,7 @@ then exit 1 fi -nb_phase_file=`find $1 -iname "*[0-9].mhd" -o -iname "*[0-9]*\]*.mhd" | wc -l` +nb_phase_file=`find $1 -iname "*[0-9]*.mhd" -o -iname "*[0-9]*\]*.mhd" | wc -l` if [ $nb_phase_file = 0 ] then echo "Error: no phase found" @@ -38,7 +38,7 @@ fi ########## CT ######### list_pattern="" -list_phase_file=`find $1 -iname "*[0-9].mhd"` +list_phase_file=`find $1 -iname "*[0-9]*.mhd"` for phase_file in $list_phase_file do phase_file_name=`basename $phase_file` @@ -63,11 +63,12 @@ do pattern="" fi - nbph=`find $1 -iname "${pattern}*[0-9].mhd" | wc -l` - orig=`find $1 -iname "${pattern}*[0-9].mhd" | sort | head -n 1` - listph=`find $1 -iname "${pattern}*[0-9].raw" | sort` + nbph=`find $1 -iname "${pattern}*[0-9]*.mhd" | wc -l` + orig=`find $1 -iname "${pattern}*[0-9]*.mhd" | sort | head -n 1` + listph=`find $1 -iname "${pattern}*[0-9]*.raw" | sort` file_name_4D="${pattern}_4D.mhd" + echo $file_name_4D write_mhd_4D $1 diff --git a/scripts/create_midP_masks.sh b/scripts/create_midP_masks.sh new file mode 100755 index 0000000..e5894a4 --- /dev/null +++ b/scripts/create_midP_masks.sh @@ -0,0 +1,248 @@ +#! /bin/bash -x + +# imports +. common.sh + +extract_patient() +{ + echo "$image_name -> Extracting patient..." + clitkExtractPatient -i $image_name -o $mask_dir_tmp/patient_$image_name --noAutoCrop -a $afdb_name $ExtractPatientExtra + clitkBinarizeImage -i $mask_dir_tmp/patient_$image_name -o $mask_dir_tmp/patient_$image_name -l 1 -u 1 --mode=BG + clitkSetBackground -i $image_name -o $mask_dir_tmp/patient_only_$image_name --mask $mask_dir_tmp/patient_$image_name --outsideValue -1000 +} + +extract_bones() +{ + if [ x = x$ExtractBonesLower1 ]; then + ExtractBonesLower1=120 + fi + echo "$image_name -> Extracting bones..." + clitkImageConvert -i $image_name -o $mask_dir_tmp/float_$image_name -t float + #clitkExtractBones -i $mask_dir_tmp/float_$image_name -o $mask_dir_tmp/bones_$image_name --lower1 120 --upper1 2000 --lower2 70 --upper2 2000 --smooth --time 0.0625 --noAutoCrop + clitkExtractBones -i $mask_dir_tmp/float_$image_name -o $mask_dir_tmp/bones_$image_name -a $afdb_name --lower1 $ExtractBonesLower1 --upper1 2000 --lower2 80 --upper2 2000 --smooth --time 0.0625 --noAutoCrop + #clitkMorphoMath -i $mask_dir_tmp/bones_$image_name -o $mask_dir_tmp/bones_$image_name --type 2 --radius 4,4,2 +} + +extract_lungs() +{ + echo "$image_name -> Extracting lungs..." + clitkExtractLung -i $image_name -o $mask_dir_tmp/lungs_$image_name -a $afdb_name --noAutoCrop +} + +resample() +{ + echo "$image_name -> Resampling..." + clitkResampleImage -i $mask_dir_tmp/patient_$image_name -o $mask_dir_tmp/patient_$image_name --spacing $resample_spacing --interp $resample_algo + clitkResampleImage -i $mask_dir_tmp/patient_only_$image_name -o $mask_dir_tmp/patient_only_$image_name --spacing $resample_spacing --interp $resample_algo + clitkResampleImage -i $mask_dir_tmp/bones_$image_name -o $mask_dir_tmp/bones_$image_name --like $mask_dir_tmp/patient_only_$image_name --interp $resample_algo + clitkResampleImage -i $mask_dir_tmp/lungs_$image_name -o $mask_dir_tmp/lungs_$image_name --like $mask_dir_tmp/patient_only_$image_name +} + +compute_motion_mask() +{ + if [ x = x$MotionMaskOffsetDetect ]; then + MotionMaskOffsetDetect="0,-5,0" + fi + clitkMotionMask -i $mask_dir_tmp/patient_only_$image_name -o $mask_dir_tmp/mm_$image_name --featureBones=$mask_dir_tmp/bones_$image_name --featureLungs=$mask_dir_tmp/lungs_$image_name --upperThresholdLungs -400 --fillingLevel 94 --offsetDetect 0,-5,0 --pad --writeFeature=$mask_dir_tmp/feature_$image_name $MotionMaskExtra --monitor=$mask_dir_tmp/monitor_$image_name +} + +set_background() +{ + echo "$image_name -> Setting Background..." + clitkSetBackground -i $mask_dir_tmp/patient_only_$image_name -o $mask_dir_tmp/inside_$image_name --mask $mask_dir_tmp/mm_$image_name --outsideValue -1200 + clitkSetBackground -i $mask_dir_tmp/patient_only_$image_name -o $mask_dir_tmp/outside_$image_name --mask $mask_dir_tmp/mm_$image_name --outsideValue -1200 --fg +} + +create_registration_masks() +{ + echo "$image_name -> Creating registration masks..." + clitkMorphoMath -i $mask_dir_tmp/mm_$image_name -o $mask_dir_tmp/regmask_in_$image_name --type 1 --radius 8 + clitkExtractPatient -i $mask_dir_tmp/outside_$image_name -o $mask_dir_tmp/regmask_out_$image_name --noAutoCrop + clitkMorphoMath -i $mask_dir_tmp/regmask_out_$image_name -o $mask_dir_tmp/regmask_out_$image_name --type 1 --radius 8 +} + +remove_tmp_masks() +{ + echo "Removing temporary files..." + image_name_base=`echo $image_name | sed 's/mhd//'` + case $1 in + 1) + #rm $mask_dir_tmp/float_$image_name_base* + ;; + 2) + #rm $mask_dir_tmp/bones_$image_name_base* + ;; + 3) + #rm $mask_dir_tmp/patient_only_$image_name_base* + ;; + esac +} + +mm_preprocessing() +{ + extract_patient + extract_bones + extract_lungs + remove_tmp_masks 1 + resample +} + +mm_postprocessing() +{ + remove_tmp_masks 2 + set_background + remove_tmp_masks 3 + create_registration_masks +} + +mm_workflow() +{ + extract_patient + extract_bones + remove_tmp_masks 1 + resample + echo "$image_name -> Computing motion mask..." + compute_motion_mask >> $mask_log_dir/motion_mask_$image_name.log + remove_tmp_masks 2 + set_background + remove_tmp_masks 3 + create_registration_masks +} + +motion_mask() +{ + #set cmd line variables + echo "4D CT -> "$1 + phases=`grep ".raw" $1` + echo "mask phases -> " $phases + + dir=`dirname $1` + cd $dir + + resample_spacing=$2 + resample_algo=$3 + + + #set other global variables + mask_dir="MASK-$resample_spacing""mm""-$resample_algo" + mask_dir_tmp="tmp."$mask_dir + + echo + echo "------------ Motion mask from create_midP_masks.sh ------------" + start=`date` + echo "start: $start" + echo + + # the motion masks are first created in a tmp directory. this directory is + # later going to be renamed to the final motion mask directory. concurrent + # executions trying to create the same set of masks will be blocked until + # the first execution finishes. naturally, these other executions will not + # recreate the masks. so first we try to create the tmp directory. + # if the creation fails, it means that another execution is + # already creating the masks, so this execution will be blocked. the + # execution is unblocked only when the creation of masks is finished and + # the mask directory is renamed. + # + # ATTENTION: RP - 08/02/2011 + # robustness issue: tmp directory may exist but may be empty or + # incomplete. the solution is to check per file, but I'll leave it like + # this for the moment. + do_mm=0 + if [ $(ls -d $mask_dir 2> /dev/null | wc -l) -eq 0 ]; then + mkdir $mask_dir_tmp 2> /dev/null + return_mkdir=$? + if [ $return_mkdir == 0 ]; then + do_mm=1 + else + while [[ $(ls -d $mask_dir 2> /dev/null | wc -l) -eq 0 ]]; do + echo "waiting creation of motion masks..." + sleep 2 + done + echo "finished waiting" + fi + fi + + regmask_in_list="" + regmask_out_list="" + reg_in_list="" + reg_out_list="" + + # multi-threaded pre-processing for motion mask calcs + if [ $do_mm == 1 ]; then + mask_log_dir=$mask_dir_tmp/LOG + mkdir -p $mask_log_dir + + for phase in $phases + do + image_name=`echo $phase | sed 's/raw/mhd/'` + afdb_name=`echo $phase | sed 's/raw/afdb/'` + check_threads $MAX_THREADS + mm_preprocessing & + done + + # single-threaded motion mask calc + for phase in $phases + do + image_name=`echo $phase | sed 's/raw/mhd/'` + + check_threads 1 + echo "$image_name -> Computing motion mask..." + compute_motion_mask >> $mask_log_dir/motion_mask_$image_name.log + done + fi + + # multi-threaded post-processing of motion mask calcs + for phase in $phases + do + image_name=`echo $phase | sed 's/raw/mhd/'` + if [ $do_mm = 1 ]; then + check_threads $MAX_THREADS + mm_postprocessing & + fi + + regmask_in_list="$regmask_in_list regmask_in_$image_name" + regmask_out_list="$regmask_out_list regmask_out_$image_name" + reg_in_list="$reg_in_list inside_$image_name" + reg_out_list="$reg_out_list outside_$image_name" + done + + # rename tmp mask directory after mask creation + check_threads 1 + mv $mask_dir_tmp $mask_dir + + wait + + echo + echo "-------- Motion mask done ! ---------" + end=`date` + echo "start: $start" + echo "end: $end" + echo +} + + +################# +# main # +################# + +if [ $# != 3 ]; then + echo "Usage: create_midP_masks.sh 4D_CT.mhd resample_spacing resample_algorithm" + exit -1 +fi + +# +# variables exported in this scope +# +# mask_dir: directory where all mask are kept +# regmask_in_list: list of registration mask files (inside lungs) +# regmask_out_list: list of registration mask files (outised lungs) +# reg_in_list: list of registration image files (inside lungs) +# reg_out_list: list of registration image files (outside lungs) +# + +# import variables specific to each patient +source variables + +if [ $1 != "using-as-lib" ]; then + motion_mask $1 $2 $3 +fi diff --git a/vv/scripts/create_sequence.sh b/scripts/create_sequence.sh similarity index 100% rename from vv/scripts/create_sequence.sh rename to scripts/create_sequence.sh diff --git a/vv/scripts/dcm_sort_by_field.sh b/scripts/dcm_sort_by_field.sh similarity index 100% rename from vv/scripts/dcm_sort_by_field.sh rename to scripts/dcm_sort_by_field.sh diff --git a/vv/scripts/dicom_info.sh b/scripts/dicom_info.sh similarity index 100% rename from vv/scripts/dicom_info.sh rename to scripts/dicom_info.sh diff --git a/segmentation/clitkMotionMaskGenericFilter.txx b/segmentation/clitkMotionMaskGenericFilter.txx index 414a2f6..91e1bbd 100644 --- a/segmentation/clitkMotionMaskGenericFilter.txx +++ b/segmentation/clitkMotionMaskGenericFilter.txx @@ -377,6 +377,8 @@ MotionMaskGenericFilter::GetLungsImage(typename itk::Image connectFilter->SetBackgroundValue(0); connectFilter->SetFullyConnected(true); if (m_Verbose) std::cout<<"Labeling the connected components..."<Update(); + if (m_Verbose) std::cout<<"found "<< connectFilter->GetObjectCount() << std::endl; //--------------------------------- // Sort the labels according to size diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 2ccbb6e..837c4df 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -256,8 +256,15 @@ IF (CLITK_BUILD_TOOLS) ADD_EXECUTABLE(clitkLineProfile clitkLineProfile.cxx clitkLineProfileGenericFilter.cxx ${clitkLineProfile_GGO_C}) TARGET_LINK_LIBRARIES(clitkLineProfile clitkCommon ${ITK_LIBRARIES}) + ADD_EXECUTABLE(clitkMakeSphereImage clitkMakeSphereImage.cxx) # clitkLineProfileGenericFilter.cxx ${clitkLineProfile_GGO_C}) + TARGET_LINK_LIBRARIES(clitkMakeSphereImage clitkCommon ${ITK_LIBRARIES}) + + #WRAP_GGO(clitkLineProfile_GGO_C clitkLineProfile.ggo) + ADD_EXECUTABLE(clitkJacobianImage clitkJacobianImage.cxx) # clitkLineProfileGenericFilter.cxx ${clitkLineProfile_GGO_C}) + TARGET_LINK_LIBRARIES(clitkJacobianImage clitkCommon ${ITK_LIBRARIES}) + IF(CLITK_EXPERIMENTAL) - + WRAP_GGO(clitkBinaryImageToMesh_GGO_C clitkBinaryImageToMesh.ggo) ADD_EXECUTABLE(clitkBinaryImageToMesh clitkBinaryImageToMesh.cxx ${clitkBinaryImageToMesh_GGO_C}) TARGET_LINK_LIBRARIES(clitkBinaryImageToMesh ${ITK_LIBRARIES} vtkCommon vtkRendering)