--- /dev/null
+#include <itkImage.h>
+#include <itkImageFileReader.h>
+#include <itkImageFileWriter.h>
+
+#include <fpa/Image/Dijkstra.h>
+#include <fpa/Image/Functors/GaussianWeight.h>
+
+// -------------------------------------------------------------------------
+static const unsigned int VDim = 2;
+typedef double TPixel;
+typedef itk::Image< TPixel, VDim > TImage;
+typedef itk::ImageFileReader< TImage > TReader;
+typedef itk::ImageFileWriter< TImage > TWriter;
+typedef fpa::Image::Dijkstra< TImage, TImage > TFilter;
+typedef fpa::Image::Functors::GaussianWeight< TImage, TPixel > TVertexFunc;
+
+// -------------------------------------------------------------------------
+int main( int argc, char* argv[] )
+{
+ // Get arguments
+ if( argc < 5 + VDim )
+ {
+ std::cerr
+ << "Usage: " << argv[ 0 ]
+ << " input_image output_image stop_at_one_front beta";
+ for( unsigned int i = 0; i < VDim; ++i )
+ std::cerr << " s_" << i;
+ std::cerr << " ..." << std::endl;
+ return( 1 );
+
+ } // fi
+ std::string input_image_filename = argv[ 1 ];
+ std::string output_image_filename = argv[ 2 ];
+ bool stop_at_one_front = ( std::atoi( argv[ 3 ] ) == 1 );
+ double beta = std::atof( argv[ 4 ] );
+
+ TReader::Pointer reader = TReader::New( );
+ reader->SetFileName( input_image_filename );
+
+ TFilter::Pointer filter = TFilter::New( );
+ filter->SetInput( reader->GetOutput( ) );
+ filter->SetStopAtOneFront( stop_at_one_front );
+
+ for( int i = 5; i < argc; i += VDim )
+ {
+ if( i + VDim <= argc )
+ {
+ TImage::IndexType seed;
+ for( int j = 0; j < VDim; ++j )
+ seed[ j ] = std::atoi( argv[ i + j ] );
+ filter->AddSeed( seed );
+
+ } // fi
+
+ } // rof
+
+ TVertexFunc::Pointer vertex_func = TVertexFunc::New( );
+ vertex_func->SetBeta( beta );
+ vertex_func->InvertOn( );
+ 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$
GenerateData( )
{
// Init objects
- this->_ConfigureOutputs( TOutputValue( 0 ) );
+ this->_ConfigureOutputs( std::numeric_limits< TOutputValue >::max( ) );
this->_InitMarks( this->GetNumberOfSeeds( ) );
TMST* mst = this->GetMinimumSpanningTree( );
// Add neighborhood
TVertices neighbors = this->_GetNeighbors( node.Vertex );
- for( TVertex neigh: neighbors )
+ typename TVertices::const_iterator neighIt = neighbors.begin( );
+ for( ; neighIt != neighbors.end( ); ++neighIt )
{
+ TVertex neigh = *neighIt;
if( this->_IsMarked( neigh ) )
{
// Invoke stop at collisions
// Complete data into minimum spanning tree
mst->ClearSeeds( );
mst->SetCollisions( this->m_Collisions );
- for( TVertex seed: this->GetSeeds( ) )
- mst->AddSeed( seed );
+ for( sIt = this->BeginSeeds( ); sIt != this->EndSeeds( ); ++sIt )
+ mst->AddSeed( *sIt );
}
#endif // __fpa__Base__Dijkstra__hxx__
fpa::Image::Functors::VertexParentBase
);
+ itkBooleanMacro( Invert );
itkGetConstMacro( Beta, double );
+ itkGetConstMacro( Invert, bool );
itkSetMacro( Beta, double );
+ itkSetMacro( Invert, bool );
public:
virtual TOutputValue Evaluate(
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 ) ) );
+ d = ( d * d ) / this->m_Beta;
+ if( this->m_Invert )
+ return( TOutputValue( double( 1 ) - std::exp( -d ) ) );
+ else
+ return( TOutputValue( std::exp( -d ) ) );
}
protected:
GaussianWeight( )
: Superclass( ),
+ m_Invert( false ),
m_Beta( double( 1 ) )
{ }
virtual ~GaussianWeight( ) { }
Self& operator=( const Self& other );
protected:
+ bool m_Invert;
double m_Beta;
};