From: Leonardo Flórez-Valencia Date: Tue, 29 Aug 2017 02:09:47 +0000 (-0500) Subject: ... X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=b4c7827278cd914c18ee5404fb636c87e8099b24;p=FrontAlgorithms.git ... --- diff --git a/appli/CTBronchi/CMakeLists.txt b/appli/CTBronchi/CMakeLists.txt index 27e869c..012436f 100644 --- a/appli/CTBronchi/CMakeLists.txt +++ b/appli/CTBronchi/CMakeLists.txt @@ -5,21 +5,21 @@ if(fpa_BUILD_CTBronchi) # ${PROJECT_BINARY_DIR}/CTBronchi_process.sh # COPYONLY # ) -# include_directories( -# ${PROJECT_SOURCE_DIR}/lib -# ${PROJECT_BINARY_DIR}/lib -# ${PROJECT_SOURCE_DIR}/appli -# ${PROJECT_BINARY_DIR}/appli -# ) -# set(_pfx fpa_CTBronchi_) -# set( -# _examples -# Process -# ) -# foreach(_e ${_examples}) -# add_executable(${_pfx}${_e} ${_e}.cxx) -# target_link_libraries(${_pfx}${_e} fpa) -# endforeach(_e) +include_directories( + ${PROJECT_SOURCE_DIR}/lib + ${PROJECT_BINARY_DIR}/lib + ${PROJECT_SOURCE_DIR}/appli + ${PROJECT_BINARY_DIR}/appli + ) +set(_pfx fpa_CTBronchi_) +set( + _examples + Process + ) +foreach(_e ${_examples}) + add_executable(${_pfx}${_e} ${_e}.cxx) + target_link_libraries(${_pfx}${_e} fpa) +endforeach(_e) endif(fpa_BUILD_CTBronchi) ## eof - $RCSfile$ diff --git a/appli/CTBronchi/Functions.h b/appli/CTBronchi/Functions.h index 272c974..cfbbcfe 100644 --- a/appli/CTBronchi/Functions.h +++ b/appli/CTBronchi/Functions.h @@ -6,6 +6,8 @@ #define __CTBronchi__Functions__h__ #include +#include +#include #include #include @@ -50,6 +52,80 @@ namespace CTBronchi std::cout << "Wrote " << fname << " in " << t << " s" << std::endl; } + // ----------------------------------------------------------------------- + bool ParseArgs( + std::map< std::string, std::string >& args, int argc, char* argv[] + ) + { + std::set< std::string > mandatory; + mandatory.insert( "in" ); + mandatory.insert( "out" ); + mandatory.insert( "seed" ); + + args[ "mori_minimum_threshold" ] = "-850"; + args[ "mori_signal_kernel_size" ] = "20"; + args[ "mori_signal_threshold" ] = "100"; + args[ "mori_signal_influence" ] = "0.5"; + args[ "mori_lower_threshold" ] = "-1024"; + args[ "mori_upper_threshold" ] = "0"; + args[ "mori_delta_threshold" ] = "1"; + args[ "labelling_upper_threshold" ] = "-550"; + args[ "random_walker_alpha" ] = "1"; + args[ "random_walker_beta" ] = "100"; + + int i = 1; + while( i < argc ) + { + std::string cmd = argv[ i ] + 1; + if( cmd == "seed" ) + { + std::stringstream seed; + seed + << argv[ i + 1 ] << ";" + << argv[ i + 2 ] << ";" + << argv[ i + 3 ]; + args[ cmd ] = seed.str( ); + i += 4; + } + else + { + args[ cmd ] = argv[ i + 1 ]; + i += 2; + + } // fi + + } // elihw + + bool complete = true; + for( std::string t: mandatory ) + complete &= ( args.find( t ) != args.end( ) ); + + if( !complete ) + { + std::cerr + << "Usage: " << argv[ 0 ] << std::endl + << "\t-in filename" << std::endl + << "\t-out filename" << std::endl + << "\t-seed x y z" << std::endl + << "\t[-out_mori filename]" << std::endl + << "\t[-out_signal filename]" << std::endl + << "\t[-out_labels filename]" << std::endl + << "\t[-mori_minimum_threshold value]" << std::endl + << "\t[-mori_signal_kernel_size value]" << std::endl + << "\t[-mori_signal_threshold value]" << std::endl + << "\t[-mori_signal_influence value]" << std::endl + << "\t[-mori_lower_threshold value]" << std::endl + << "\t[-mori_upper_threshold value]" << std::endl + << "\t[-mori_delta_threshold value]" << std::endl + << "\t[-labelling_upper_threshold value]" << std::endl + << "\t[-random_walker_alpha value]" << std::endl + << "\t[-random_walker_beta value]" << std::endl; + return( false ); + + } // fi + return( true ); + } + } // ecapseman #endif // __CTBronchi__Functions__h__ diff --git a/appli/CTBronchi/Mori.h b/appli/CTBronchi/Mori.h index a228fa5..4693d19 100644 --- a/appli/CTBronchi/Mori.h +++ b/appli/CTBronchi/Mori.h @@ -12,22 +12,26 @@ namespace CTBronchi { // ----------------------------------------------------------------------- - template< class _TInputPtr, class _TOutputPtr > - void Mori( - _TOutputPtr& output, const _TInputPtr& input, - const std::map< std::string, std::string >& args + template< class _TInputPtr, class _TOutputPtr, class _TSeed > + typename _TInputPtr::ObjectType::PixelType Mori( + _TOutputPtr& output, const _TInputPtr& input, _TSeed& seed, + std::map< std::string, std::string >& args ) { typedef typename _TInputPtr::ObjectType _TInput; typedef typename _TOutputPtr::ObjectType _TOutput; typedef fpa::Filters::Image::Mori< _TInput, _TOutput > _TMori; - typedef typename _TInput::PixelType _TInputPixel; + typedef typename _TInput::PixelType _TInputPixel; + typedef typename _TOutput::PixelType _TOutputPixel; + + _TOutputPixel i_val = _TOutputPixel( 1 ); + _TOutputPixel o_val = _TOutputPixel( 0 ); typename _TMori::Pointer mori = _TMori::New( ); mori->SetInput( input ); - mori->SetSeed( global_seed ); - mori->SetInsideValue( inside_value ); - mori->SetOutsideValue( outside_value ); + mori->SetSeed( seed ); + mori->SetInsideValue( i_val ); + mori->SetOutsideValue( o_val ); mori->SetMinimumThreshold( _TInputPixel( std::atof( args[ "mori_minimum_threshold" ].c_str( ) ) ) ); @@ -69,13 +73,13 @@ namespace CTBronchi signal << x << " " << y << std::endl; } // rof - std::ofstream signals_str( i->second.c_str( ) ); signals_str << signal.str( ); signals_str.close( ); } // fi output->DisconnectPipeline( ); + return( mori->GetOptimumThreshold( ) ); } } // ecapseman diff --git a/appli/CTBronchi/MoriLabelling.h b/appli/CTBronchi/MoriLabelling.h index d4eea09..b599310 100644 --- a/appli/CTBronchi/MoriLabelling.h +++ b/appli/CTBronchi/MoriLabelling.h @@ -5,10 +5,10 @@ #ifndef __CTBronchi__MoriLabelling__h__ #define __CTBronchi__MoriLabelling__h__ +#include +#include +#include #include -#include -#include -#include #include #include @@ -18,46 +18,47 @@ namespace CTBronchi */ template< class _TInputImage, class _TLabelImage > class MoriLabellingTraits - : public fpa::Filters::Image::DefaultTraits< _TInputImage, _TLabelImage, typename _TLabelImage::PixelType > + : public fpa::Filters::Image::DefaultTraits< _TInputImage, _TLabelImage, typename _TLabelImage::PixelType > { public: typedef _TInputImage TInputImage; typedef _TLabelImage TLabelImage; - typedef fpa::Filters::Image::DefaultTraits< TInputImage, TLabelImage, typename TLabelImage::PixelType > Superclass; - - typedef typename Superclass::TInternalTraits TInternalTraits; - typedef typename Superclass::TFilter TFilter; - typedef fpa::Filters::MarksInterface< TInternalTraits > TMarksInterface; - typedef fpa::Filters::Image::LabelsSeedInterface< TInternalTraits > TSeedsInterface; + typedef typename TLabelImage::PixelType TLabel; + typedef fpa::Filters::Image::DefaultTraits< TInputImage, TLabelImage, TLabel > Superclass; + typedef typename Superclass::TInternalTraits TInternalTraits; + typedef typename Superclass::TMarksImage TMarksImage; + typedef typename Superclass::TFilterInterface TFilterInterface; + + typedef fpa::Filters::BaseMarksInterface< TInternalTraits > TMarksInterface; + typedef fpa::Filters::Image::SeedsFromLabelsInterface< TInternalTraits > TSeedsInterface; }; /** */ template< class _TInputImage, class _TLabelImage > class MoriLabelling - : public fpa::Filters::Image::LabelsSeedFilter< fpa::Filters::Image::Algorithm< fpa::Filters::RegionGrow< CTBronchi::MoriLabellingTraits< _TInputImage, _TLabelImage > > >, _TLabelImage > + : public fpa::Filters::Image::RegionGrow< _TInputImage, _TLabelImage, typename _TLabelImage::PixelType, CTBronchi::MoriLabellingTraits< _TInputImage, _TLabelImage > > { public: typedef _TInputImage TInputImage; typedef _TLabelImage TLabelImage; typedef CTBronchi::MoriLabellingTraits< TInputImage, TLabelImage > TTraits; - fpaTraitsMacro( typename, TTraits ); - - typedef fpa::Filters::RegionGrow< TTraits > TBase; - typedef fpa::Filters::Image::Algorithm< TBase > TAlgorithm; - typedef fpa::Filters::Image::LabelsSeedFilter< TAlgorithm, _TLabelImage > Superclass; - typedef MoriLabelling Self; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; + fpaTraitsMacro( typename TTraits ); - typedef fpa::Functors::RegionGrow::BinaryThreshold< TInputValue > TLabelFunctor; + typedef fpa::Filters::Image::RegionGrow< TInputImage, TLabelImage, TMark, TTraits > Superclass; + typedef MoriLabelling Self; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + typedef fpa::Functors::RegionGrow::BinaryThreshold< TInputValue > TFunctor; public: itkNewMacro( Self ); itkTypeMacro( CTBronchi::MoriLabelling, fpa::Filters::Image::RegionGrow ); - itkGetConstMacro( InputInsideValue, TInputValue ); - itkSetMacro( InputInsideValue, TInputValue ); + itkGetConstMacro( LastThreshold, TInputValue ); + itkSetMacro( LastThreshold, TInputValue ); + + fpaFilterInputMacro( InputLabels, TLabelImage ); public: TInputValue GetUpperThreshold( ) const; @@ -67,7 +68,8 @@ namespace CTBronchi MoriLabelling( ); virtual ~MoriLabelling( ); - virtual void _UpdateOutputValue( TNode& n ) override; + virtual const itk::DataObject* _GetReferenceInput( ) const override; + virtual void _PostComputeOutputValue( TNode& n ) override; private: // Purposely not implemented. @@ -75,8 +77,8 @@ namespace CTBronchi Self& operator=( const Self& other ); protected: - typename TLabelFunctor::Pointer m_LabelFunctor; - TInputValue m_InputInsideValue; + typename TFunctor::Pointer m_Functor; + TInputValue m_LastThreshold; }; } // ecapseman diff --git a/appli/CTBronchi/MoriLabelling.hxx b/appli/CTBronchi/MoriLabelling.hxx index 7963416..b6f982a 100644 --- a/appli/CTBronchi/MoriLabelling.hxx +++ b/appli/CTBronchi/MoriLabelling.hxx @@ -12,7 +12,7 @@ typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >:: TInputValue CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >:: GetUpperThreshold( ) const { - return( this->m_LabelFunctor->GetUpperThreshold( ) ); + return( this->m_Functor->GetUpperThreshold( ) ); } // ------------------------------------------------------------------------- @@ -20,17 +20,19 @@ template< class _TInputImage, class _TLabelImage > void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >:: SetUpperThreshold( TInputValue t ) { - this->m_LabelFunctor->SetUpperThreshold( t ); + this->m_Functor->SetUpperThreshold( t ); } // ------------------------------------------------------------------------- template< class _TInputImage, class _TLabelImage > CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >:: MoriLabelling( ) - : Superclass( ) + : Superclass( ), + m_LastThreshold( TInputValue( 0 ) ) { - this->m_LabelFunctor = TLabelFunctor::New( ); - this->SetPredicate( this->m_LabelFunctor ); + fpaFilterInputConfigureMacro( InputLabels, TLabelImage ); + this->m_Functor = TFunctor::New( ); + this->SetPredicate( this->m_Functor ); } // ------------------------------------------------------------------------- @@ -40,24 +42,72 @@ CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >:: { } +// ------------------------------------------------------------------------- +template< class _TInputImage, class _TLabelImage > +const itk::DataObject* +CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >:: +_GetReferenceInput( ) const +{ + return( this->GetInputLabels( ) ); +} + // ------------------------------------------------------------------------- template< class _TInputImage, class _TLabelImage > void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >:: -_UpdateOutputValue( TNode& n ) +_PostComputeOutputValue( TNode& n ) { - this->TBase::_UpdateOutputValue( n ); - if( n.FrontId != 0 ) + this->Superclass::_PostComputeOutputValue( n ); + if( n.Value == this->GetInsideValue( ) ) { - const TLabelImage* input_labels = this->GetInputLabels( ); - if( input_labels->GetPixel( n.Vertex ) != this->GetInputInsideValue( ) ) - n.Value = TOutputValue( 0 ); - else - n.Value = this->GetInsideValue( ); + const _TInputImage* input = this->GetInput( ); + const TLabelImage* labels = this->GetInputLabels( ); + double x = input->GetPixel( n.Vertex ); + /* TODO + double a = std::fabs( x - double( this->m_Functor->GetUpperThreshold( ) ) ); + double b = std::fabs( x - double( this->m_LastThreshold ) ); + */ + if( labels->GetPixel( n.Vertex ) == 0 /* && b < a*/ ) + n.Value = 0; } // fi - this->GetOutput( )->SetPixel( n.Vertex, n.Value ); } +// ------------------------------------------------------------------------- +namespace CTBronchi +{ + template< class _TInputPtr, class _TOutputPtr, class _TInputValue > + void Label( + _TOutputPtr& output, + const _TInputPtr& input, const _TOutputPtr& input_labels, + const _TInputValue& last_thr, + std::map< std::string, std::string >& args + ) + { + typedef typename _TInputPtr::ObjectType _TInput; + typedef typename _TOutputPtr::ObjectType _TOutput; + typedef CTBronchi::MoriLabelling< _TInput, _TOutput > _TLabelling; + + typename _TLabelling::Pointer labelling = _TLabelling::New( ); + labelling->SetInput( input ); + labelling->SetInputLabels( input_labels ); + labelling->SetOutsideValue( 2 ); + labelling->SetInsideValue( 1 ); + labelling->SetUpperThreshold( + _TInputValue( std::atof( args[ "labelling_upper_threshold" ].c_str( ) ) ) + ); + labelling->SetLastThreshold( last_thr ); + double t = MeasureTime( labelling ); + std::cout << "Labelling executed in " << t << " s" << std::endl; + output = labelling->GetOutput( ); + std::map< std::string, std::string >::const_iterator i = + args.find( "out_labels" ); + if( i != args.end( ) ) + WriteImage( output, i->second ); + output->DisconnectPipeline( ); + } + +} // ecapseman + #endif // __CTBronchi__MoriLabelling__hxx__ // eof - $RCSfile$ diff --git a/appli/CTBronchi/Process.cxx b/appli/CTBronchi/Process.cxx index e169148..c5c9686 100644 --- a/appli/CTBronchi/Process.cxx +++ b/appli/CTBronchi/Process.cxx @@ -3,252 +3,154 @@ // @email florez-l@javeriana.edu.co // ========================================================================= -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include +#include +#include #include +#include // ------------------------------------------------------------------------- const unsigned int Dim = 3; typedef short TInputPixel; typedef unsigned char TLabelPixel; typedef float TScalar; -typedef itk::Image< TInputPixel, Dim > TInputImage; +typedef itk::Image< TInputPixel, Dim > TImage; typedef itk::Image< TLabelPixel, Dim > TLabelImage; typedef itk::Image< TScalar, Dim > TScalarImage; -typedef std::map< std::string, std::string > TMap; // ------------------------------------------------------------------------- -TMap Args; -TInputImage::PointType global_seed; -TLabelPixel inside_value = TLabelPixel( 1 ); -TLabelPixel outside_value = TLabelPixel( 0 ); -TLabelPixel inside_label = TLabelPixel( 1 ); -TLabelPixel outside_label = TLabelPixel( 2 ); +/* TODO + TMap Args; + TInputImage::PointType global_seed; + TLabelPixel inside_value = TLabelPixel( 1 ); + TLabelPixel outside_value = TLabelPixel( 0 ); + TLabelPixel inside_label = TLabelPixel( 1 ); + TLabelPixel outside_label = TLabelPixel( 2 ); +*/ // ------------------------------------------------------------------------- -double MeasureTime( itk::ProcessObject* f ) -{ - std::chrono::time_point< std::chrono::high_resolution_clock > s, e; - std::chrono::duration< double > t; - s = std::chrono::high_resolution_clock::now( ); - f->Update( ); - e = std::chrono::high_resolution_clock::now( ); - t = e - s; - return( t.count( ) ); -} - -// ------------------------------------------------------------------------- -template< class _TImagePtr > -void ReadImage( _TImagePtr& image, const std::string& fname ) -{ - typedef typename _TImagePtr::ObjectType _TImage; - typedef itk::ImageFileReader< _TImage > _TReader; - typename _TReader::Pointer reader = _TReader::New( ); - reader->SetFileName( fname ); - double t = MeasureTime( reader ); - std::cout << "Read " << fname << " in " << t << " s" << std::endl; - image = reader->GetOutput( ); - image->DisconnectPipeline( ); -} - -// ------------------------------------------------------------------------- -template< class _TImagePtr > -void WriteImage( const _TImagePtr& image, const std::string& fname ) -{ - typedef typename _TImagePtr::ObjectType _TImage; - typedef itk::ImageFileWriter< _TImage > _TWriter; - typename _TWriter::Pointer writer = _TWriter::New( ); - writer->SetFileName( fname ); - writer->SetInput( image ); - double t = MeasureTime( writer ); - std::cout << "Wrote " << fname << " in " << t << " s" << std::endl; -} - -// ------------------------------------------------------------------------- -template< class _TInputPtr, class _TOutputPtr > -void Mori( _TOutputPtr& output, const _TInputPtr& input ) -{ - typedef typename _TInputPtr::ObjectType _TInput; - typedef typename _TOutputPtr::ObjectType _TOutput; - typedef fpa::Filters::Image::Mori< _TInput, _TOutput > _TMori; - - typename _TMori::Pointer mori = _TMori::New( ); - mori->SetInput( input ); - mori->SetSeed( global_seed ); - mori->SetInsideValue( inside_value ); - mori->SetOutsideValue( outside_value ); - mori->SetMinimumThreshold( - TInputPixel( std::atof( Args[ "mori_minimum_threshold" ].c_str( ) ) ) - ); - mori->SetSignalKernelSize( - std::atoi( Args[ "mori_signal_kernel_size" ].c_str( ) ) - ); - mori->SetSignalThreshold( - std::atof( Args[ "mori_signal_threshold" ].c_str( ) ) - ); - mori->SetSignalInfluence( - std::atof( Args[ "mori_signal_influence" ].c_str( ) ) - ); - mori->SetThresholds( - TInputPixel( std::atof( Args[ "mori_lower_threshold" ].c_str( ) ) ), - TInputPixel( std::atof( Args[ "mori_upper_threshold" ].c_str( ) ) ), - TInputPixel( std::atof( Args[ "mori_delta_threshold" ].c_str( ) ) ) - ); - double t = MeasureTime( mori ); - std::cout << "Mori executed in " << t << " s" << std::endl; - output = mori->GetOutput( ); - - TMap::const_iterator i = Args.find( "out_mori" ); - if( i != Args.end( ) ) - WriteImage( output, i->second ); - - i = Args.find( "out_signal" ); - if( i != Args.end( ) ) - { - std::stringstream signal; - unsigned long nthr = mori->GetNumberOfEvaluatedThresholds( ); - signal << "# nThr = " << nthr << std::endl; - signal << "# Opt = " << mori->GetOptimumThreshold( ) << std::endl; - for( unsigned long j = 0; j < nthr; ++j ) - { - typename _TMori::TPeak p; - double x, y; - mori->GetSignalValues( j, x, y, p ); - signal << x << " " << y << std::endl; - - } // rof - - std::ofstream signals_str( i->second.c_str( ) ); - signals_str << signal.str( ); - signals_str.close( ); - - } // fi - output->DisconnectPipeline( ); -} - -// ------------------------------------------------------------------------- -template< class _TInputPtr, class _TOutputPtr > -void Label( _TOutputPtr& output, const _TInputPtr& input, const _TOutputPtr& labels ) -{ - typedef typename _TInputPtr::ObjectType _TInput; - typedef typename _TOutputPtr::ObjectType _TOutput; - typedef CTBronchi::MoriLabelling< _TInput, _TOutput > _TLabelling; - - typename _TLabelling::Pointer labelling = _TLabelling::New( ); - labelling->SetInput( input ); - labelling->SetInputLabels( labels ); - labelling->SetOutsideValue( outside_label ); - labelling->SetInsideValue( inside_label ); - labelling->SetInputInsideValue( inside_value ); - labelling->SetUpperThreshold( - TInputPixel( std::atof( Args[ "labelling_upper_threshold" ].c_str( ) ) ) - ); - double t = MeasureTime( labelling ); - std::cout << "Labelling executed in " << t << " s" << std::endl; - output = labelling->GetOutput( ); - TMap::const_iterator i = Args.find( "out_labels" ); - if( i != Args.end( ) ) - WriteImage( output, i->second ); - output->DisconnectPipeline( ); -} - -// ------------------------------------------------------------------------- -template< class _TRawPtr, class _TLabelPtr > -void RandomWalker( _TLabelPtr& output, const _TRawPtr& raw, const _TLabelPtr& labels ) -{ - typedef typename _TRawPtr::ObjectType _TRaw; - typedef typename _TLabelPtr::ObjectType _TLabel; -} - -// ------------------------------------------------------------------------- -bool ParseArgs( int argc, char* argv[] ) -{ - std::set< std::string > mandatory; - mandatory.insert( "in" ); - mandatory.insert( "out_segmentation" ); - mandatory.insert( "seed_x" ); - mandatory.insert( "seed_y" ); - mandatory.insert( "seed_z" ); - - Args[ "mori_minimum_threshold" ] = "-850"; - Args[ "mori_signal_kernel_size" ] = "20"; - Args[ "mori_signal_threshold" ] = "100"; - Args[ "mori_signal_influence" ] = "0.5"; - Args[ "mori_lower_threshold" ] = "-1024"; - Args[ "mori_upper_threshold" ] = "0"; - Args[ "mori_delta_threshold" ] = "1"; - Args[ "labelling_upper_threshold" ] = "-400"; - - for( int i = 1; i < argc; i += 2 ) - Args[ argv[ i ] + 1 ] = argv[ i + 1 ]; - - bool complete = true; - for( std::string t: mandatory ) - complete &= ( Args.find( t ) != Args.end( ) ); - - if( !complete ) - { - std::cerr - << "Usage: " << argv[ 0 ] << std::endl - << "\t-in filename" << std::endl - << "\t-out_segmentation filename" << std::endl - << "\t-seed_x value -seed_y value -seed_z value" << std::endl - << "\t[-out_mori filename]" << std::endl - << "\t[-out_signal filename]" << std::endl - << "\t[-out_labels filename]" << std::endl - << "\t[-mori_minimum_threshold value]" << std::endl - << "\t[-mori_signal_kernel_size value]" << std::endl - << "\t[-mori_signal_threshold value]" << std::endl - << "\t[-mori_signal_influence value]" << std::endl - << "\t[-mori_lower_threshold value]" << std::endl - << "\t[-mori_upper_threshold value]" << std::endl - << "\t[-mori_delta_threshold value]" << std::endl - << "\t[-labelling_upper_threshold value]" << std::endl; - return( false ); - - } // fi - return( true ); -} +/* TODO + template< class _TInputPtr, class _TOutputPtr > + void Label( _TOutputPtr& output, const _TInputPtr& input, const _TOutputPtr& labels ) + { + typedef typename _TInputPtr::ObjectType _TInput; + typedef typename _TOutputPtr::ObjectType _TOutput; + typedef CTBronchi::MoriLabelling< _TInput, _TOutput > _TLabelling; + + typename _TLabelling::Pointer labelling = _TLabelling::New( ); + labelling->SetInput( input ); + labelling->SetInputLabels( labels ); + labelling->SetOutsideValue( outside_label ); + labelling->SetInsideValue( inside_label ); + labelling->SetInputInsideValue( inside_value ); + labelling->SetUpperThreshold( + TInputPixel( std::atof( Args[ "labelling_upper_threshold" ].c_str( ) ) ) + ); + double t = MeasureTime( labelling ); + std::cout << "Labelling executed in " << t << " s" << std::endl; + output = labelling->GetOutput( ); + TMap::const_iterator i = Args.find( "out_labels" ); + if( i != Args.end( ) ) + WriteImage( output, i->second ); + output->DisconnectPipeline( ); + } + + // ------------------------------------------------------------------------- + template< class _TRawPtr, class _TLabelPtr > + void RandomWalker( _TLabelPtr& output, const _TRawPtr& raw, const _TLabelPtr& labels ) + { + typedef typename _TRawPtr::ObjectType _TRaw; + typedef typename _TLabelPtr::ObjectType _TLabel; + } + + // ------------------------------------------------------------------------- + bool ParseArgs( int argc, char* argv[] ) + { + std::set< std::string > mandatory; + mandatory.insert( "in" ); + mandatory.insert( "out_segmentation" ); + mandatory.insert( "seed_x" ); + mandatory.insert( "seed_y" ); + mandatory.insert( "seed_z" ); + + Args[ "mori_minimum_threshold" ] = "-850"; + Args[ "mori_signal_kernel_size" ] = "20"; + Args[ "mori_signal_threshold" ] = "100"; + Args[ "mori_signal_influence" ] = "0.5"; + Args[ "mori_lower_threshold" ] = "-1024"; + Args[ "mori_upper_threshold" ] = "0"; + Args[ "mori_delta_threshold" ] = "1"; + Args[ "labelling_upper_threshold" ] = "-400"; + + for( int i = 1; i < argc; i += 2 ) + Args[ argv[ i ] + 1 ] = argv[ i + 1 ]; + + bool complete = true; + for( std::string t: mandatory ) + complete &= ( Args.find( t ) != Args.end( ) ); + + if( !complete ) + { + std::cerr + << "Usage: " << argv[ 0 ] << std::endl + << "\t-in filename" << std::endl + << "\t-out_segmentation filename" << std::endl + << "\t-seed_x value -seed_y value -seed_z value" << std::endl + << "\t[-out_mori filename]" << std::endl + << "\t[-out_signal filename]" << std::endl + << "\t[-out_labels filename]" << std::endl + << "\t[-mori_minimum_threshold value]" << std::endl + << "\t[-mori_signal_kernel_size value]" << std::endl + << "\t[-mori_signal_threshold value]" << std::endl + << "\t[-mori_signal_influence value]" << std::endl + << "\t[-mori_lower_threshold value]" << std::endl + << "\t[-mori_upper_threshold value]" << std::endl + << "\t[-mori_delta_threshold value]" << std::endl + << "\t[-labelling_upper_threshold value]" << std::endl; + return( false ); + + } // fi + return( true ); + } +*/ // ------------------------------------------------------------------------- int main( int argc, char* argv[] ) { + std::map< std::string, std::string > args; try { - if( ParseArgs( argc, argv ) ) + if( CTBronchi::ParseArgs( args, argc, argv ) ) { // Parse seed - global_seed[ 0 ] = std::atof( Args[ "seed_x" ].c_str( ) ); - global_seed[ 1 ] = std::atof( Args[ "seed_y" ].c_str( ) ); - global_seed[ 2 ] = std::atof( Args[ "seed_z" ].c_str( ) ); + TImage::PointType seed; + char* str = new char[ args[ "seed" ].size( ) + 1 ]; + strcpy( str, args[ "seed" ].c_str( ) ); + seed[ 0 ] = std::atof( strtok( str, ";" ) ); + seed[ 1 ] = std::atof( strtok( NULL, ";" ) ); + seed[ 2 ] = std::atof( strtok( NULL, ";" ) ); // Read input image - TInputImage::Pointer input_image; - ReadImage( input_image, Args[ "in" ] ); + TImage::Pointer input_image; + CTBronchi::ReadImage( input_image, args[ "in" ] ); // Mori segmentation TLabelImage::Pointer mori; - Mori( mori, input_image ); + TInputPixel opt_thr = CTBronchi::Mori( mori, input_image, seed, args ); - // Create labels + // Label image TLabelImage::Pointer labels; - Label( labels, input_image, mori ); + CTBronchi::Label( labels, input_image, mori, opt_thr, args ); - return( 0 ); + // Final segmentation + TScalarImage::Pointer segmentation; + CTBronchi::RandomWalker( segmentation, input_image, labels, args ); - } // fi - return( 1 ); + // Save + CTBronchi::WriteImage( segmentation, args[ "out" ] ); + } + else + return( 1 ); } catch( std::exception& err ) { @@ -261,6 +163,36 @@ int main( int argc, char* argv[] ) return( 1 ); } // yrt + return( 0 ); + + /* TODO + try + { + if( ParseArgs( argc, argv ) ) + { + // Parse seed + global_seed[ 0 ] = std::atof( Args[ "seed_x" ].c_str( ) ); + global_seed[ 1 ] = std::atof( Args[ "seed_y" ].c_str( ) ); + global_seed[ 2 ] = std::atof( Args[ "seed_z" ].c_str( ) ); + + // Read input image + TInputImage::Pointer input_image; + ReadImage( input_image, Args[ "in" ] ); + + // Mori segmentation + TLabelImage::Pointer mori; + Mori( mori, input_image ); + + // Create labels + TLabelImage::Pointer labels; + Label( labels, input_image, mori ); + + return( 0 ); + + } // fi + return( 1 ); + } + */ /* TODO if [ -z "$label_upper_threshold" ]; then label_upper_threshold="-600"; fi if [ -z "$label_inside" ]; then label_inside="1"; fi diff --git a/appli/CTBronchi/RandomWalker.h b/appli/CTBronchi/RandomWalker.h new file mode 100644 index 0000000..0edb26d --- /dev/null +++ b/appli/CTBronchi/RandomWalker.h @@ -0,0 +1,48 @@ +// ========================================================================= +// @author Leonardo Florez Valencia +// @email florez-l@javeriana.edu.co +// ========================================================================= +#ifndef __CTBronchi__RandomWalker__h__ +#define __CTBronchi__RandomWalker__h__ + +#include +#include +#include +#include + +namespace CTBronchi +{ + // ----------------------------------------------------------------------- + template< class _TInputPtr, class _TOutputPtr, class _TLabelPtr > + void RandomWalker( + _TOutputPtr& output, + const _TInputPtr& input, const _TLabelPtr& labels, + std::map< std::string, std::string >& args + ) + { + typedef typename _TInputPtr::ObjectType _TInput; + typedef typename _TOutputPtr::ObjectType _TOutput; + typedef typename _TLabelPtr::ObjectType _TLabel; + typedef typename _TOutput::PixelType _TOutputPixel; + typedef fpa::Filters::Image::RandomWalker< _TInput, _TLabel, _TOutputPixel > _TRandomWalker; + typedef fpa::Functors::Dijkstra::Image::Gaussian< _TInput, _TOutputPixel > _TWeight; + + typename _TWeight::Pointer weight = _TWeight::New( ); + weight->SetAlpha( std::atof( args[ "random_walker_alpha" ].c_str( ) ) ); + weight->SetBeta( std::atof( args[ "random_walker_beta" ].c_str( ) ) ); + + typename _TRandomWalker::Pointer rw = _TRandomWalker::New( ); + rw->SetInputImage( input ); + rw->SetInputLabels( labels ); + rw->SetWeightFunction( weight ); + double t = CTBronchi::MeasureTime( rw ); + std::cout << "RandomWalker executed in " << t << " s" << std::endl; + output = rw->GetOutput( ); + output->DisconnectPipeline( ); + } + +} // ecapseman + +#endif // __CTBronchi__Functions__h__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Filters/Image/SeedsFromLabelsInterface.hxx b/lib/fpa/Filters/Image/SeedsFromLabelsInterface.hxx index 8f58ba4..908bd1a 100644 --- a/lib/fpa/Filters/Image/SeedsFromLabelsInterface.hxx +++ b/lib/fpa/Filters/Image/SeedsFromLabelsInterface.hxx @@ -64,7 +64,7 @@ _PrepareSeeds( const itk::DataObject* reference ) node.Vertex = lIt.GetIndex( ); node.Parent = lIt.GetIndex( ); node.FrontId = lIt.Get( ); - node.Value = TOutputValue( 0 ); + node.Value = lIt.Get( ); if( !is_seed ) { this->_AssignOutputValue( node );