1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
7 #include <itkImageFileWriter.h>
8 #include <fpa/Filters/Image/Dijkstra.h>
10 // -------------------------------------------------------------------------
11 const unsigned int Dim = 2;
12 typedef unsigned char TInputPixel;
13 typedef float TOutputPixel;
14 typedef itk::Image< TInputPixel, Dim > TInputImage;
15 typedef itk::Image< TOutputPixel, Dim > TOutputImage;
17 // -------------------------------------------------------------------------
18 int main( int argc, char* argv[] )
24 << "Usage: " << argv[ 0 ]
25 << " output_image output_marks output_mst size [seeds]"
30 std::string output_image_filename = argv[ 1 ];
31 std::string output_marks_filename = argv[ 2 ];
32 std::string output_mst_filename = argv[ 3 ];
33 TInputImage::SizeType size;
34 size.Fill( std::atoi( argv[ 4 ] ) );
37 TInputImage::Pointer image = TInputImage::New( );
38 image->SetRegions( size );
40 image->FillBuffer( TInputPixel( 1 ) );
43 typedef fpa::Filters::Image::Dijkstra< TInputImage, TOutputImage > TFilter;
44 TFilter::Pointer filter = TFilter::New( );
45 filter->SetInput( image );
48 for( int i = 5; i < argc; i += Dim )
50 TInputImage::IndexType seed;
51 for( int j = 0; j < Dim; ++j )
53 seed[ j ] = std::atoi( argv[ i + j ] );
54 filter->AddSeed( seed );
62 typedef itk::ImageFileWriter< TFilter::TOutputImage > TOutputWriter;
63 TOutputWriter::Pointer output_writer = TOutputWriter::New( );
64 output_writer->SetInput( filter->GetOutput( ) );
65 output_writer->SetFileName( output_image_filename );
67 typedef itk::ImageFileWriter< TFilter::TMarksImage > TMarksWriter;
68 TMarksWriter::Pointer marks_writer = TMarksWriter::New( );
69 marks_writer->SetInput( filter->GetMarks( ) );
70 marks_writer->SetFileName( output_marks_filename );
72 typedef itk::ImageFileWriter< TFilter::TMST > TMSTWriter;
73 TMSTWriter::Pointer mst_writer = TMSTWriter::New( );
74 mst_writer->SetInput( filter->GetMinimumSpanningTree( ) );
75 mst_writer->SetFileName( output_mst_filename );
79 output_writer->Update( );
80 marks_writer->Update( );
81 mst_writer->Update( );
83 catch( std::exception& err )
85 std::cerr << "Error caught: " << err.what( ) << std::endl;