]> Creatis software - FrontAlgorithms.git/blob - tests/image/Dijkstra_Gaussian.cxx
5622e7f28c0a8e412e13b923d0734276f0c89c21
[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 = 3;
8 typedef short 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 += 3 )
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       seed[ 2 ] = std::atoi( argv[ i + 2 ] );
67       filter->AddSeed( seed );
68
69     } // fi
70
71   } // rof
72
73   // Execute filter
74   filter->Update( );
75
76   // Save results
77   std::string err1 =
78     fpa::tests::image::Write( filter->GetOutput( ), output_image_filename );
79   std::string err2 =
80     fpa::tests::image::Write( filter->GetMarks( ), output_marks_filename );
81   if( err1 != "" ) std::cerr << "Error caught: " << err1 << std::endl;
82   if( err2 != "" ) std::cerr << "Error caught: " << err2 << std::endl;
83
84   return( 0 );
85 }
86
87 // eof - $RCSfile$