]> 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 < 6 )
22   {
23     std::cerr
24       << "Usage: " << argv[ 0 ]
25       << " input_image labels_image output_image output_costs"
26       << " 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 beta = std::atof( argv[ 5 ] );
36
37   // Read 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   // Read label
48   TLabelImage::Pointer labels;
49   std::string err1 = fpa::tests::image::Read( labels, labels_image_filename );
50   if( err1 != "" )
51   {
52     std::cerr << "Error caught: " << err1 << std::endl;
53     return( 1 );
54
55   } // fi
56
57   // Prepare weight
58   TWeight::Pointer weight = TWeight::New( );
59   weight->SetBeta( beta );
60
61   // Prepare filter
62   TFilter::Pointer filter = TFilter::New( );
63   filter->SetInput( image );
64   filter->SetWeightFunction( weight );
65   filter->SetLabels( labels );
66
67   // Execute filter
68   try
69   {
70     filter->Update( );
71   }
72   catch( std::exception& err )
73   {
74     std::cerr << "Error caught: " << err.what( ) << std::endl;
75     return( 1 );
76
77   } // yrt
78
79   // Save results
80   std::string err2 =
81     fpa::tests::image::Write( filter->GetMarks( ), output_image_filename );
82   std::string err3 =
83     fpa::tests::image::Write( filter->GetOutput( ), output_costs_filename );
84   if( err2 != "" ) std::cerr << "Error caught: " << err2 << std::endl;
85   if( err3 != "" ) std::cerr << "Error caught: " << err3 << std::endl;
86
87   return( 0 );
88 }
89
90 // eof - $RCSfile$