]> Creatis software - FrontAlgorithms.git/commitdiff
...
authorLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Tue, 29 Aug 2017 18:59:56 +0000 (13:59 -0500)
committerLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Tue, 29 Aug 2017 18:59:56 +0000 (13:59 -0500)
appli/CTBronchi/CMakeLists.txt
appli/CTBronchi/CTBronchi_process.sh
appli/CTBronchi/Functions.h
appli/CTBronchi/Process.cxx
appli/CTBronchi/RandomWalker.h
lib/fpa/Filters/Image/SeedsFromLabelsInterface.hxx

index 012436fb12d5fd55be2cd562f94fe64078fd4fa9..1851e55671088bd42244a923e619800c0344c165 100644 (file)
@@ -1,12 +1,12 @@
 option(fpa_BUILD_CTBronchi "Build bronchi analysis from CT images applications?" OFF)
 if(fpa_BUILD_CTBronchi)
-#  configure_file(
-#    CTBronchi_process.sh
-#    ${PROJECT_BINARY_DIR}/CTBronchi_process.sh
-#    COPYONLY
-#    )
-include_directories(
-  ${PROJECT_SOURCE_DIR}/lib
+  configure_file(
+    CTBronchi_process.sh
+    ${PROJECT_BINARY_DIR}/CTBronchi_process.sh
+    COPYONLY
+    )
+  include_directories(
+    ${PROJECT_SOURCE_DIR}/lib
   ${PROJECT_BINARY_DIR}/lib
   ${PROJECT_SOURCE_DIR}/appli
   ${PROJECT_BINARY_DIR}/appli
index f22b699ce9c40efc1e692ed0120ac138bc65d958..1f144db7b0bf5948d34222a797825d90d461d0b9 100755 (executable)
@@ -1,95 +1,26 @@
 #!/bin/bash
 
-## Command line arguments
-while [[ "$#" -gt 1 ]]; do
-    key="$1"
-    case $key in
-        -input)
-        input="$2"
-        shift
-        ;;
-        -seed)
-        sx="$2"
-        sy="$3"
-        sz="$4"
-        shift
-        ;;
-        -mori)
-        mori="$2"
-        shift
-        ;;
-        -labels)
-        labels="$2"
-        shift
-        ;;
-        -output)
-        output="$2"
-        shift
-        ;;
-        *)
-        # Do nothing
-        ;;
-    esac
-    shift
-done
-if [ -z "$input" ] || [ -z "$sx" ] || [ -z "$sy" ] || [ -z "$sz" ]; then
-    (>&2 echo "Usage: $0 -input input_raw_image -seed x y z [-mori mori_image_dfilename] [-labels labels_image_filename] [-output output_image_filename] [-mori_init_threshold value] [-mori_end_threshold value] [-mori_delta value] [-mori_minimum_threshold value] [-mori_inside_value value] [-mori_outside_value value] [-mori_signal_kernel_size value] [-mori_signal_threshold value] [-mori_signal_influence value] [-label_upper_threshold value] [-label_inside value] [-label_outside value] [-random_walker_beta value]")
-    exit 1
-fi
-if [ -z "$mori_init_threshold" ]; then mori_init_threshold="-1024"; fi
-if [ -z "$mori_end_threshold" ]; then mori_end_threshold="0"; fi
-if [ -z "$mori_delta" ]; then mori_delta="1"; fi
-if [ -z "$mori_minimum_threshold" ]; then mori_minimum_threshold="-850"; fi
-if [ -z "$mori_inside_value" ]; then mori_inside_value="255"; fi
-if [ -z "$mori_outside_value" ]; then mori_outside_value="0"; fi
-if [ -z "$mori_signal_kernel_size" ]; then mori_signal_kernel_size="20"; fi
-if [ -z "$mori_signal_threshold" ]; then mori_signal_threshold="500"; fi
-if [ -z "$mori_signal_influence" ]; then mori_signal_influence="0.5"; fi
-if [ -z "$label_upper_threshold" ]; then label_upper_threshold="-600"; fi
-if [ -z "$label_inside" ]; then label_inside="1"; fi
-if [ -z "$label_outside" ]; then label_outside="2"; fi
-if [ -z "$random_walker_beta" ]; then random_walker_beta="20"; fi
+input=$1
+dir=`dirname $input`
+base=`basename $1 .mhd`_florez-l
+output="$dir/$base"_segmentation.mhd
+mori="$dir/$base"_mori.mhd
+signal="$dir/$base"_mori_signal.txt
+labels="$dir/$base"_labels.mhd
+diff="$dir/$base"_diff.mhd
+seed="$dir"/seed_florez-l.txt
 
-base_name=`dirname $input`/`basename $input .mhd`
-if [ -z "$mori" ]; then
-    mori="$base_name"_mori.mhd
-fi
-signal="$mori"_signal.txt
-if [ -z "$labels" ]; then
-    labels="$base_name"_labels.mhd
-fi
-if [ -z "$output" ]; then
-    output="$base_name"_rw.mhd
-fi
-
-exec_dir=`dirname $0`
-mori_seg=`dirname $0`/fpa_CTBronchi_MoriSegmentation
-mori_lab=`dirname $0`/fpa_CTBronchi_MoriLabelling
-random_walker=`dirname $0`/fpa_CTBronchi_RandomWalker
-
-$mori_seg \
-    $input $mori $signal \
-    $mori_init_threshold \
-    $mori_end_threshold \
-    $mori_delta \
-    $mori_minimum_threshold \
-    $mori_inside_value \
-    $mori_outside_value \
-    $mori_signal_kernel_size \
-    $mori_signal_threshold \
-    $mori_signal_influence \
-    $sx $sy $sz
-
-$mori_lab \
-    $input $mori $labels \
-    $label_upper_threshold \
-    $mori_inside_value \
-    $label_inside \
-    $label_outside
-
-$random_walker \
-    $input $labels $output \
-    $label_inside \
-    $random_walker_beta
+(>&2 echo -n "Processing $input... ")
+echo "************************************************"
+./fpa_CTBronchi_Process \
+    -in $input \
+    -out $output \
+    -seed `cat $seed` \
+    -out_mori $mori \
+    -out_signal $signal \
+    -out_labels $labels \
+    -out_diff $diff
+echo "************************************************"
+(>&2 echo "done.")
 
 ## eof - $RCSfile$
index cfbbcfe369190e4170b5a6b34af5d3162a87d4a3..7f20083f1017baab844ae97bd103f47a296a4e0e 100644 (file)
@@ -69,7 +69,7 @@ namespace CTBronchi
     args[ "mori_lower_threshold" ] = "-1024";
     args[ "mori_upper_threshold" ] = "0";
     args[ "mori_delta_threshold" ] = "1";
-    args[ "labelling_upper_threshold" ] = "-550";
+    args[ "labelling_upper_threshold" ] = "-600";
     args[ "random_walker_alpha" ] = "1";
     args[ "random_walker_beta" ] = "100";
 
@@ -110,6 +110,7 @@ namespace CTBronchi
         << "\t[-out_mori filename]" << std::endl
         << "\t[-out_signal filename]" << std::endl
         << "\t[-out_labels filename]" << std::endl
+        << "\t[-out_diff filename]" << std::endl
         << "\t[-mori_minimum_threshold value]" << std::endl
         << "\t[-mori_signal_kernel_size value]" << std::endl
         << "\t[-mori_signal_threshold value]" << std::endl
index c5c968630cd787b91520a40838f9daa4b9e40ab2..19d16d50edc716e60f7b1b88e5ea451cc983748e 100644 (file)
@@ -4,6 +4,8 @@
 // =========================================================================
 
 #include <itkImage.h>
+#include <itkAbsoluteValueDifferenceImageFilter.h>
+#include <itkBinaryThresholdImageFilter.h>
 #include <CTBronchi/Functions.h>
 #include <CTBronchi/Mori.h>
 #include <CTBronchi/MoriLabelling.h>
 const unsigned int Dim = 3;
 typedef short         TInputPixel;
 typedef unsigned char TLabelPixel;
-typedef float         TScalar;
 typedef itk::Image< TInputPixel, Dim > TImage;
 typedef itk::Image< TLabelPixel, Dim > TLabelImage;
-typedef itk::Image< TScalar, Dim >     TScalarImage;
-
-// -------------------------------------------------------------------------
-/* TODO
-   TMap Args;
-   TInputImage::PointType global_seed;
-   TLabelPixel inside_value = TLabelPixel( 1 );
-   TLabelPixel outside_value = TLabelPixel( 0 );
-   TLabelPixel inside_label = TLabelPixel( 1 );
-   TLabelPixel outside_label = TLabelPixel( 2 );
-*/
-
-// -------------------------------------------------------------------------
-/* TODO
-   template< class _TInputPtr, class _TOutputPtr >
-   void Label( _TOutputPtr& output, const _TInputPtr& input, const _TOutputPtr& labels )
-   {
-   typedef typename _TInputPtr::ObjectType  _TInput;
-   typedef typename _TOutputPtr::ObjectType _TOutput;
-   typedef CTBronchi::MoriLabelling< _TInput, _TOutput > _TLabelling;
-
-   typename _TLabelling::Pointer labelling = _TLabelling::New( );
-   labelling->SetInput( input );
-   labelling->SetInputLabels( labels );
-   labelling->SetOutsideValue( outside_label );
-   labelling->SetInsideValue( inside_label );
-   labelling->SetInputInsideValue( inside_value );
-   labelling->SetUpperThreshold(
-   TInputPixel( std::atof( Args[ "labelling_upper_threshold" ].c_str( ) ) )
-   );
-   double t = MeasureTime( labelling );
-   std::cout << "Labelling executed in " << t << " s" << std::endl;
-   output = labelling->GetOutput( );
-   TMap::const_iterator i = Args.find( "out_labels" );
-   if( i != Args.end( ) )
-   WriteImage( output, i->second );
-   output->DisconnectPipeline( );
-   }
-
-   // -------------------------------------------------------------------------
-   template< class _TRawPtr, class _TLabelPtr >
-   void RandomWalker( _TLabelPtr& output, const _TRawPtr& raw, const _TLabelPtr& labels )
-   {
-   typedef typename _TRawPtr::ObjectType  _TRaw;
-   typedef typename _TLabelPtr::ObjectType _TLabel;
-   }
-
-   // -------------------------------------------------------------------------
-   bool ParseArgs( int argc, char* argv[] )
-   {
-   std::set< std::string > mandatory;
-   mandatory.insert( "in" );
-   mandatory.insert( "out_segmentation" );
-   mandatory.insert( "seed_x" );
-   mandatory.insert( "seed_y" );
-   mandatory.insert( "seed_z" );
-
-   Args[ "mori_minimum_threshold" ] = "-850";
-   Args[ "mori_signal_kernel_size" ] = "20";
-   Args[ "mori_signal_threshold" ] = "100";
-   Args[ "mori_signal_influence" ] = "0.5";
-   Args[ "mori_lower_threshold" ] = "-1024";
-   Args[ "mori_upper_threshold" ] = "0";
-   Args[ "mori_delta_threshold" ] = "1";
-   Args[ "labelling_upper_threshold" ] = "-400";
-
-   for( int i = 1; i < argc; i += 2 )
-   Args[ argv[ i ] + 1 ] = argv[ i + 1 ];
-
-   bool complete = true;
-   for( std::string t: mandatory )
-   complete &= ( Args.find( t ) != Args.end( ) );
-
-   if( !complete )
-   {
-   std::cerr
-   << "Usage: " << argv[ 0 ] << std::endl
-   << "\t-in filename" << std::endl
-   << "\t-out_segmentation filename" << std::endl
-   << "\t-seed_x value -seed_y value -seed_z value" << std::endl
-   << "\t[-out_mori filename]" << std::endl
-   << "\t[-out_signal filename]" << std::endl
-   << "\t[-out_labels filename]" << std::endl
-   << "\t[-mori_minimum_threshold value]" << std::endl
-   << "\t[-mori_signal_kernel_size value]" << std::endl
-   << "\t[-mori_signal_threshold value]" << std::endl
-   << "\t[-mori_signal_influence value]" << std::endl
-   << "\t[-mori_lower_threshold value]" << std::endl
-   << "\t[-mori_upper_threshold value]" << std::endl
-   << "\t[-mori_delta_threshold value]" << std::endl
-   << "\t[-labelling_upper_threshold value]" << std::endl;
-   return( false );
-
-   } // fi
-   return( true );
-   }
-*/
 
 // -------------------------------------------------------------------------
 int main( int argc, char* argv[] )
@@ -142,12 +46,40 @@ int main( int argc, char* argv[] )
       TLabelImage::Pointer labels;
       CTBronchi::Label( labels, input_image, mori, opt_thr, args );
 
-      // Final segmentation
-      TScalarImage::Pointer segmentation;
-      CTBronchi::RandomWalker( segmentation, input_image, labels, args );
+      // Final labels
+      TLabelImage::Pointer final_labels;
+      CTBronchi::RandomWalker( final_labels, input_image, labels, args );
+
+      // Extract label 1
+      typedef itk::BinaryThresholdImageFilter< TLabelImage, TLabelImage > TBinThr;
+      TBinThr::Pointer bin_thr = TBinThr::New( );
+      bin_thr->SetInput( final_labels );
+      bin_thr->SetLowerThreshold( 1 );
+      bin_thr->SetUpperThreshold( 1 );
+      bin_thr->SetInsideValue( 1 );
+      bin_thr->SetOutsideValue( 0 );
+      double t = CTBronchi::MeasureTime( bin_thr );
+      std::cout << "Label extracted in " << t << " s" << std::endl;
+      TLabelImage::Pointer segmentation = bin_thr->GetOutput( );
 
       // Save
       CTBronchi::WriteImage( segmentation, args[ "out" ] );
+
+      // Save difference
+      std::map< std::string, std::string >::const_iterator i =
+        args.find( "out_diff" );
+      if( i != args.end( ) )
+      {
+        typedef itk::AbsoluteValueDifferenceImageFilter< TLabelImage, TLabelImage, TLabelImage > TDiff;
+        TDiff::Pointer diff = TDiff::New( );
+        diff->SetInput1( mori );
+        diff->SetInput2( segmentation );
+        t = CTBronchi::MeasureTime( diff );
+        std::cout << "Difference computed in " << t << " s" << std::endl;
+        TLabelImage::Pointer difference = diff->GetOutput( );
+        CTBronchi::WriteImage( difference, i->second );
+
+      } // fi
     }
     else
       return( 1 );
@@ -164,41 +96,6 @@ int main( int argc, char* argv[] )
 
   } // yrt
   return( 0 );
-
-  /* TODO
-     try
-     {
-     if( ParseArgs( argc, argv ) )
-     {
-     // Parse seed
-     global_seed[ 0 ] = std::atof( Args[ "seed_x" ].c_str( ) );
-     global_seed[ 1 ] = std::atof( Args[ "seed_y" ].c_str( ) );
-     global_seed[ 2 ] = std::atof( Args[ "seed_z" ].c_str( ) );
-
-     // Read input image
-     TInputImage::Pointer input_image;
-     ReadImage( input_image, Args[ "in" ] );
-
-     // Mori segmentation
-     TLabelImage::Pointer mori;
-     Mori( mori, input_image );
-
-     // Create labels
-     TLabelImage::Pointer labels;
-     Label( labels, input_image, mori );
-
-     return( 0 );
-
-     } // fi
-     return( 1 );
-     }
-  */
-  /* TODO
-     if [ -z "$label_upper_threshold" ]; then label_upper_threshold="-600"; fi
-     if [ -z "$label_inside" ]; then label_inside="1"; fi
-     if [ -z "$label_outside" ]; then label_outside="2"; fi
-     if [ -z "$random_walker_beta" ]; then random_walker_beta="20"; fi
-  */
 }
 
 // eof - $RCSfile$
index 0edb26d49e702a57847b2ac0e0310ee5fc983187..c284a542e6e0fcbc39c147607b075a9f154f34fa 100644 (file)
 namespace CTBronchi
 {
   // -----------------------------------------------------------------------
-  template< class _TInputPtr, class _TOutputPtr, class _TLabelPtr >
+  template< class _TInputPtr, class _TLabelPtr >
   void RandomWalker(
-    _TOutputPtr& output,
+    _TLabelPtr& output,
     const _TInputPtr& input, const _TLabelPtr& labels,
     std::map< std::string, std::string >& args
     )
   {
     typedef typename _TInputPtr::ObjectType  _TInput;
-    typedef typename _TOutputPtr::ObjectType _TOutput;
     typedef typename _TLabelPtr::ObjectType _TLabel;
-    typedef typename _TOutput::PixelType _TOutputPixel;
-    typedef fpa::Filters::Image::RandomWalker< _TInput, _TLabel, _TOutputPixel > _TRandomWalker;
-    typedef fpa::Functors::Dijkstra::Image::Gaussian< _TInput, _TOutputPixel > _TWeight;
+    typedef float _TScalar;
+    typedef fpa::Filters::Image::RandomWalker< _TInput, _TLabel, _TScalar > _TRandomWalker;
+    typedef fpa::Functors::Dijkstra::Image::Gaussian< _TInput, _TScalar > _TWeight;
 
     typename _TWeight::Pointer weight = _TWeight::New( );
     weight->SetAlpha( std::atof( args[ "random_walker_alpha" ].c_str( ) ) );
@@ -37,7 +36,7 @@ namespace CTBronchi
     rw->SetWeightFunction( weight );
     double t = CTBronchi::MeasureTime( rw );
     std::cout << "RandomWalker executed in " << t << " s" << std::endl;
-    output = rw->GetOutput( );
+    output = rw->GetOutputLabels( );
     output->DisconnectPipeline( );
   }
 
index 908bd1a2c238494478bc0a0ca58dc26b3745ea44..00ceefee304681178d553cced72c9372fcab09b4 100644 (file)
@@ -63,8 +63,8 @@ _PrepareSeeds( const itk::DataObject* reference )
         TNode node;
         node.Vertex = lIt.GetIndex( );
         node.Parent = lIt.GetIndex( );
-        node.FrontId = lIt.Get( );
-        node.Value = lIt.Get( );
+        node.FrontId = TMark( lIt.Get( ) );
+        node.Value = TOutputValue( lIt.Get( ) );
         if( !is_seed )
         {
           this->_AssignOutputValue( node );