]> Creatis software - FrontAlgorithms.git/blob - tests/image/RandomWalker.cxx
...
[FrontAlgorithms.git] / tests / image / RandomWalker.cxx
1 #include "BaseFunctions.h"
2 #include <itkImage.h>
3 #include <fpa/Image/RandomWalker.h>
4 #include <fpa/Image/Functors/Dijkstra/Gaussian.h>
5
6 // -------------------------------------------------------------------------
7 const unsigned int Dim = 2;
8 typedef short         TPixel;
9 typedef unsigned char TLabel;
10 typedef float         TScalar;
11
12 typedef itk::Image< TPixel, Dim >                                    TInputImage;
13 typedef itk::Image< TLabel, Dim >                                    TLabelImage;
14 typedef fpa::Image::RandomWalker< TInputImage, TLabelImage, TScalar >    TFilter;
15 typedef fpa::Image::Functors::Dijkstra::Gaussian< TInputImage, TScalar > TWeight;
16
17 // -------------------------------------------------------------------------
18 int main( int argc, char* argv[] )
19 {
20   // Get arguments
21   if( argc < 7 )
22   {
23     std::cerr
24       << "Usage: " << argv[ 0 ]
25       << " input_image labels_image output_image output_costs"
26       << " alpha beta"
27       << std::endl;
28     return( 1 );
29
30   } // fi
31   std::string input_image_filename = argv[ 1 ];
32   std::string labels_image_filename = argv[ 2 ];
33   std::string output_image_filename = argv[ 3 ];
34   std::string output_costs_filename = argv[ 4 ];
35   double alpha = std::atof( argv[ 5 ] );
36   double beta = std::atof( argv[ 6 ] );
37
38   // Read 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   // Read label
49   TLabelImage::Pointer labels;
50   std::string err1 = fpa::tests::image::Read( labels, labels_image_filename );
51   if( err1 != "" )
52   {
53     std::cerr << "Error caught: " << err1 << std::endl;
54     return( 1 );
55
56   } // fi
57
58   // Prepare weight
59   TWeight::Pointer weight = TWeight::New( );
60   weight->SetAlpha( alpha );
61   weight->SetBeta( beta );
62
63   // Prepare filter
64   TFilter::Pointer filter = TFilter::New( );
65   filter->SetInput( image );
66   filter->SetWeightFunction( weight );
67   filter->SetLabels( labels );
68
69   // Execute filter
70   try
71   {
72     filter->Update( );
73   }
74   catch( std::exception& err )
75   {
76     std::cerr << "Error caught: " << err.what( ) << std::endl;
77     return( 1 );
78
79   } // yrt
80
81   // Save results
82   std::string err2 =
83     fpa::tests::image::Write( filter->GetMarks( ), output_image_filename );
84   std::string err3 =
85     fpa::tests::image::Write( filter->GetOutput( ), output_costs_filename );
86   if( err2 != "" ) std::cerr << "Error caught: " << err2 << std::endl;
87   if( err3 != "" ) std::cerr << "Error caught: " << err3 << std::endl;
88
89   return( 0 );
90 }
91
92 // eof - $RCSfile$