X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=tests%2Fimage%2FRandomWalker%2FGaussian.cxx;fp=tests%2Fimage%2FRandomWalker%2FGaussian.cxx;h=be6016e5c806edc9478d60a4a1d979853bce4ffa;hb=2047276c8f1a02432fbcc7014722d460d6c1e60f;hp=0000000000000000000000000000000000000000;hpb=3c639e5da479c7216a0a302ffa156ac6762caeed;p=FrontAlgorithms.git diff --git a/tests/image/RandomWalker/Gaussian.cxx b/tests/image/RandomWalker/Gaussian.cxx new file mode 100644 index 0000000..be6016e --- /dev/null +++ b/tests/image/RandomWalker/Gaussian.cxx @@ -0,0 +1,94 @@ +// ========================================================================= +// @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 unsigned char TInputLabel; +typedef float TOutputPixel; +typedef itk::Image< TInputPixel, Dim > TInputImage; +typedef itk::Image< TInputLabel, Dim > TInputLabelImage; +typedef itk::Image< TOutputPixel, Dim > TOutputImage; + +// ------------------------------------------------------------------------- +int main( int argc, char* argv[] ) +{ + // Get arguments + if( argc < 7 ) + { + std::cerr + << "Usage: " << argv[ 0 ] + << " input_image input_labels output_image output_costs alpha beta" + << std::endl; + return( 1 ); + + } // fi + std::string input_image_filename = argv[ 1 ]; + std::string input_labels_filename = argv[ 2 ]; + std::string output_image_filename = argv[ 3 ]; + std::string output_costs_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 ); + + // Read labels + typedef itk::ImageFileReader< TInputLabelImage > TInputLabelImageReader; + TInputLabelImageReader::Pointer input_labels_reader = + TInputLabelImageReader::New( ); + input_labels_reader->SetFileName( input_labels_filename ); + + // Prepare weight functor + typedef fpa::Functors::Dijkstra::Image::Gaussian< TInputImage, TOutputPixel > TWeight; + TWeight::Pointer weight = TWeight::New( ); + weight->SetAlpha( alpha ); + weight->SetBeta( beta ); + + // Prepare filter + typedef fpa::Filters::Image::RandomWalker< TInputImage, TInputLabelImage, TOutputImage > TFilter; + TFilter::Pointer filter = TFilter::New( ); + filter->SetInputImage( input_image_reader->GetOutput( ) ); + filter->SetInputLabels( input_labels_reader->GetOutput( ) ); + filter->SetWeightFunction( weight ); + + // Execute filter + filter->Update( ); + + // Save results + typedef itk::ImageFileWriter< TFilter::TOutputLabels > TOutputWriter; + TOutputWriter::Pointer output_writer = TOutputWriter::New( ); + output_writer->SetInput( filter->GetOutputLabels( ) ); + output_writer->SetFileName( output_image_filename ); + + typedef itk::ImageFileWriter< TFilter::TCostsImage > TCostsWriter; + TCostsWriter::Pointer costs_writer = TCostsWriter::New( ); + costs_writer->SetInput( filter->GetOutputCosts( ) ); + costs_writer->SetFileName( output_costs_filename ); + + try + { + output_writer->Update( ); + costs_writer->Update( ); + } + catch( std::exception& err ) + { + std::cerr << "Error caught: " << err.what( ) << std::endl; + return( 1 ); + + } // yrt + + return( 0 ); +} + +// eof - $RCSfile$