]> Creatis software - FrontAlgorithms.git/commitdiff
...
authorLeonardo Flórez-Valencia <leonardo.florez@gmail.com>
Thu, 6 Jul 2017 04:22:31 +0000 (23:22 -0500)
committerLeonardo Flórez-Valencia <leonardo.florez@gmail.com>
Thu, 6 Jul 2017 04:22:31 +0000 (23:22 -0500)
tests/image/CMakeLists.txt
tests/image/RegionGrow_BinaryThreshold.cxx [new file with mode: 0644]

index ac3f2f6ee49c9f90df48631229d8b1e96abba510..06dfae81eb9b9f8cdc63ce7e6282f121d55078d0 100644 (file)
@@ -2,6 +2,7 @@ set(_pfx test_fpa_image_)
 set(
   _examples
   RegionGrow_Tautology
+  RegionGrow_BinaryThreshold
   MoriSegmentation
   #  Dijkstra_Identity
   #  Dijkstra_Gaussian
diff --git a/tests/image/RegionGrow_BinaryThreshold.cxx b/tests/image/RegionGrow_BinaryThreshold.cxx
new file mode 100644 (file)
index 0000000..b40f25a
--- /dev/null
@@ -0,0 +1,91 @@
+#include "BaseFunctions.h"
+#include <itkImage.h>
+#include <fpa/Image/RegionGrow.h>
+#include <fpa/Base/Functors/RegionGrow/BinaryThreshold.h>
+
+// -------------------------------------------------------------------------
+const unsigned int Dim = 3;
+typedef short         TInputPixel;
+typedef unsigned char TOutputPixel;
+
+typedef itk::Image< TInputPixel, Dim >                      TInputImage;
+typedef itk::Image< TOutputPixel, Dim >                     TOutputImage;
+typedef fpa::Image::RegionGrow< TInputImage, TOutputImage > TFilter;
+typedef fpa::Base::Functors::RegionGrow::BinaryThreshold< TInputPixel > TPredicate;
+
+// -------------------------------------------------------------------------
+int main( int argc, char* argv[] )
+{
+  // Get arguments
+  if( argc < 8 + Dim )
+  {
+    std::cerr
+      << "Usage: " << argv[ 0 ]
+      << " input_image output_image output_marks"
+      << " lower upper strict [index/point] ..."
+      << 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 ];
+  TInputPixel lower = TInputPixel( std::atof( argv[ 4 ] ) );
+  TInputPixel upper = TInputPixel( std::atof( argv[ 5 ] ) );
+  bool strict = ( argv[ 6 ][ 0 ] == '1' );
+  std::string seeds_type = argv[ 7 ];
+
+  // Create image
+  TInputImage::Pointer input_image;
+  std::string err0 =
+    fpa::tests::image::Read( input_image, input_image_filename );
+  if( err0 != "" ) std::cerr << err0 << std::endl;
+
+  // Prepare predicate
+  TPredicate::Pointer predicate = TPredicate::New( );
+  predicate->SetLower( lower );
+  predicate->SetUpper( upper );
+  predicate->SetStrict( strict );
+
+  // Prepare filter
+  TFilter::Pointer filter = TFilter::New( );
+  filter->SetInput( input_image );
+  filter->SetPredicate( predicate );
+  filter->SetInsideValue( 255 );
+  filter->SetOutsideValue( 0 );
+
+  // Get all seeds
+  for( int i = 8; i < argc; i += Dim )
+  {
+    if( seeds_type == "index" )
+    {
+      TInputImage::IndexType seed;
+      for( unsigned int d = 0; d < Dim; ++d )
+        seed[ d ] = std::atoi( argv[ i + d ] );
+      filter->AddSeed( seed );
+    }
+    else
+    {
+      TInputImage::PointType seed;
+      for( unsigned int d = 0; d < Dim; ++d )
+        seed[ d ] = std::atof( argv[ i + d ] );
+      filter->AddSeed( seed );
+
+    } // fi
+  } // rof
+
+  // Execute 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 << err1 << std::endl;
+  if( err2 != "" ) std::cerr << err2 << std::endl;
+
+  return( 0 );
+}
+
+// eof - $RCSfile$