]> Creatis software - FrontAlgorithms.git/blob - appli/CTBronchi/AndSegmentations.cxx
...
[FrontAlgorithms.git] / appli / CTBronchi / AndSegmentations.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 <itkAndImageFilter.h>
10 #include "Functions.h"
11
12 // -------------------------------------------------------------------------
13 const unsigned int Dim = 3;
14 typedef unsigned char             TPixel;
15 typedef itk::Image< TPixel, Dim > TImage;
16
17 // -------------------------------------------------------------------------
18 int main( int argc, char* argv[] )
19 {
20   typedef TCLAP::ValueArg< std::string > _TStringArg;
21
22   // Parse input line
23   _TStringArg in1( "i", "input1", "Input image 1", true, "", "file" );
24   _TStringArg in2( "j", "input2", "Input image 2", true, "", "file" );
25   _TStringArg out( "o", "output", "Output image", true, "", "file" );
26   try
27   {
28     TCLAP::CmdLine cmd( "FastRandomWalker", ' ', "1.0.0" );
29     cmd.add( out );
30     cmd.add( in2 );
31     cmd.add( in1 );
32     cmd.parse( argc, argv );
33   }
34   catch( TCLAP::ArgException& err )
35   {
36     std::cerr
37       << "===============================" << std::endl
38       << "Error caught: " << std::endl
39       << err.error( ) << " " << err.argId( ) << std::endl
40       << "===============================" << std::endl
41       << std::endl;
42     return( 1 );
43
44   } // yrt
45
46   try
47   {
48     // Read input image 1
49     TImage::Pointer input_image1;
50     CTBronchi::ReadImage( input_image1, in1.getValue( ) );
51
52     // Read input image 2
53     TImage::Pointer input_image2;
54     CTBronchi::ReadImage( input_image2, in2.getValue( ) );
55
56     // And images
57     typedef itk::AndImageFilter< TImage, TImage, TImage > TFilter;
58     TFilter::Pointer filter = TFilter::New( );
59     filter->SetInput1( input_image1 );
60     filter->SetInput2( input_image2 );
61     double t = CTBronchi::MeasureTime( filter );
62     std::cout << "And filter executed in " << t << " s" << std::endl;
63
64     // Write result
65     CTBronchi::WriteImage( filter->GetOutput( ), out.getValue( ) );
66   }
67   catch( std::exception& err )
68   {
69     std::cerr
70       << "===============================" << std::endl
71       << "Error caught: " << std::endl
72       << err.what( ) << std::endl
73       << "===============================" << std::endl
74       << std::endl;
75     return( 1 );
76
77   } // yrt
78   return( 0 );
79 }
80
81 // eof - $RCSfile$