1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
7 #include <tclap/CmdLine.h>
9 #include <fpa/Filters/Image/RandomWalker.h>
10 #include <fpa/Functors/Dijkstra/Image/Gaussian.h>
11 #include "Functions.h"
13 // -------------------------------------------------------------------------
14 const unsigned int Dim = 3;
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;
21 // -------------------------------------------------------------------------
22 int main( int argc, char* argv[] )
24 typedef TCLAP::ValueArg< std::string > _TStringArg;
25 typedef TCLAP::ValueArg< TScalar > _TRealArg;
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)" );
35 TCLAP::CmdLine cmd( "FastRandomWalker", ' ', "1.0.0" );
41 cmd.parse( argc, argv );
43 catch( TCLAP::ArgException& err )
46 << "===============================" << std::endl
47 << "Error caught: " << std::endl
48 << err.error( ) << " " << err.argId( ) << std::endl
49 << "===============================" << std::endl
58 TImage::Pointer input_image;
59 CTBronchi::ReadImage( input_image, in.getValue( ) );
62 TLabels::Pointer input_labels;
63 CTBronchi::ReadImage( input_labels, labels.getValue( ) );
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( ) );
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;
81 CTBronchi::WriteImage( filter->GetOutputLabels( ), out.getValue( ) );
83 catch( std::exception& err )
86 << "===============================" << std::endl
87 << "Error caught: " << std::endl
88 << err.what( ) << std::endl
89 << "===============================" << std::endl