]> Creatis software - FrontAlgorithms.git/commitdiff
...
authorLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Sat, 25 Mar 2017 01:25:46 +0000 (20:25 -0500)
committerLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Sat, 25 Mar 2017 01:25:46 +0000 (20:25 -0500)
examples/CMakeLists.txt
examples/sandbox.cxx [new file with mode: 0644]
libs/fpa/Image/Dijkstra.h
libs/fpa/Image/Functors/GaussianWeight.h [new file with mode: 0644]

index 297746a359eea3a2f597ff25fe16789583739238..2bed4e539017b74d308ad932155737162d896e3e 100644 (file)
@@ -10,6 +10,10 @@ IF(BUILD_EXAMPLES)
     #BronchiiInitialSegmentationWithMori
     #BronchiiInitialSegmentationWithBinaryThresholdRegionGrow
     )
+  OPTION(BUILD_EXAMPLE_SANDBOX "Build sandbox example." OFF)
+  IF(BUILD_EXAMPLE_SANDBOX)
+    LIST(APPEND _examples sandbox)
+  ENDIF(BUILD_EXAMPLE_SANDBOX)
   INCLUDE_DIRECTORIES(
     ${PROJECT_SOURCE_DIR}/libs
     ${PROJECT_BINARY_DIR}/libs
diff --git a/examples/sandbox.cxx b/examples/sandbox.cxx
new file mode 100644 (file)
index 0000000..d27bea9
--- /dev/null
@@ -0,0 +1,113 @@
+#include <itkImage.h>
+#include <itkImageFileReader.h>
+#include <itkImageFileWriter.h>
+#include <itkMinimumMaximumImageCalculator.h>
+#include <itkImageRegionConstIteratorWithIndex.h>
+
+#include <fpa/Image/Dijkstra.h>
+#include <fpa/Image/Functors/GaussianWeight.h>
+
+// -------------------------------------------------------------------------
+static const unsigned int VDim = 2;
+typedef short                                        TPixel;
+typedef double                                       TScalar;
+typedef itk::Image< TPixel, VDim >                   TImage;
+typedef itk::Image< TScalar, VDim >                  TScalarImage;
+typedef itk::ImageFileReader< TImage >               TReader;
+typedef itk::ImageFileWriter< TScalarImage >         TWriter;
+typedef fpa::Image::Dijkstra< TImage, TScalarImage > TFilter;
+typedef itk::MinimumMaximumImageCalculator< TImage > TMinMax;
+typedef itk::ImageRegionConstIteratorWithIndex< TImage > TIterator;
+
+typedef fpa::Image::Functors::GaussianWeight< TImage, TScalar > TVertexFunc;
+
+// -------------------------------------------------------------------------
+int main( int argc, char* argv[] )
+{
+  // Get arguments
+  if( argc < 5 )
+  {
+    std::cerr
+      << "Usage: " << argv[ 0 ]
+      << " input_image input_seeds output_image beta"
+      << std::endl;
+    return( 1 );
+
+  } // fi
+  std::string input_image_filename = argv[ 1 ];
+  std::string input_seeds_filename = argv[ 2 ];
+  std::string output_image_filename = argv[ 3 ];
+  double beta = std::atof( argv[ 4 ] );
+
+  // Read seeds
+  TReader::Pointer input_seeds = TReader::New( );
+  input_seeds->SetFileName( input_seeds_filename );
+  try
+  {
+    input_seeds->Update( );
+  }
+  catch( std::exception& err )
+  {
+    std::cerr << "Error: " << err.what( ) << std::endl;
+    return( 1 );
+
+  } // yrt
+  TMinMax::Pointer minmax = TMinMax::New( );
+  minmax->SetImage( input_seeds->GetOutput( ) );
+  minmax->Compute( );
+
+  // Read image
+  TReader::Pointer input_image = TReader::New( );
+  input_image->SetFileName( input_image_filename );
+
+  // Prepare dijkstra filter
+  TFilter::Pointer filter = TFilter::New( );
+  filter->SetInput( input_image->GetOutput( ) );
+  filter->StopAtOneFrontOff( );
+
+  // Assign seeds
+  /* TODO
+     TIterator sIt(
+     input_seeds->GetOutput( ),
+     input_seeds->GetOutput( )->GetRequestedRegion( )
+     );
+     for( sIt.GoToBegin( ); !sIt.IsAtEnd( ); ++sIt )
+     if( sIt.Get( ) > minmax->GetMinimum( ) )
+     filter->AddSeed( sIt.GetIndex( ) );
+  */
+  TImage::IndexType seed;
+  /* TODO
+     seed[ 0 ] = 248;
+     seed[ 1 ] = 326;
+     seed[ 2 ] = 312;
+  */
+  seed[ 0 ] = 482;
+  seed[ 1 ] = 57;
+  filter->AddSeed( seed );
+
+  seed[ 0 ] = 306;
+  seed[ 1 ] = 439;
+  filter->AddSeed( seed );
+
+  TVertexFunc::Pointer vertex_func = TVertexFunc::New( );
+  vertex_func->SetBeta( beta );
+  filter->SetFunctor( vertex_func );
+
+  TWriter::Pointer writer = TWriter::New( );
+  writer->SetInput( filter->GetOutput( ) );
+  writer->SetFileName( output_image_filename );
+
+  try
+  {
+    writer->Update( );
+  }
+  catch( std::exception& err )
+  {
+    std::cerr << "ERROR: " << err.what( ) << std::endl;
+    return( 1 );
+
+  } // yrt
+  return( 0 );
+}
+
+// eof - $RCSfile$
index 8516d7bbc408bafd69055deb96ca7e567cca2794..1df0836a985668ee3f0f526144b63d80f8e2d7f8 100644 (file)
@@ -65,7 +65,6 @@ namespace fpa
       virtual void GenerateData( ) override
         {
           // Configure functors with input image
-          typedef typename TFilter::TInputImage  _TInputIage;
           typedef typename TFilter::TOutputValue _TOutputValue;
           typedef fpa::Image::Functors::VertexParentBase< _TInputImage, _TOutputValue > _TVFunc;
           _TVFunc* vfunc =
diff --git a/libs/fpa/Image/Functors/GaussianWeight.h b/libs/fpa/Image/Functors/GaussianWeight.h
new file mode 100644 (file)
index 0000000..3b2212a
--- /dev/null
@@ -0,0 +1,78 @@
+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
+
+#ifndef __fpa__Image__Functors__GaussianWeight__h__
+#define __fpa__Image__Functors__GaussianWeight__h__
+
+#include <fpa/Image/Functors/VertexParentBase.h>
+#include <cmath>
+
+namespace fpa
+{
+  namespace Image
+  {
+    namespace Functors
+    {
+      /**
+       */
+      template< class _TInputImage, class _TOutputValue >
+      class GaussianWeight
+        : public fpa::Image::Functors::VertexParentBase< _TInputImage, _TOutputValue >
+      {
+      public:
+        typedef _TInputImage                    TInputImage;
+        typedef _TOutputValue                   TOutputValue;
+        typedef GaussianWeight                  Self;
+        typedef itk::SmartPointer< Self >       Pointer;
+        typedef itk::SmartPointer< const Self > ConstPointer;
+        typedef fpa::Image::Functors::VertexParentBase< TInputImage, TOutputValue > Superclass;
+
+        typedef typename Superclass::TVertex TVertex;
+
+      public:
+        itkNewMacro( Self );
+        itkTypeMacro(
+          fpa::Image::Functors::GaussianWeight,
+          fpa::Image::Functors::VertexParentBase
+          );
+
+        itkGetConstMacro( Beta, double );
+        itkSetMacro( Beta, double );
+
+      public:
+        virtual TOutputValue Evaluate(
+          const TVertex& a, const TVertex& p
+          ) const override
+          {
+            double va = double( this->m_Image->GetPixel( a ) );
+            double vp = double( this->m_Image->GetPixel( p ) );
+            double d = va - vp;
+            return( TOutputValue( std::exp( -d * d * this->m_Beta ) ) );
+          }
+
+      protected:
+        GaussianWeight( )
+          : Superclass( ),
+            m_Beta( double( 1 ) )
+          { }
+        virtual ~GaussianWeight( ) { }
+
+      private:
+        GaussianWeight( const Self& other );
+        Self& operator=( const Self& other );
+
+      protected:
+        double m_Beta;
+      };
+
+    } // ecapseman
+
+  } // ecapseman
+
+} // ecapseman
+
+#endif // __fpa__Image__Functors__GaussianWeight__h__
+
+// eof - $RCSfile$