]> Creatis software - FrontAlgorithms.git/blob - appli/CTBronchi/MoriLabelling.cxx
b2c901baf8fd06f980b2eec9142cad55bc16290c
[FrontAlgorithms.git] / appli / CTBronchi / MoriLabelling.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 "MoriLabelling.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< double > _TRealArg;
26   typedef TCLAP::ValueArg< TPixel > _TPixelArg;
27
28   // Parse input line
29   _TStringArg in( "i", "input", "Input image", true, "", "file" );
30   _TStringArg labels( "l", "labels", "Input labels", true, "", "file" );
31   _TStringArg vesselness( "v", "vesselness", "Input vesselness", true, "", "file" );
32   _TStringArg out( "o", "output", "Output image", true, "", "file" );
33   _TRealArg vThr( "a", "vesselness_thr", "Vesselness threshold", false, 0.05, "value (0.05)" );
34   _TPixelArg uThr( "u", "upper_thr", "Upper threshold", false, -400, "value (-400)" );
35   try
36   {
37     TCLAP::CmdLine cmd( "Labelling", ' ', "1.0.0" );
38     cmd.add( uThr );
39     cmd.add( vThr );
40     cmd.add( out );
41     cmd.add( vesselness );
42     cmd.add( labels );
43     cmd.add( in );
44     cmd.parse( argc, argv );
45   }
46   catch( TCLAP::ArgException& err )
47   {
48     std::cerr
49       << "===============================" << std::endl
50       << "Error caught: " << std::endl
51       << err.error( ) << " " << err.argId( ) << std::endl
52       << "===============================" << std::endl
53       << std::endl;
54     return( 1 );
55
56   } // yrt
57
58   try
59   {
60     // Read input image
61     TImage::Pointer input_image;
62     CTBronchi::ReadImage( input_image, in.getValue( ) );
63
64     // Read input labels
65     TLabels::Pointer input_labels;
66     CTBronchi::ReadImage( input_labels, labels.getValue( ) );
67
68     // Read input vesselness
69     TScalarImage::Pointer input_vesselness;
70     CTBronchi::ReadImage( input_vesselness, vesselness.getValue( ) );
71
72     // Create labels
73     typedef CTBronchi::MoriLabelling< TImage, TLabels, TScalarImage > _TLabelling;
74     _TLabelling::Pointer labelling = _TLabelling::New( );
75     labelling->SetInput( input_image );
76     labelling->SetInputLabels( input_labels );
77     labelling->SetInputVesselness( input_vesselness );
78     labelling->SetVesselnessThreshold( vThr.getValue( ) );
79     labelling->SetUpperThreshold( uThr.getValue( ) );
80     labelling->SetInsideValue( 1 );
81     labelling->SetOutsideValue( 2 );
82     labelling->SetFillValue( 2 );
83     double t = CTBronchi::MeasureTime( labelling );
84     std::cout << "Labelling executed in " << t << " s" << std::endl;
85
86     // Write result
87     CTBronchi::WriteImage( labelling->GetOutput( ), out.getValue( ) );
88   }
89   catch( std::exception& err )
90   {
91     std::cerr
92       << "===============================" << std::endl
93       << "Error caught: " << std::endl
94       << err.what( ) << std::endl
95       << "===============================" << std::endl
96       << std::endl;
97     return( 1 );
98
99   } // yrt
100   return( 0 );
101 }
102
103 // eof - $RCSfile$