1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
7 #include <itkAbsoluteValueDifferenceImageFilter.h>
8 #include <itkBinaryThresholdImageFilter.h>
9 #include <CTBronchi/Functions.h>
10 #include <CTBronchi/Mori.h>
11 #include <CTBronchi/MoriLabelling.h>
12 #include <CTBronchi/RandomWalker.h>
14 // -------------------------------------------------------------------------
15 const unsigned int Dim = 3;
16 typedef short TInputPixel;
17 typedef unsigned char TLabelPixel;
18 typedef itk::Image< TInputPixel, Dim > TImage;
19 typedef itk::Image< TLabelPixel, Dim > TLabelImage;
21 // -------------------------------------------------------------------------
22 int main( int argc, char* argv[] )
24 std::map< std::string, std::string > args;
27 if( CTBronchi::ParseArgs( args, argc, argv ) )
30 TImage::PointType seed;
31 char* str = new char[ args[ "seed" ].size( ) + 1 ];
32 strcpy( str, args[ "seed" ].c_str( ) );
33 seed[ 0 ] = std::atof( strtok( str, ";" ) );
34 seed[ 1 ] = std::atof( strtok( NULL, ";" ) );
35 seed[ 2 ] = std::atof( strtok( NULL, ";" ) );
38 TImage::Pointer input_image;
39 CTBronchi::ReadImage( input_image, args[ "in" ] );
42 TLabelImage::Pointer mori;
43 TInputPixel opt_thr = CTBronchi::Mori( mori, input_image, seed, args );
46 TLabelImage::Pointer labels;
47 CTBronchi::Label( labels, input_image, mori, opt_thr, args );
50 TLabelImage::Pointer final_labels;
51 CTBronchi::RandomWalker( final_labels, input_image, labels, args );
54 typedef itk::BinaryThresholdImageFilter< TLabelImage, TLabelImage > TBinThr;
55 TBinThr::Pointer bin_thr = TBinThr::New( );
56 bin_thr->SetInput( final_labels );
57 bin_thr->SetLowerThreshold( 1 );
58 bin_thr->SetUpperThreshold( 1 );
59 bin_thr->SetInsideValue( 1 );
60 bin_thr->SetOutsideValue( 0 );
61 double t = CTBronchi::MeasureTime( bin_thr );
62 std::cout << "Label extracted in " << t << " s" << std::endl;
63 TLabelImage::Pointer segmentation = bin_thr->GetOutput( );
66 CTBronchi::WriteImage( segmentation, args[ "out" ] );
69 std::map< std::string, std::string >::const_iterator i =
70 args.find( "out_diff" );
71 if( i != args.end( ) )
73 typedef itk::AbsoluteValueDifferenceImageFilter< TLabelImage, TLabelImage, TLabelImage > TDiff;
74 TDiff::Pointer diff = TDiff::New( );
75 diff->SetInput1( mori );
76 diff->SetInput2( segmentation );
77 t = CTBronchi::MeasureTime( diff );
78 std::cout << "Difference computed in " << t << " s" << std::endl;
79 TLabelImage::Pointer difference = diff->GetOutput( );
80 CTBronchi::WriteImage( difference, i->second );
87 catch( std::exception& err )
90 << "===============================" << std::endl
91 << "Error caught: " << std::endl
93 << "===============================" << std::endl