]> Creatis software - FrontAlgorithms.git/blob - appli/CTBronchi/FastRandomWalker.cxx
...
[FrontAlgorithms.git] / appli / CTBronchi / FastRandomWalker.cxx
1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5
6 #include <string>
7 #include <tclap/CmdLine.h>
8 #include <itkImage.h>
9 #include <fpa/Filters/Image/RandomWalker.h>
10 #include <fpa/Functors/Dijkstra/Image/Gaussian.h>
11 #include "Functions.h"
12
13 // -------------------------------------------------------------------------
14 const unsigned int Dim = 3;
15 typedef short                                  TPixel;
16 typedef unsigned char                          TLabel;
17 typedef itk::NumericTraits< TPixel >::RealType TScalar;
18 typedef itk::Image< TPixel, Dim >              TImage;
19 typedef itk::Image< TLabel, Dim >              TLabels;
20
21 // -------------------------------------------------------------------------
22 int main( int argc, char* argv[] )
23 {
24   typedef TCLAP::ValueArg< std::string > _TStringArg;
25   typedef TCLAP::ValueArg< TScalar > _TRealArg;
26
27   // Parse input line
28   _TStringArg in( "i", "input", "Input image", true, "", "file" );
29   _TStringArg labels( "l", "labels", "Input labels", true, "", "file" );
30   _TStringArg out( "o", "output", "Output image", true, "", "file" );
31   _TRealArg beta( "b", "beta", "Beta", false, 2.5, "value (2.5)" );
32   _TRealArg eps( "e", "epsilon", "Epsilon", false, 1e-5, "value (1e-5)" );
33   try
34   {
35     TCLAP::CmdLine cmd( "FastRandomWalker", ' ', "1.0.0" );
36     cmd.add( eps );
37     cmd.add( beta );
38     cmd.add( out );
39     cmd.add( labels );
40     cmd.add( in );
41     cmd.parse( argc, argv );
42   }
43   catch( TCLAP::ArgException& err )
44   {
45     std::cerr
46       << "===============================" << std::endl
47       << "Error caught: " << std::endl
48       << err.error( ) << " " << err.argId( ) << std::endl
49       << "===============================" << std::endl
50       << std::endl;
51     return( 1 );
52
53   } // yrt
54
55   try
56   {
57     // Read input image
58     TImage::Pointer input_image;
59     CTBronchi::ReadImage( input_image, in.getValue( ) );
60
61     // Read input labels
62     TLabels::Pointer input_labels;
63     CTBronchi::ReadImage( input_labels, labels.getValue( ) );
64
65     // Prepare weight functor
66     typedef fpa::Functors::Dijkstra::Image::Gaussian< TImage, TScalar > TWeight;
67     TWeight::Pointer weight = TWeight::New( );
68     weight->SetBeta( beta.getValue( ) );
69     weight->SetEpsilon( eps.getValue( ) );
70
71     // Random walk
72     typedef fpa::Filters::Image::RandomWalker< TImage, TLabels, TScalar > TFilter;
73     TFilter::Pointer filter = TFilter::New( );
74     filter->SetInputImage( input_image );
75     filter->SetInputLabels( input_labels );
76     filter->SetWeightFunction( weight );
77     double t = CTBronchi::MeasureTime( filter );
78     std::cout << "FastRandomWalk executed in " << t << " s" << std::endl;
79
80     // Write result
81     CTBronchi::WriteImage( filter->GetOutputLabels( ), out.getValue( ) );
82   }
83   catch( std::exception& err )
84   {
85     std::cerr
86       << "===============================" << std::endl
87       << "Error caught: " << std::endl
88       << err.what( ) << std::endl
89       << "===============================" << std::endl
90       << std::endl;
91     return( 1 );
92
93   } // yrt
94   return( 0 );
95 }
96
97 // eof - $RCSfile$