1 #ifndef __fpa__Image__MoriFilterHelper__hxx__
2 #define __fpa__Image__MoriFilterHelper__hxx__
4 // -------------------------------------------------------------------------
5 template< class _TInputImage, class _TOutputImage >
6 fpa::Image::MoriFilterHelper< _TInputImage, _TOutputImage >::
11 this->m_Upper = std::numeric_limits< TPixel >::max( );
12 if( std::numeric_limits< TPixel >::is_integer )
13 this->m_Lower = std::numeric_limits< TPixel >::min( );
15 this->m_Lower = -this->m_Upper;
16 typename TBinThresholdFunction::Pointer functor =
17 TBinThresholdFunction::New( );
18 this->SetGrowFunction( functor );
21 // -------------------------------------------------------------------------
22 template< class _TInputImage, class _TOutputImage >
23 fpa::Image::MoriFilterHelper< _TInputImage, _TOutputImage >::
28 // -------------------------------------------------------------------------
29 template< class _TInputImage, class _TOutputImage >
30 bool fpa::Image::MoriFilterHelper< _TInputImage, _TOutputImage >::
31 _ContinueGenerateData( )
33 TBinThresholdFunction* functor =
34 dynamic_cast< TBinThresholdFunction* >( this->GetGrowFunction( ) );
35 TPixel u = functor->GetUpper( );
37 // Update flooding data
38 this->m_Curve.push_back( TCurveData( u, this->m_ActualCount ) );
39 std::cout << u << " " << this->m_ActualCount << std::endl;
42 if( u < this->m_Upper )
45 if( u > this->m_Upper )
47 functor->SetUpper( u );
48 this->m_Queue = this->m_NextQueue;
49 while( this->m_NextQueue.size( ) > 0 )
50 this->m_NextQueue.pop( );
57 // -------------------------------------------------------------------------
58 template< class _TInputImage, class _TOutputImage >
59 void fpa::Image::MoriFilterHelper< _TInputImage, _TOutputImage >::
60 _BeforeGenerateData( )
62 this->Superclass::_BeforeGenerateData( );
64 while( this->m_NextQueue.size( ) > 0 )
65 this->m_NextQueue.pop( );
66 this->m_OptimumThreshold = ( typename _TOutputImage::PixelType )( 0 );
67 this->m_ActualCount = 0;
68 this->m_Curve.clear( );
69 TBinThresholdFunction* functor =
70 dynamic_cast< TBinThresholdFunction* >( this->GetGrowFunction( ) );
71 functor->SetLower( this->m_Lower );
72 functor->SetUpper( this->m_Lower + this->m_Step );
75 // -------------------------------------------------------------------------
76 template< class _TInputImage, class _TOutputImage >
77 void fpa::Image::MoriFilterHelper< _TInputImage, _TOutputImage >::
80 typedef typename _TOutputImage::PixelType _TOut;
82 this->Superclass::_AfterGenerateData( );
83 while( this->m_NextQueue.size( ) > 0 )
84 this->m_NextQueue.pop( );
86 // Find optimum threshold by dicotomy
88 unsigned long r = this->m_Curve.size( ) - 1;
89 while( ( r - l ) > 1 )
91 unsigned long m = ( r + l ) >> 1;
92 double vm = double( this->m_Curve[ m ].second );
93 double dl = vm - double( this->m_Curve[ l ].second );
94 double dr = double( this->m_Curve[ r ].second ) - vm;
101 this->m_OptimumThreshold = _TOut( ( r + l ) >> 1 );
104 // -------------------------------------------------------------------------
105 template< class _TInputImage, class _TOutputImage >
106 void fpa::Image::MoriFilterHelper< _TInputImage, _TOutputImage >::
109 this->Superclass::_BeforeLoop( );
112 // -------------------------------------------------------------------------
113 template< class _TInputImage, class _TOutputImage >
114 void fpa::Image::MoriFilterHelper< _TInputImage, _TOutputImage >::
117 this->Superclass::_AfterLoop( );
120 // -------------------------------------------------------------------------
121 template< class _TInputImage, class _TOutputImage >
122 bool fpa::Image::MoriFilterHelper< _TInputImage, _TOutputImage >::
123 _UpdateValue( _TQueueNode& v, const _TQueueNode& p )
125 typedef typename _TOutputImage::PixelType _TOut;
127 bool ret = this->Superclass::_UpdateValue( v, p );
128 v.Result = _TOut( this->m_Curve.size( ) + 1 );
130 this->m_NextQueue.push( v );
134 // -------------------------------------------------------------------------
135 template< class _TInputImage, class _TOutputImage >
136 void fpa::Image::MoriFilterHelper< _TInputImage, _TOutputImage >::
137 _UpdateResult( const _TQueueNode& n )
139 this->Superclass::_UpdateResult( n );
140 this->m_ActualCount += 1;
143 #endif // __fpa__Image__MoriFilterHelper__hxx__