-#include <chrono>
+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
+
+#include <string>
+#include <tclap/CmdLine.h>
#include <itkImage.h>
-#include <itkImageFileReader.h>
-#include <itkImageFileWriter.h>
-#include <CTBronchi/MoriLabelling.h>
+#include "MoriLabelling.h"
+#include "Functions.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;
+typedef short TPixel;
+typedef unsigned char TLabel;
+typedef itk::NumericTraits< TPixel >::RealType TScalar;
+typedef itk::Image< TPixel, Dim > TImage;
+typedef itk::Image< TLabel, Dim > TLabels;
+typedef itk::Image< TScalar, Dim > TScalarImage;
// -------------------------------------------------------------------------
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;
+ typedef TCLAP::ValueArg< std::string > _TStringArg;
+ typedef TCLAP::ValueArg< double > _TRealArg;
+ typedef TCLAP::ValueArg< TPixel > _TPixelArg;
+
+ // Parse input line
+ _TStringArg in( "i", "input", "Input image", true, "", "file" );
+ _TStringArg labels( "l", "labels", "Input labels", true, "", "file" );
+ _TStringArg vesselness( "v", "vesselness", "Input vesselness", true, "", "file" );
+ _TStringArg out( "o", "output", "Output image", true, "", "file" );
+ _TRealArg vThr( "a", "vesselness_thr", "Vesselness threshold", false, 0.05, "value (0.05)" );
+ _TPixelArg uThr( "u", "upper_thr", "Upper threshold", false, -400, "value (-400)" );
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;
+ TCLAP::CmdLine cmd( "Labelling", ' ', "1.0.0" );
+ cmd.add( uThr );
+ cmd.add( vThr );
+ cmd.add( out );
+ cmd.add( vesselness );
+ cmd.add( labels );
+ cmd.add( in );
+ cmd.parse( argc, argv );
}
- catch( std::exception& err )
+ catch( TCLAP::ArgException& err )
{
- std::cerr << "Error caught: " << err.what( ) << std::endl;
+ std::cerr
+ << "===============================" << std::endl
+ << "Error caught: " << std::endl
+ << err.error( ) << " " << err.argId( ) << std::endl
+ << "===============================" << std::endl
+ << 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;
+ // Read input image
+ TImage::Pointer input_image;
+ CTBronchi::ReadImage( input_image, in.getValue( ) );
+
+ // Read input labels
+ TLabels::Pointer input_labels;
+ CTBronchi::ReadImage( input_labels, labels.getValue( ) );
+
+ // Read input vesselness
+ TScalarImage::Pointer input_vesselness;
+ CTBronchi::ReadImage( input_vesselness, vesselness.getValue( ) );
+
+ // Create labels
+ typedef CTBronchi::MoriLabelling< TImage, TLabels, TScalarImage > _TLabelling;
+ _TLabelling::Pointer labelling = _TLabelling::New( );
+ labelling->SetInput( input_image );
+ labelling->SetInputLabels( input_labels );
+ labelling->SetInputVesselness( input_vesselness );
+ labelling->SetVesselnessThreshold( vThr.getValue( ) );
+ labelling->SetUpperThreshold( uThr.getValue( ) );
+ labelling->SetInsideValue( 1 );
+ labelling->SetOutsideValue( 2 );
+ labelling->SetFillValue( 2 );
+ double t = CTBronchi::MeasureTime( labelling );
+ std::cout << "Labelling executed in " << t << " s" << std::endl;
+
+ // Write result
+ CTBronchi::WriteImage( labelling->GetOutput( ), out.getValue( ) );
}
catch( std::exception& err )
{
- std::cerr << "Error caught: " << err.what( ) << std::endl;
+ std::cerr
+ << "===============================" << std::endl
+ << "Error caught: " << std::endl
+ << err.what( ) << std::endl
+ << "===============================" << std::endl
+ << std::endl;
return( 1 );
} // yrt
- std::cout << "----------------------------------------------" << std::endl;
-
return( 0 );
}