]> Creatis software - FrontAlgorithms.git/blob - tests/image/Dijkstra_Gaussian.cxx
...
[FrontAlgorithms.git] / tests / image / Dijkstra_Gaussian.cxx
1 #include "BaseFunctions.h"
2 #include <itkImage.h>
3 #include <fpa/Image/Dijkstra.h>
4 #include <fpa/Image/Functors/Dijkstra/Gaussian.h>
5
6 // -------------------------------------------------------------------------
7 const unsigned int Dim = 2;
8 typedef unsigned char TPixel;
9 typedef float         TScalar;
10
11 typedef itk::Image< TPixel, Dim >                                    TInputImage;
12 typedef itk::Image< TScalar, Dim >                                  TScalarImage;
13 typedef fpa::Image::Dijkstra< TInputImage, TScalarImage >                TFilter;
14 typedef fpa::Image::Functors::Dijkstra::Gaussian< TInputImage, TScalar > TWeight;
15
16 // -------------------------------------------------------------------------
17 int main( int argc, char* argv[] )
18 {
19   // Get arguments
20   if( argc < 7 )
21   {
22     std::cerr
23       << "Usage: " << argv[ 0 ]
24       << " input_image output_image output_marks alpha beta"
25       << " stop_at_one_front ..."
26       << std::endl;
27     return( 1 );
28
29   } // fi
30   std::string input_image_filename = argv[ 1 ];
31   std::string output_image_filename = argv[ 2 ];
32   std::string output_marks_filename = argv[ 3 ];
33   double alpha = std::atoi( argv[ 4 ] );
34   double beta = std::atoi( argv[ 5 ] );
35   bool stop_at_one_front = ( argv[ 6 ][ 0 ] == '1' );
36
37   // Create image
38   TInputImage::Pointer image;
39   std::string err0 = fpa::tests::image::Read( image, input_image_filename );
40   if( err0 != "" )
41   {
42     std::cerr << "Error caught: " << err0 << std::endl;
43     return( 1 );
44
45   } // fi
46
47   // Prepare weight
48   TWeight::Pointer weight = TWeight::New( );
49   weight->SetAlpha( alpha );
50   weight->SetBeta( beta );
51
52   // Prepare filter
53   TFilter::Pointer filter = TFilter::New( );
54   filter->SetInput( image );
55   filter->SetWeightFunction( weight );
56   filter->SetStopAtOneFront( stop_at_one_front );
57
58   // Get all seeds
59   for( int i = 7; i < argc; i += 2 )
60   {
61     if( i + 1 < argc )
62     {
63       TInputImage::IndexType seed;
64       seed[ 0 ] = std::atoi( argv[ i ] );
65       seed[ 1 ] = std::atoi( argv[ i + 1 ] );
66       filter->AddSeed( seed );
67
68     } // fi
69
70   } // rof
71
72   // Execute filter
73   filter->Update( );
74
75   // Save results
76   std::string err1 =
77     fpa::tests::image::Write( filter->GetOutput( ), output_image_filename );
78   std::string err2 =
79     fpa::tests::image::Write( filter->GetMarks( ), output_marks_filename );
80   if( err1 != "" ) std::cerr << "Error caught: " << err1 << std::endl;
81   if( err2 != "" ) std::cerr << "Error caught: " << err2 << std::endl;
82
83   return( 0 );
84 }
85
86 // eof - $RCSfile$