From 781520794cb7530b882effe7222dde78f1039eb3 Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Mon, 6 Apr 2015 21:42:16 -0500 Subject: [PATCH] Some bugs... --- ...age_RegionGrow_GaussianModelEstimation.cxx | 86 ++----------------- .../Functors/GaussianModelEstimatorFunction.h | 68 +++++++++++++++ .../GaussianModelEstimatorFunction.hxx | 49 +++++++++++ 3 files changed, 123 insertions(+), 80 deletions(-) create mode 100644 lib/fpa/Image/Functors/GaussianModelEstimatorFunction.h create mode 100644 lib/fpa/Image/Functors/GaussianModelEstimatorFunction.hxx diff --git a/appli/examples/example_Image_RegionGrow_GaussianModelEstimation.cxx b/appli/examples/example_Image_RegionGrow_GaussianModelEstimation.cxx index 919409a..2d27878 100644 --- a/appli/examples/example_Image_RegionGrow_GaussianModelEstimation.cxx +++ b/appli/examples/example_Image_RegionGrow_GaussianModelEstimation.cxx @@ -21,12 +21,9 @@ #include #include -#include -#include - #include -#include #include +#include // ------------------------------------------------------------------------- const unsigned int Dim = 2; @@ -37,81 +34,6 @@ typedef itk::Image< itk::RGBPixel< TPixel >, Dim > TColorImage; typedef itk::Image< TPixel, Dim > TImage; typedef itk::ImageToVTKImageFilter< TColorImage > TVTKImage; -// ------------------------------------------------------------------------- -template< class I, class S > -class GaussianFunction - : public itk::FunctionBase< typename I::PixelType, bool > -{ -public: - // Type-related and pointers - typedef GaussianFunction Self; - typedef itk::FunctionBase< typename I::PixelType, bool > Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; - - // Superclass' types - typedef cpPlugins::Extensions::Algorithms::IterativeGaussianModelEstimator< S, 3 > TEstimator; - typedef cpPlugins::Extensions::Algorithms::RGBToYPbPrFunction< S > TYPbPrFunction; - -public: - itkNewMacro( Self ); - itkTypeMacro( GaussianFunction, itkFunctionBase ); - - itkGetConstMacro( ModelSupport, unsigned long ); - itkSetMacro( ModelSupport, unsigned long ); - -public: - virtual bool Evaluate( const typename I::PixelType& rgb ) const - { - /* TODO - if( !this->m_Estimating ) - { - this->m_Estimator->AddSample( this->m_YPbPrFunction( rgb ) ); - if( this->m_Estimator->GetNumberOfSamples( ) == this->m_ModelSupport ) - { - this->m_Estimating = true; - this->m_Estimator->UpdateModel( ); - std::cout << this->m_Estimator->GetMinimumProbability( ) << std::endl; - std::cout << this->m_Estimator->GetMaximumProbability( ) << std::endl; - - } // fi - return( true ); - } - else - { - S p = this->m_Estimator->Probability( this->m_YPbPrFunction( rgb ) ); - return( p > this->m_Estimator->GetMinimumProbability( ) ); - - } // fi - */ - return( true ); - } - -protected: - GaussianFunction( ) - : Superclass( ), - m_ModelSupport( 10 ) - { - this->m_Estimator = TEstimator::New( ); - this->m_Estimator->Clear( ); - this->m_Estimating = false; - } - virtual ~GaussianFunction( ) - { } - -private: - // Purposely not implemented - GaussianFunction( const Self& ); - void operator=( const Self& ); - -protected: - typename TEstimator::Pointer m_Estimator; - TYPbPrFunction m_YPbPrFunction; - - unsigned long m_ModelSupport; - mutable bool m_Estimating; -}; - // ------------------------------------------------------------------------- int main( int argc, char* argv[] ) { @@ -198,7 +120,7 @@ int main( int argc, char* argv[] ) interactor->Start( ); // Prepare region grow function - typedef GaussianFunction< TColorImage, TScalar > TFunction; + typedef fpa::Image::Functors::GaussianModelEstimatorFunction< TColorImage, TScalar > TFunction; TFunction::Pointer function = TFunction::New( ); function->SetModelSupport( support ); @@ -239,6 +161,10 @@ int main( int argc, char* argv[] ) // Go! filter->Update( ); + window->Render( ); + widget->Off( ); + interactor->Start( ); + return( 0 ); } diff --git a/lib/fpa/Image/Functors/GaussianModelEstimatorFunction.h b/lib/fpa/Image/Functors/GaussianModelEstimatorFunction.h new file mode 100644 index 0000000..1017803 --- /dev/null +++ b/lib/fpa/Image/Functors/GaussianModelEstimatorFunction.h @@ -0,0 +1,68 @@ +#ifndef __FPA__IMAGE__FUNCTORS__GAUSSIANMODELESTIMATORFUNCTION__H__ +#define __FPA__IMAGE__FUNCTORS__GAUSSIANMODELESTIMATORFUNCTION__H__ + +#include +#include +#include + +namespace fpa +{ + namespace Image + { + namespace Functors + { + /** + */ + template< class I, class S > + class GaussianModelEstimatorFunction + : public itk::FunctionBase< typename I::PixelType, bool > + { + public: + // Type-related and pointers + typedef GaussianModelEstimatorFunction Self; + typedef itk::FunctionBase< typename I::PixelType, bool > Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + // Superclass' types + typedef cpPlugins::Extensions::Algorithms::IterativeGaussianModelEstimator< S, 3 > TEstimator; + typedef cpPlugins::Extensions::Algorithms::RGBToYPbPrFunction< S > TYPbPrFunction; + + public: + itkNewMacro( Self ); + itkTypeMacro( GaussianModelEstimatorFunction, itkFunctionBase ); + + itkGetConstMacro( ModelSupport, unsigned long ); + itkSetMacro( ModelSupport, unsigned long ); + + public: + virtual bool Evaluate( const typename I::PixelType& rgb ) const; + + protected: + GaussianModelEstimatorFunction( ); + virtual ~GaussianModelEstimatorFunction( ); + + private: + // Purposely not implemented + GaussianModelEstimatorFunction( const Self& ); + void operator=( const Self& ); + + protected: + typename TEstimator::Pointer m_Estimator; + TYPbPrFunction m_YPbPrFunction; + + unsigned long m_ModelSupport; + mutable bool m_Estimating; + }; + + } // ecapseman + + } // ecapseman + +} // ecapseman + +#include + +#endif // __FPA__IMAGE__FUNCTORS__GAUSSIANMODELESTIMATORFUNCTION__H__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Image/Functors/GaussianModelEstimatorFunction.hxx b/lib/fpa/Image/Functors/GaussianModelEstimatorFunction.hxx new file mode 100644 index 0000000..a90a39a --- /dev/null +++ b/lib/fpa/Image/Functors/GaussianModelEstimatorFunction.hxx @@ -0,0 +1,49 @@ +#ifndef __FPA__IMAGE__FUNCTORS__GAUSSIANMODELESTIMATORFUNCTION__HXX__ +#define __FPA__IMAGE__FUNCTORS__GAUSSIANMODELESTIMATORFUNCTION__HXX__ + +// ------------------------------------------------------------------------- +template< class I, class S > +bool fpa::Image::Functors::GaussianModelEstimatorFunction< I, S >:: +Evaluate( const typename I::PixelType& rgb ) const +{ + if( !this->m_Estimating ) + { + this->m_Estimator->AddSample( this->m_YPbPrFunction( rgb ) ); + if( this->m_Estimator->GetNumberOfSamples( ) == this->m_ModelSupport ) + { + this->m_Estimating = true; + this->m_Estimator->UpdateModel( ); + + } // fi + return( true ); + } + else + { + S p = this->m_Estimator->Probability( this->m_YPbPrFunction( rgb ) ); + return( p > this->m_Estimator->GetMinimumProbability( ) ); + + } // fi +} + +// ------------------------------------------------------------------------- +template< class I, class S > +fpa::Image::Functors::GaussianModelEstimatorFunction< I, S >:: +GaussianModelEstimatorFunction( ) + : Superclass( ), + m_ModelSupport( 10 ) +{ + this->m_Estimator = TEstimator::New( ); + this->m_Estimator->Clear( ); + this->m_Estimating = false; +} + +// ------------------------------------------------------------------------- +template< class I, class S > +fpa::Image::Functors::GaussianModelEstimatorFunction< I, S >:: +~GaussianModelEstimatorFunction( ) +{ +} + +#endif // __FPA__IMAGE__FUNCTORS__GAUSSIANMODELESTIMATORFUNCTION__HXX__ + +// eof - $RCSfile$ -- 2.45.1