X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=appli%2FCTBronchi%2FRandomWalker.cxx;h=561dd36e4b1a1af80601cb686c0cf01d20e6aed5;hb=926cb50be2ef54fce0d9493119dc89626e9b7526;hp=f6e81fbcda161999c3bb388b3b71a940c327c196;hpb=6f716a6d2ce76a7bc9abb37406ce3802aa1e4451;p=FrontAlgorithms.git diff --git a/appli/CTBronchi/RandomWalker.cxx b/appli/CTBronchi/RandomWalker.cxx index f6e81fb..561dd36 100644 --- a/appli/CTBronchi/RandomWalker.cxx +++ b/appli/CTBronchi/RandomWalker.cxx @@ -5,19 +5,26 @@ #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[] ) { @@ -27,7 +34,7 @@ int main( int argc, char* argv[] ) std::cerr << "Usage: " << argv[ 0 ] << std::endl << " input_image label_image output_image" << std::endl - << " alpha(0) beta(100)" + << " label beta(100)" << std::endl; return( 1 ); @@ -35,7 +42,7 @@ 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 ] ); + TLabel label = TLabel( std::atoi( argv[ 4 ] ) ); double beta = std::atof( argv[ 5 ] ); // Read images @@ -49,7 +56,6 @@ int main( int argc, char* argv[] ) // Prepare weight TWeight::Pointer weight = TWeight::New( ); - weight->SetAlpha( alpha ); weight->SetBeta( beta ); // Prepare filter @@ -58,6 +64,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 +102,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 +118,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 {