X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=appli%2FCTBronchi%2FRandomWalker.cxx;h=57045586197710f4909a850f1bff2a35380c027a;hb=e69d65c084b579e4014cf35688eae78a9a397834;hp=f6e81fbcda161999c3bb388b3b71a940c327c196;hpb=7a0591e1611721f36428cee7d7cce6161f517612;p=FrontAlgorithms.git diff --git a/appli/CTBronchi/RandomWalker.cxx b/appli/CTBronchi/RandomWalker.cxx index f6e81fb..5704558 100644 --- a/appli/CTBronchi/RandomWalker.cxx +++ b/appli/CTBronchi/RandomWalker.cxx @@ -5,29 +5,36 @@ #include #include +#include +#include // ------------------------------------------------------------------------- const unsigned int Dim = 3; typedef short TPixel; typedef unsigned short TLabel; +typedef unsigned char TBinary; typedef double TScalar; typedef itk::Image< TPixel, Dim > TInputImage; typedef itk::Image< TLabel, Dim > TLabelImage; +typedef itk::Image< TBinary, Dim > TBinaryImage; typedef fpa::Image::RandomWalker< TInputImage, TLabelImage, TScalar > TFilter; typedef fpa::Image::Functors::Dijkstra::Gaussian< TInputImage, TScalar > TWeight; +typedef ivq::ITK::ExtractLabelFunction< TLabel, TBinary > TLabelFunction; +typedef ivq::ITK::ImageUnaryFunctionFilter< TLabelImage, TBinaryImage > TLabelExtractor; + // ------------------------------------------------------------------------- int main( int argc, char* argv[] ) { // Get arguments - if( argc < 6 ) + if( argc < 7 ) { std::cerr << "Usage: " << argv[ 0 ] << std::endl << " input_image label_image output_image" << std::endl - << " alpha(0) beta(100)" + << " label alpha(0) beta(100)" << std::endl; return( 1 ); @@ -35,8 +42,9 @@ int main( int argc, char* argv[] ) std::string input_image_filename = argv[ 1 ]; std::string label_image_filename = argv[ 2 ]; std::string output_image_filename = argv[ 3 ]; - double alpha = std::atof( argv[ 4 ] ); - double beta = std::atof( argv[ 5 ] ); + TLabel label = TLabel( std::atoi( argv[ 4 ] ) ); + double alpha = std::atof( argv[ 5 ] ); + double beta = std::atof( argv[ 6 ] ); // Read images itk::ImageFileReader< TInputImage >::Pointer input_image_reader = @@ -58,6 +66,17 @@ int main( int argc, char* argv[] ) filter->SetLabels( label_image_reader->GetOutput( ) ); filter->SetWeightFunction( weight ); + // Label extraction + TLabelFunction::Pointer label_function = TLabelFunction::New( ); + label_function->SetLabel( label ); + label_function->SetInsideValue( 255 ); + label_function->SetOutsideValue( 0 ); + + TLabelExtractor::Pointer label_extractor = TLabelExtractor::New( ); + label_extractor->SetInput( filter->GetMarks( ) ); + label_extractor->SetFunction( label_function ); + + // Show some information std::cout << "----------------------------------------------" << std::endl; std::cout << "Image: " << input_image_filename << std::endl; @@ -85,6 +104,13 @@ int main( int argc, char* argv[] ) tr = te - ts; std::cout << "Labelling time: " << tr.count( ) << " s" << std::endl; + + ts = std::chrono::high_resolution_clock::now( ); + label_extractor->Update( ); + te = std::chrono::high_resolution_clock::now( ); + tr = te - ts; + std::cout + << "Extract label time: " << tr.count( ) << " s" << std::endl; } catch( std::exception& err ) { @@ -94,9 +120,9 @@ int main( int argc, char* argv[] ) } // yrt // Save output image - itk::ImageFileWriter< TLabelImage >::Pointer output_image_writer = - itk::ImageFileWriter< TLabelImage >::New( ); - output_image_writer->SetInput( filter->GetMarks( ) ); + itk::ImageFileWriter< TBinaryImage >::Pointer output_image_writer = + itk::ImageFileWriter< TBinaryImage >::New( ); + output_image_writer->SetInput( label_extractor->GetOutput( ) ); output_image_writer->SetFileName( output_image_filename ); try {