]> Creatis software - FrontAlgorithms.git/blobdiff - appli/CTBronchi/MoriLabelling.cxx
...
[FrontAlgorithms.git] / appli / CTBronchi / MoriLabelling.cxx
diff --git a/appli/CTBronchi/MoriLabelling.cxx b/appli/CTBronchi/MoriLabelling.cxx
new file mode 100644 (file)
index 0000000..0915cd5
--- /dev/null
@@ -0,0 +1,118 @@
+#include <chrono>
+#include <itkImage.h>
+#include <itkImageFileReader.h>
+#include <itkImageFileWriter.h>
+#include <CTBronchi/MoriLabelling.h>
+
+// -------------------------------------------------------------------------
+const unsigned int Dim = 3;
+typedef short          TPixel;
+typedef unsigned short TLabel;
+
+typedef itk::Image< TPixel, Dim > TInputImage;
+typedef itk::Image< TLabel, Dim > TLabelImage;
+
+typedef CTBronchi::MoriLabelling< TInputImage, TLabelImage > TFilter;
+
+// -------------------------------------------------------------------------
+int main( int argc, char* argv[] )
+{
+  // Get arguments
+  if( argc < 8 )
+  {
+    std::cerr
+      << "Usage: " << argv[ 0 ] << std::endl
+      << "   input_image label_image output_image" << std::endl
+      << "   upper_threshold(-400)" << std::endl
+      << "   inside_value(255)" << std::endl
+      << "   inside_label(1) outside_label(2)"
+      << std::endl;
+    return( 1 );
+
+  } // fi
+  std::string input_image_filename = argv[ 1 ];
+  std::string label_image_filename = argv[ 2 ];
+  std::string output_image_filename = argv[ 3 ];
+  TLabel upper_threshold = std::atoi( argv[ 4 ] );
+  TLabel inside_value = std::atoi( argv[ 5 ] );
+  TLabel inside_label = std::atoi( argv[ 6 ] );
+  TLabel outside_label = std::atoi( argv[ 7 ] );
+
+  // Read images
+  itk::ImageFileReader< TInputImage >::Pointer input_image_reader =
+    itk::ImageFileReader< TInputImage >::New( );
+  input_image_reader->SetFileName( input_image_filename );
+
+  itk::ImageFileReader< TLabelImage >::Pointer label_image_reader =
+    itk::ImageFileReader< TLabelImage >::New( );
+  label_image_reader->SetFileName( label_image_filename );
+
+  // Prepare filter
+  TFilter::Pointer filter = TFilter::New( );
+  filter->SetInputLabelImage( label_image_reader->GetOutput( ) );
+  filter->SetInputRawImage( input_image_reader->GetOutput( ) );
+  filter->SetUpperThreshold( upper_threshold );
+  filter->SetInsideValue( inside_value );
+  filter->SetInsideLabel( inside_label );
+  filter->SetOutsideLabel( outside_label );
+
+  // Show some information
+  std::cout << "----------------------------------------------" << std::endl;
+  std::cout << "Image: " << input_image_filename << std::endl;
+
+  // Execute pipeline
+  std::chrono::time_point< std::chrono::high_resolution_clock > ts, te;
+  std::chrono::duration< double > tr;
+  try
+  {
+    ts = std::chrono::high_resolution_clock::now( );
+    input_image_reader->Update( );
+    te = std::chrono::high_resolution_clock::now( );
+    tr = te - ts;
+    std::cout << "Raw read time: " << tr.count( ) << " s" << std::endl;
+
+    ts = std::chrono::high_resolution_clock::now( );
+    label_image_reader->Update( );
+    te = std::chrono::high_resolution_clock::now( );
+    tr = te - ts;
+    std::cout << "Label read time: " << tr.count( ) << " s" << std::endl;
+
+    ts = std::chrono::high_resolution_clock::now( );
+    filter->Update( );
+    te = std::chrono::high_resolution_clock::now( );
+    tr = te - ts;
+    std::cout
+      << "Labelling time: " << tr.count( ) << " s" << std::endl;
+  }
+  catch( std::exception& err )
+  {
+    std::cerr << "Error caught: " << err.what( ) << std::endl;
+    return( 1 );
+
+  } // yrt
+
+  // Save output image
+  itk::ImageFileWriter< TLabelImage >::Pointer output_image_writer =
+    itk::ImageFileWriter< TLabelImage >::New( );
+  output_image_writer->SetInput( filter->GetOutput( ) );
+  output_image_writer->SetFileName( output_image_filename );
+  try
+  {
+    ts = std::chrono::high_resolution_clock::now( );
+    output_image_writer->Update( );
+    te = std::chrono::high_resolution_clock::now( );
+    tr = te - ts;
+    std::cout << "Write time: " << tr.count( ) << " s" << std::endl;
+  }
+  catch( std::exception& err )
+  {
+    std::cerr << "Error caught: " << err.what( ) << std::endl;
+    return( 1 );
+
+  } // yrt
+  std::cout << "----------------------------------------------" << std::endl;
+
+  return( 0 );
+}
+
+// eof - $RCSfile$