]> Creatis software - FrontAlgorithms.git/blobdiff - tests/image/MoriSegmentation.cxx
...
[FrontAlgorithms.git] / tests / image / MoriSegmentation.cxx
index d1b26f52bb6f2600fa073042426cc1bb53f7a224..f2dd92a0e8147e22436acf13e8fbcc78d93d68d3 100644 (file)
@@ -1,4 +1,5 @@
 #include "BaseFunctions.h"
+#include <chrono>
 #include <itkImage.h>
 #include <fpa/Image/Mori.h>
 
@@ -15,11 +16,11 @@ typedef fpa::Image::Mori< TInputImage, TLabelImage > TFilter;
 int main( int argc, char* argv[] )
 {
   // Get arguments
-  if( argc < 8 + Dim )
+  if( argc < 9 + Dim )
   {
     std::cerr
       << "Usage: " << argv[ 0 ]
-      << " input_image output_image output_levels"
+      << " input_image output_image output_marks output_signal"
       << " init_threshold end_threshold delta [index/point] seed"
       << std::endl;
     return( 1 );
@@ -27,20 +28,21 @@ int main( int argc, char* argv[] )
   } // fi
   std::string input_image_filename = argv[ 1 ];
   std::string output_image_filename = argv[ 2 ];
-  std::string output_levels_filename = argv[ 3 ];
-  TPixel init_threshold = std::atoi( argv[ 4 ] );
-  TPixel end_threshold = std::atoi( argv[ 5 ] );
-  TPixel delta = std::atoi( argv[ 6 ] );
-  std::string seed_type = argv[ 7 ];
+  std::string output_marks_filename = argv[ 3 ];
+  std::string output_signal_filename = argv[ 4 ];
+  TPixel init_threshold = std::atoi( argv[ 5 ] );
+  TPixel end_threshold = std::atoi( argv[ 6 ] );
+  TPixel delta = std::atoi( argv[ 7 ] );
+  std::string seed_type = argv[ 8 ];
 
   TInputImage::IndexType iseed;
   TInputImage::PointType pseed;
   for( unsigned int i = 0; i < Dim; ++i )
   {
     if( seed_type == "index" )
-      iseed[ i ] = std::atoi( argv[ 8 + i ] );
+      iseed[ i ] = std::atoi( argv[ 9 + i ] );
     else
-      pseed[ i ] = std::atof( argv[ 8 + i ] );
+      pseed[ i ] = std::atof( argv[ 9 + i ] );
 
   } // rof
 
@@ -60,18 +62,41 @@ int main( int argc, char* argv[] )
   filter->SetThresholds( init_threshold, end_threshold, delta );
   filter->SetInsideValue( 255 );
   filter->SetOutsideValue( 0 );
+  filter->SetSignalLag( 20 );
+  filter->SetSignalThreshold( 500 );
+  filter->SetSignalInfluence( 0.5 );
 
   // Execute filter
+  std::chrono::time_point< std::chrono::high_resolution_clock > tstart, tend;
+  tstart = std::chrono::high_resolution_clock::now( );
   filter->Update( );
+  tend = std::chrono::high_resolution_clock::now( );
+  std::chrono::duration< double > telapsed = tend - tstart;
 
   // Save results
   std::string err1 =
-    fpa::tests::image::Write( filter->GetOutput( ), output_image_filename );
+    fpa::tests::image::Write( filter->GetThresholdedOutput( ), output_image_filename );
   std::string err2 =
-    fpa::tests::image::Write( filter->GetOutputLevels( ), output_levels_filename );
+    fpa::tests::image::Write( filter->GetMarks( ), output_marks_filename );
   if( err1 != "" ) std::cerr << err1 << std::endl;
   if( err2 != "" ) std::cerr << err2 << std::endl;
 
+  std::ofstream osignal( output_signal_filename.c_str( ) );
+  const TFilter::TSignal& signal = filter->GetSignal( );
+  for( unsigned long i = 0; i < signal.size( ); ++i )
+    osignal << signal[ i ].first << " " << signal[ i ].second << std::endl;
+  osignal.close( );
+
+  std::cout
+    << "------------------------------------------------------" << std::endl
+    << "Elapsed time: " << telapsed.count( ) << " s" << std::endl
+    << "Optimum threshold: "
+    << filter->GetOptimumThreshold( ) << std::endl
+    << "Number of evaluated thresholds: "
+    << filter->GetNumberOfEvaluatedThresholds( ) << std::endl
+    << "------------------------------------------------------"
+    << std::endl;
+
   return( 0 );
 }