1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
7 #include <itkImageFileReader.h>
8 #include <itkImageFileWriter.h>
9 #include <fpa/Filters/Image/Dijkstra.h>
10 #include <fpa/Functors/Dijkstra/Invert.h>
12 // -------------------------------------------------------------------------
13 const unsigned int Dim = 2;
14 typedef unsigned char TInputPixel;
15 typedef float TOutputPixel;
16 typedef itk::Image< TInputPixel, Dim > TInputImage;
17 typedef itk::Image< TOutputPixel, Dim > TOutputImage;
19 // -------------------------------------------------------------------------
20 int main( int argc, char* argv[] )
26 << "Usage: " << argv[ 0 ]
27 << " input_image output_image output_marks output_mst alpha beta [seeds]"
32 std::string input_image_filename = argv[ 1 ];
33 std::string output_image_filename = argv[ 2 ];
34 std::string output_marks_filename = argv[ 3 ];
35 std::string output_mst_filename = argv[ 4 ];
36 double alpha = std::atof( argv[ 5 ] );
37 double beta = std::atof( argv[ 6 ] );
40 typedef itk::ImageFileReader< TInputImage > TInputImageReader;
41 TInputImageReader::Pointer input_image_reader = TInputImageReader::New( );
42 input_image_reader->SetFileName( input_image_filename );
44 // Prepare weight functor
45 typedef fpa::Functors::Dijkstra::Invert< TOutputPixel > TWeight;
46 TWeight::Pointer weight = TWeight::New( );
47 weight->SetAlpha( alpha );
48 weight->SetBeta( beta );
51 typedef fpa::Filters::Image::Dijkstra< TInputImage, TOutputImage > TFilter;
52 TFilter::Pointer filter = TFilter::New( );
53 filter->SetInput( input_image_reader->GetOutput( ) );
54 filter->SetWeightFunction( weight );
57 for( int i = 7; i < argc; i += Dim )
59 TInputImage::IndexType seed;
60 for( int j = 0; j < Dim; ++j )
62 seed[ j ] = std::atoi( argv[ i + j ] );
63 filter->AddSeed( seed );
71 typedef itk::ImageFileWriter< TFilter::TOutputImage > TOutputWriter;
72 TOutputWriter::Pointer output_writer = TOutputWriter::New( );
73 output_writer->SetInput( filter->GetOutput( ) );
74 output_writer->SetFileName( output_image_filename );
76 typedef itk::ImageFileWriter< TFilter::TMarksImage > TMarksWriter;
77 TMarksWriter::Pointer marks_writer = TMarksWriter::New( );
78 marks_writer->SetInput( filter->GetMarks( ) );
79 marks_writer->SetFileName( output_marks_filename );
81 typedef itk::ImageFileWriter< TFilter::TMST > TMSTWriter;
82 TMSTWriter::Pointer mst_writer = TMSTWriter::New( );
83 mst_writer->SetInput( filter->GetMinimumSpanningTree( ) );
84 mst_writer->SetFileName( output_mst_filename );
88 output_writer->Update( );
89 marks_writer->Update( );
90 mst_writer->Update( );
92 catch( std::exception& err )
94 std::cerr << "Error caught: " << err.what( ) << std::endl;