--- /dev/null
+#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$
--- /dev/null
+// =========================================================================
+// @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$