]> Creatis software - FrontAlgorithms.git/blobdiff - tests/image/Dijkstra_Gaussian.cxx
...
[FrontAlgorithms.git] / tests / image / Dijkstra_Gaussian.cxx
diff --git a/tests/image/Dijkstra_Gaussian.cxx b/tests/image/Dijkstra_Gaussian.cxx
new file mode 100644 (file)
index 0000000..d0461ff
--- /dev/null
@@ -0,0 +1,99 @@
+#include "BaseFunctions.h"
+#include <itkImage.h>
+#include <fpa/Image/Dijkstra.h>
+#include <fpa/Image/Functors/Dijkstra/Gaussian.h>
+
+// -------------------------------------------------------------------------
+const unsigned int Dim = 2;
+typedef unsigned char TPixel;
+typedef float         TScalar;
+
+typedef itk::Image< TPixel, Dim >                                    TInputImage;
+typedef itk::Image< TScalar, Dim >                                  TScalarImage;
+typedef fpa::Image::Dijkstra< TInputImage, TScalarImage >                TFilter;
+typedef fpa::Image::Functors::Dijkstra::Gaussian< TInputImage, TScalar > TWeight;
+
+// -------------------------------------------------------------------------
+int main( int argc, char* argv[] )
+{
+  // Get arguments
+  if( argc < 8 )
+  {
+    std::cerr
+      << "Usage: " << argv[ 0 ]
+      << " input_image output_image output_marks alpha beta"
+      << " stop_at_one_front visual_debug ..."
+      << std::endl;
+    return( 1 );
+
+  } // fi
+  std::string input_image_filename = argv[ 1 ];
+  std::string output_image_filename = argv[ 2 ];
+  std::string output_marks_filename = argv[ 3 ];
+  double alpha = std::atoi( argv[ 4 ] );
+  double beta = std::atoi( argv[ 5 ] );
+  bool stop_at_one_front = ( argv[ 6 ][ 0 ] == '1' );
+  bool visual_debug = ( argv[ 7 ][ 0 ] == '1' );
+
+  // Create image
+  TInputImage::Pointer image;
+  std::string err0 = fpa::tests::image::Read( image, input_image_filename );
+  if( err0 != "" )
+  {
+    std::cerr << "Error caught: " << err0 << std::endl;
+    return( 1 );
+
+  } // fi
+
+  // Interact with image
+  fpa::tests::image::Viewer< TFilter > viewer( image );
+  if( visual_debug )
+  {
+    viewer.ActivateSeedWidget( );
+    viewer.Show( );
+
+  } // fi
+
+  // Prepare weight
+  TWeight::Pointer weight = TWeight::New( );
+  weight->SetAlpha( alpha );
+  weight->SetBeta( beta );
+
+  // Prepare filter
+  TFilter::Pointer filter = TFilter::New( );
+  filter->SetInput( image );
+  filter->SetWeightFunction( weight );
+  filter->SetStopAtOneFront( stop_at_one_front );
+
+  // Get all seeds
+  for( int i = 8; i < argc; i += 2 )
+  {
+    if( i + 1 < argc )
+    {
+      TInputImage::IndexType seed;
+      seed[ 0 ] = std::atoi( argv[ i ] );
+      seed[ 1 ] = std::atoi( argv[ i + 1 ] );
+      filter->AddSeed( seed );
+
+    } // fi
+
+  } // rof
+  viewer.AssociateSeedsTo( filter );
+
+  // Prepare visual debug and update
+  if( visual_debug )
+    viewer.ObserveFilter( filter );
+  filter->Update( );
+
+  // Save results
+  std::string err1 =
+    fpa::tests::image::Write( filter->GetOutput( ), output_image_filename );
+  std::string err2 =
+    fpa::tests::image::Write( filter->GetMarks( ), output_marks_filename );
+  if( err1 != "" ) std::cerr << "Error caught: " << err1 << std::endl;
+  if( err2 != "" ) std::cerr << "Error caught: " << err2 << std::endl;
+
+  return( 0 );
+}
+
+// eof - $RCSfile$