]> Creatis software - FrontAlgorithms.git/blob - tests/image/Dijkstra_Gaussian.cxx
d0461ff6bb5409ddcd015ae2ef614f2c68034e81
[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 < 8 )
21   {
22     std::cerr
23       << "Usage: " << argv[ 0 ]
24       << " input_image output_image output_marks alpha beta"
25       << " stop_at_one_front visual_debug ..."
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   bool visual_debug = ( argv[ 7 ][ 0 ] == '1' );
37
38   // Create image
39   TInputImage::Pointer image;
40   std::string err0 = fpa::tests::image::Read( image, input_image_filename );
41   if( err0 != "" )
42   {
43     std::cerr << "Error caught: " << err0 << std::endl;
44     return( 1 );
45
46   } // fi
47
48   // Interact with image
49   fpa::tests::image::Viewer< TFilter > viewer( image );
50   if( visual_debug )
51   {
52     viewer.ActivateSeedWidget( );
53     viewer.Show( );
54
55   } // fi
56
57   // Prepare weight
58   TWeight::Pointer weight = TWeight::New( );
59   weight->SetAlpha( alpha );
60   weight->SetBeta( beta );
61
62   // Prepare filter
63   TFilter::Pointer filter = TFilter::New( );
64   filter->SetInput( image );
65   filter->SetWeightFunction( weight );
66   filter->SetStopAtOneFront( stop_at_one_front );
67
68   // Get all seeds
69   for( int i = 8; i < argc; i += 2 )
70   {
71     if( i + 1 < argc )
72     {
73       TInputImage::IndexType seed;
74       seed[ 0 ] = std::atoi( argv[ i ] );
75       seed[ 1 ] = std::atoi( argv[ i + 1 ] );
76       filter->AddSeed( seed );
77
78     } // fi
79
80   } // rof
81   viewer.AssociateSeedsTo( filter );
82
83   // Prepare visual debug and update
84   if( visual_debug )
85     viewer.ObserveFilter( filter );
86   filter->Update( );
87
88   // Save results
89   std::string err1 =
90     fpa::tests::image::Write( filter->GetOutput( ), output_image_filename );
91   std::string err2 =
92     fpa::tests::image::Write( filter->GetMarks( ), output_marks_filename );
93   if( err1 != "" ) std::cerr << "Error caught: " << err1 << std::endl;
94   if( err2 != "" ) std::cerr << "Error caught: " << err2 << std::endl;
95
96   return( 0 );
97 }
98
99 // eof - $RCSfile$