X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=tests%2Fimage%2FDijkstra%2FInvert.cxx;fp=tests%2Fimage%2FDijkstra%2FInvert.cxx;h=fc0ace714e2845a2d831322b018fa973813d6e78;hb=bd89a1af0c14ed2ac0afeca923103de54283cbaf;hp=0000000000000000000000000000000000000000;hpb=a8ac405fe1422bc0792a810f7f0693096a22c20e;p=FrontAlgorithms.git diff --git a/tests/image/Dijkstra/Invert.cxx b/tests/image/Dijkstra/Invert.cxx new file mode 100644 index 0000000..fc0ace7 --- /dev/null +++ b/tests/image/Dijkstra/Invert.cxx @@ -0,0 +1,102 @@ +// ========================================================================= +// @author Leonardo Florez Valencia +// @email florez-l@javeriana.edu.co +// ========================================================================= + +#include +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +const unsigned int Dim = 2; +typedef unsigned char TInputPixel; +typedef float TOutputPixel; +typedef itk::Image< TInputPixel, Dim > TInputImage; +typedef itk::Image< TOutputPixel, Dim > TOutputImage; + +// ------------------------------------------------------------------------- +int main( int argc, char* argv[] ) +{ + // Get arguments + if( argc < 7 ) + { + std::cerr + << "Usage: " << argv[ 0 ] + << " input_image output_image output_marks output_mst alpha beta [seeds]" + << 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 ]; + std::string output_mst_filename = argv[ 4 ]; + double alpha = std::atof( argv[ 5 ] ); + double beta = std::atof( argv[ 6 ] ); + + // Read image + typedef itk::ImageFileReader< TInputImage > TInputImageReader; + TInputImageReader::Pointer input_image_reader = TInputImageReader::New( ); + input_image_reader->SetFileName( input_image_filename ); + + // Prepare weight functor + typedef fpa::Functors::Dijkstra::Invert< TOutputPixel > TWeight; + TWeight::Pointer weight = TWeight::New( ); + weight->SetAlpha( alpha ); + weight->SetBeta( beta ); + + // Prepare filter + typedef fpa::Filters::Image::Dijkstra< TInputImage, TOutputImage > TFilter; + TFilter::Pointer filter = TFilter::New( ); + filter->SetInput( input_image_reader->GetOutput( ) ); + filter->SetWeightFunction( weight ); + + // Get all seeds + for( int i = 7; i < argc; i += Dim ) + { + TInputImage::IndexType seed; + for( int j = 0; j < Dim; ++j ) + if( i + j < argc ) + seed[ j ] = std::atoi( argv[ i + j ] ); + filter->AddSeed( seed ); + + } // rof + + // Execute filter + filter->Update( ); + + // Save results + typedef itk::ImageFileWriter< TFilter::TOutputImage > TOutputWriter; + TOutputWriter::Pointer output_writer = TOutputWriter::New( ); + output_writer->SetInput( filter->GetOutput( ) ); + output_writer->SetFileName( output_image_filename ); + + typedef itk::ImageFileWriter< TFilter::TMarksImage > TMarksWriter; + TMarksWriter::Pointer marks_writer = TMarksWriter::New( ); + marks_writer->SetInput( filter->GetMarks( ) ); + marks_writer->SetFileName( output_marks_filename ); + + typedef itk::ImageFileWriter< TFilter::TMST > TMSTWriter; + TMSTWriter::Pointer mst_writer = TMSTWriter::New( ); + mst_writer->SetInput( filter->GetMinimumSpanningTree( ) ); + mst_writer->SetFileName( output_mst_filename ); + + try + { + output_writer->Update( ); + marks_writer->Update( ); + mst_writer->Update( ); + } + catch( std::exception& err ) + { + std::cerr << "Error caught: " << err.what( ) << std::endl; + return( 1 ); + + } // yrt + + return( 0 ); +} + +// eof - $RCSfile$