3 #include <itkImageFileReader.h>
4 #include <itkImageFileWriter.h>
5 #include <CTBronchi/MoriLabelling.h>
7 // -------------------------------------------------------------------------
8 const unsigned int Dim = 3;
10 typedef unsigned short TLabel;
12 typedef itk::Image< TPixel, Dim > TInputImage;
13 typedef itk::Image< TLabel, Dim > TLabelImage;
15 typedef CTBronchi::MoriLabelling< TInputImage, TLabelImage > TFilter;
17 // -------------------------------------------------------------------------
18 int main( int argc, char* argv[] )
24 << "Usage: " << argv[ 0 ] << std::endl
25 << " input_image label_image output_image" << std::endl
26 << " upper_threshold(-400)" << std::endl
27 << " inside_value(255)" << std::endl
28 << " inside_label(1) outside_label(2)"
33 std::string input_image_filename = argv[ 1 ];
34 std::string label_image_filename = argv[ 2 ];
35 std::string output_image_filename = argv[ 3 ];
36 TLabel upper_threshold = std::atoi( argv[ 4 ] );
37 TLabel inside_value = std::atoi( argv[ 5 ] );
38 TLabel inside_label = std::atoi( argv[ 6 ] );
39 TLabel outside_label = std::atoi( argv[ 7 ] );
42 itk::ImageFileReader< TInputImage >::Pointer input_image_reader =
43 itk::ImageFileReader< TInputImage >::New( );
44 input_image_reader->SetFileName( input_image_filename );
46 itk::ImageFileReader< TLabelImage >::Pointer label_image_reader =
47 itk::ImageFileReader< TLabelImage >::New( );
48 label_image_reader->SetFileName( label_image_filename );
51 TFilter::Pointer filter = TFilter::New( );
52 filter->SetInputLabelImage( label_image_reader->GetOutput( ) );
53 filter->SetInputRawImage( input_image_reader->GetOutput( ) );
54 filter->SetUpperThreshold( upper_threshold );
55 filter->SetInsideValue( inside_value );
56 filter->SetInsideLabel( inside_label );
57 filter->SetOutsideLabel( outside_label );
59 // Show some information
60 std::cout << "----------------------------------------------" << std::endl;
61 std::cout << "Image: " << input_image_filename << std::endl;
64 std::chrono::time_point< std::chrono::high_resolution_clock > ts, te;
65 std::chrono::duration< double > tr;
68 ts = std::chrono::high_resolution_clock::now( );
69 input_image_reader->Update( );
70 te = std::chrono::high_resolution_clock::now( );
72 std::cout << "Raw read time: " << tr.count( ) << " s" << std::endl;
74 ts = std::chrono::high_resolution_clock::now( );
75 label_image_reader->Update( );
76 te = std::chrono::high_resolution_clock::now( );
78 std::cout << "Label read time: " << tr.count( ) << " s" << std::endl;
80 ts = std::chrono::high_resolution_clock::now( );
82 te = std::chrono::high_resolution_clock::now( );
85 << "Labelling time: " << tr.count( ) << " s" << std::endl;
87 catch( std::exception& err )
89 std::cerr << "Error caught: " << err.what( ) << std::endl;
95 itk::ImageFileWriter< TLabelImage >::Pointer output_image_writer =
96 itk::ImageFileWriter< TLabelImage >::New( );
97 output_image_writer->SetInput( filter->GetOutput( ) );
98 output_image_writer->SetFileName( output_image_filename );
101 ts = std::chrono::high_resolution_clock::now( );
102 output_image_writer->Update( );
103 te = std::chrono::high_resolution_clock::now( );
105 std::cout << "Write time: " << tr.count( ) << " s" << std::endl;
107 catch( std::exception& err )
109 std::cerr << "Error caught: " << err.what( ) << std::endl;
113 std::cout << "----------------------------------------------" << std::endl;