1 #ifndef __fpa__Image__MoriRegionGrow__hxx__
2 #define __fpa__Image__MoriRegionGrow__hxx__
4 // -------------------------------------------------------------------------
5 template< class _TInputImage, class _TOutputImage >
6 fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
10 m_Sensitivity( double( 1 ) )
12 this->m_Upper = std::numeric_limits< TPixel >::max( );
13 if( std::numeric_limits< TPixel >::is_integer )
14 this->m_Lower = std::numeric_limits< TPixel >::min( );
16 this->m_Lower = -this->m_Upper;
17 typename TBinThresholdFunction::Pointer functor =
18 TBinThresholdFunction::New( );
19 this->SetGrowFunction( functor );
22 // -------------------------------------------------------------------------
23 template< class _TInputImage, class _TOutputImage >
24 fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
29 // -------------------------------------------------------------------------
30 template< class _TInputImage, class _TOutputImage >
31 bool fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
32 _ContinueGenerateData( )
34 TBinThresholdFunction* functor =
35 dynamic_cast< TBinThresholdFunction* >( this->GetGrowFunction( ) );
36 TPixel u = functor->GetUpper( );
40 if( this->m_N > double( 10 ) )
42 double Q = double( this->m_PrevCount );
43 Q += ( this->m_STD * this->m_Sensitivity );
44 if( double( this->m_ActualCount ) > Q )
49 if( this->m_PrevCount > 0 )
50 v = double( this->m_ActualCount ) - double( this->m_PrevCount );
53 this->m_PrevCount = this->m_ActualCount;
54 this->m_N += double( 1 );
57 if( this->m_N > double( 1 ) )
59 ( this->m_S2 - ( ( this->m_S1 * this->m_S1 ) / this->m_N ) ) /
60 ( this->m_N - double( 1 ) );
62 this->m_STD = double( 0 );
63 this->m_STD = std::sqrt( this->m_STD );
65 std::cout << u << " " << this->m_ActualCount << " " << this->m_STD << std::endl;
67 if( u < this->m_Upper )
70 if( u > this->m_Upper )
72 functor->SetUpper( u );
73 this->m_Queue = this->m_NextQueue;
74 while( this->m_NextQueue.size( ) > 0 )
75 this->m_NextQueue.pop( );
82 // -------------------------------------------------------------------------
83 template< class _TInputImage, class _TOutputImage >
84 void fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
85 _BeforeGenerateData( )
87 this->Superclass::_BeforeGenerateData( );
89 while( this->m_NextQueue.size( ) > 0 )
90 this->m_NextQueue.pop( );
91 this->m_ActualCount = 0;
92 this->m_PrevCount = 0;
93 this->m_N = double( 0 );
94 this->m_S1 = double( 0 );
95 this->m_S2 = double( 0 );
96 this->m_STD = double( 0 );
97 TBinThresholdFunction* functor =
98 dynamic_cast< TBinThresholdFunction* >( this->GetGrowFunction( ) );
99 functor->SetLower( this->m_Lower );
100 functor->SetUpper( this->m_Lower + this->m_Step );
103 // -------------------------------------------------------------------------
104 template< class _TInputImage, class _TOutputImage >
105 void fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
106 _AfterGenerateData( )
108 this->Superclass::_AfterGenerateData( );
109 while( this->m_NextQueue.size( ) > 0 )
110 this->m_NextQueue.pop( );
113 // -------------------------------------------------------------------------
114 template< class _TInputImage, class _TOutputImage >
115 void fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
118 this->Superclass::_BeforeLoop( );
121 // -------------------------------------------------------------------------
122 template< class _TInputImage, class _TOutputImage >
123 void fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
126 this->Superclass::_AfterLoop( );
129 // -------------------------------------------------------------------------
130 template< class _TInputImage, class _TOutputImage >
131 bool fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
132 _UpdateValue( _TQueueNode& v, const _TQueueNode& p )
134 bool ret = this->Superclass::_UpdateValue( v, p );
137 v.Result = this->m_InsideValue;
138 this->m_NextQueue.push( v );
144 // -------------------------------------------------------------------------
145 template< class _TInputImage, class _TOutputImage >
146 void fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
147 _UpdateResult( const _TQueueNode& n )
149 this->Superclass::_UpdateResult( n );
150 this->m_ActualCount += 1;
153 #endif // __fpa__Image__MoriRegionGrow__hxx__