]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Image/Functors/GaussianModelEstimatorFunction.hxx
accfb27825bf66fb6a34918c325499aa149ceb24
[FrontAlgorithms.git] / lib / fpa / Image / Functors / GaussianModelEstimatorFunction.hxx
1 #ifndef __FPA__IMAGE__FUNCTORS__GAUSSIANMODELESTIMATORFUNCTION__HXX__
2 #define __FPA__IMAGE__FUNCTORS__GAUSSIANMODELESTIMATORFUNCTION__HXX__
3
4 // -------------------------------------------------------------------------
5 template< class I, class S >
6 bool fpa::Image::Functors::GaussianModelEstimatorFunction< I, S >::
7 SaveModelToFile( const std::string& filename ) const
8 {
9   this->m_Estimator->SaveModelToFile( filename );
10 }
11
12 // -------------------------------------------------------------------------
13 template< class I, class S >
14 bool fpa::Image::Functors::GaussianModelEstimatorFunction< I, S >::
15 LoadModelFromFile( const std::string& filename )
16 {
17   this->m_Estimator->LoadModelFromFile( filename );
18   this->m_RealModelSupport =
19     this->m_ModelSupport + this->m_Estimator->GetNumberOfSamples( );
20   this->m_Estimating = false;
21   this->Modified( );
22 }
23
24 // -------------------------------------------------------------------------
25 template< class I, class S >
26 void fpa::Image::Functors::GaussianModelEstimatorFunction< I, S >::
27 SetModelSupport( const unsigned long& s )
28 {
29   this->m_ModelSupport = s;
30   this->m_RealModelSupport = s;
31   this->Modified( );
32 }
33
34 // -------------------------------------------------------------------------
35 template< class I, class S >
36 bool fpa::Image::Functors::GaussianModelEstimatorFunction< I, S >::
37 Evaluate( const typename I::PixelType& rgb ) const
38 {
39   if( !this->m_Estimating && this->m_ModelSupport > 0 )
40   {
41     this->m_Estimator->AddSample( this->m_YPbPrFunction( rgb ) );
42     if( this->m_Estimator->GetNumberOfSamples( ) == this->m_RealModelSupport )
43       this->m_Estimating = true;
44     return( true );
45   }
46   else
47   {
48     S p = this->m_Estimator->Probability( this->m_YPbPrFunction( rgb ) );
49     return( p >= 0.3 );
50
51   } // fi
52 }
53
54 // -------------------------------------------------------------------------
55 template< class I, class S >
56 fpa::Image::Functors::GaussianModelEstimatorFunction< I, S >::
57 GaussianModelEstimatorFunction( )
58   : Superclass( ),
59     m_ModelSupport( 10 ),
60     m_RealModelSupport( 10 )
61 {
62   this->m_Estimator = TEstimator::New( );
63   this->m_Estimator->Clear( );
64   this->m_Estimating = false;
65 }
66
67 // -------------------------------------------------------------------------
68 template< class I, class S >
69 fpa::Image::Functors::GaussianModelEstimatorFunction< I, S >::
70 ~GaussianModelEstimatorFunction( )
71 {
72 }
73
74 #endif // __FPA__IMAGE__FUNCTORS__GAUSSIANMODELESTIMATORFUNCTION__HXX__
75
76 // eof - $RCSfile$