]> Creatis software - FrontAlgorithms.git/blob - examples/Dijkstra_Gaussian.cxx
7befb2bf8d094badccca01ed8d8b27155a1001a5
[FrontAlgorithms.git] / examples / Dijkstra_Gaussian.cxx
1 #include <itkImage.h>
2 #include <itkImageFileReader.h>
3 #include <itkImageFileWriter.h>
4
5 #include <fpa/Image/Dijkstra.h>
6 #include <fpa/Image/Functors/GaussianWeight.h>
7
8 // -------------------------------------------------------------------------
9 static const unsigned int VDim = 2;
10 typedef double                                                 TPixel;
11 typedef itk::Image< TPixel, VDim >                             TImage;
12 typedef itk::ImageFileReader< TImage >                         TReader;
13 typedef itk::ImageFileWriter< TImage >                         TWriter;
14 typedef fpa::Image::Dijkstra< TImage, TImage >                 TFilter;
15 typedef fpa::Image::Functors::GaussianWeight< TImage, TPixel > TVertexFunc;
16
17 // -------------------------------------------------------------------------
18 int main( int argc, char* argv[] )
19 {
20   // Get arguments
21   if( argc < 5 + VDim )
22   {
23     std::cerr
24       << "Usage: " << argv[ 0 ]
25       << " input_image output_image stop_at_one_front beta";
26     for( unsigned int i = 0; i < VDim; ++i )
27       std::cerr << " s_" << i;
28     std::cerr << " ..." << std::endl;
29     return( 1 );
30
31   } // fi
32   std::string input_image_filename = argv[ 1 ];
33   std::string output_image_filename = argv[ 2 ];
34   bool stop_at_one_front = ( std::atoi( argv[ 3 ] ) == 1 );
35   double beta = std::atof( argv[ 4 ] );
36
37   TReader::Pointer reader = TReader::New( );
38   reader->SetFileName( input_image_filename );
39
40   TFilter::Pointer filter = TFilter::New( );
41   filter->SetInput( reader->GetOutput( ) );
42   filter->SetStopAtOneFront( stop_at_one_front );
43
44   for( int i = 5; i < argc; i += VDim )
45   {
46     if( i + VDim <= argc )
47     {
48       TImage::IndexType seed;
49       for( int j = 0; j < VDim; ++j )
50         seed[ j ] = std::atoi( argv[ i + j ] );
51       filter->AddSeed( seed );
52
53     } // fi
54
55   } // rof
56
57   TVertexFunc::Pointer vertex_func = TVertexFunc::New( );
58   vertex_func->SetBeta( beta );
59   vertex_func->InvertOn( );
60   filter->SetFunctor( vertex_func );
61
62   TWriter::Pointer writer = TWriter::New( );
63   writer->SetInput( filter->GetOutput( ) );
64   writer->SetFileName( output_image_filename );
65
66   try
67   {
68     writer->Update( );
69   }
70   catch( std::exception& err )
71   {
72     std::cerr << "ERROR: " << err.what( ) << std::endl;
73     return( 1 );
74
75   } // yrt
76   return( 0 );
77 }
78
79 // eof - $RCSfile$