X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=examples%2FDijkstra_Gaussian.cxx;fp=examples%2FDijkstra_Gaussian.cxx;h=7befb2bf8d094badccca01ed8d8b27155a1001a5;hb=e82144a4e9fb907de430c8aca4b92577a81033fb;hp=0000000000000000000000000000000000000000;hpb=4a3722c8e245ff242e8e253a8c1704db53f21c77;p=FrontAlgorithms.git diff --git a/examples/Dijkstra_Gaussian.cxx b/examples/Dijkstra_Gaussian.cxx new file mode 100644 index 0000000..7befb2b --- /dev/null +++ b/examples/Dijkstra_Gaussian.cxx @@ -0,0 +1,79 @@ +#include +#include +#include + +#include +#include + +// ------------------------------------------------------------------------- +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$