]> Creatis software - FrontAlgorithms.git/blob - appli/CTBronchi/SliceBySliceRandomWalker.cxx
...
[FrontAlgorithms.git] / appli / CTBronchi / SliceBySliceRandomWalker.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/Common/SliceBySliceRandomWalker.h>
10 #include "Functions.h"
11
12 // -------------------------------------------------------------------------
13 const unsigned int Dim = 3;
14 typedef short                                  TPixel;
15 typedef unsigned char                          TLabel;
16 typedef itk::NumericTraits< TPixel >::RealType TScalar;
17 typedef itk::Image< TPixel, Dim >              TImage;
18 typedef itk::Image< TLabel, Dim >              TLabels;
19 typedef itk::Image< TScalar, Dim >             TScalarImage;
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 vesselness( "v", "vesselness", "Input vesselness", true, "", "file" );
31   _TStringArg out( "o", "output", "Output image", true, "", "file" );
32   _TRealArg beta( "b", "beta", "Beta", false, 2.5, "value (2.5)" );
33   _TRealArg eps( "e", "epsilon", "Epsilon", false, 1e-5, "value (1e-5)" );
34   _TRealArg vThr( "t", "vthreshold", "Vesselness thresnold (%)", false, 5, "value (5)" );
35   try
36   {
37     TCLAP::CmdLine cmd( "FastRandomWalker", ' ', "1.0.0" );
38     cmd.add( eps );
39     cmd.add( vThr );
40     cmd.add( beta );
41     cmd.add( out );
42     cmd.add( vesselness );
43     cmd.add( labels );
44     cmd.add( in );
45     cmd.parse( argc, argv );
46   }
47   catch( TCLAP::ArgException& err )
48   {
49     std::cerr
50       << "===============================" << std::endl
51       << "Error caught: " << std::endl
52       << err.error( ) << " " << err.argId( ) << std::endl
53       << "===============================" << std::endl
54       << std::endl;
55     return( 1 );
56
57   } // yrt
58
59   try
60   {
61     // Read input image
62     TImage::Pointer input_image;
63     CTBronchi::ReadImage( input_image, in.getValue( ) );
64
65     // Read input labels
66     TLabels::Pointer input_labels;
67     CTBronchi::ReadImage( input_labels, labels.getValue( ) );
68
69     // Read input vesselness
70     TScalarImage::Pointer input_vesselness;
71     CTBronchi::ReadImage( input_vesselness, vesselness.getValue( ) );
72
73     // Random walk
74     typedef fpa::Common::SliceBySliceRandomWalker< TImage, TLabels, TScalarImage > TFilter;
75     TFilter::Pointer filter = TFilter::New( );
76     filter->SetInput( input_image );
77     filter->SetInputLabels( input_labels );
78     filter->SetInputVesselness( input_vesselness );
79     filter->SetBeta( beta.getValue( ) );
80     filter->SetVesselnessThreshold( vThr.getValue( ) );
81     filter->SetEpsilon( eps.getValue( ) );
82     double t = CTBronchi::MeasureTime( filter );
83     std::cout
84       << "SliceBySliceRandomWalker executed in "
85       << t << " s" << std::endl;
86
87     // Write result
88     CTBronchi::WriteImage( filter->GetOutput( ), out.getValue( ) );
89   }
90   catch( std::exception& err )
91   {
92     std::cerr
93       << "===============================" << std::endl
94       << "Error caught: " << std::endl
95       << err.what( ) << std::endl
96       << "===============================" << std::endl
97       << std::endl;
98     return( 1 );
99
100   } // yrt
101   return( 0 );
102 }
103
104 // eof - $RCSfile$