1 #ifndef __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__
2 #define __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__
4 #include <fpa/Image/Functors/RegionGrowThresholdFunction.h>
6 // -------------------------------------------------------------------------
8 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
9 AddThreshold( const TPixel& v )
11 this->m_Histogram[ v ] = 0;
15 fpa::Image::Functors::RegionGrowThresholdFunction< I >
18 dynamic_cast< TFunction* >( this->GetMembershipFunction( ) );
19 if( function != NULL )
21 function->SetLowerThreshold( this->m_Histogram.begin( )->first );
22 function->SetUpperThreshold( this->m_Histogram.rbegin( )->first );
29 // -------------------------------------------------------------------------
31 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
32 AddThresholds( const TPixel& t0, const TPixel& t1, const unsigned int& s )
34 double o = ( double( t1 ) - double( t0 ) ) / ( double( s ) - double( 1 ) );
35 for( unsigned int i = 0; i < s; i++ )
36 this->AddThreshold( TPixel( ( double( i ) * o ) + double( t0 ) ) );
39 // -------------------------------------------------------------------------
41 fpa::Image::RegionGrowWithMultipleThresholds< I >::
42 RegionGrowWithMultipleThresholds( )
44 m_DerivativeThreshold( double( 3 ) )
47 fpa::Image::Functors::RegionGrowThresholdFunction< I >
49 typename TFunction::Pointer function = TFunction::New( );
50 this->SetMembershipFunction( function );
53 // -------------------------------------------------------------------------
55 fpa::Image::RegionGrowWithMultipleThresholds< I >::
56 ~RegionGrowWithMultipleThresholds( )
60 // -------------------------------------------------------------------------
62 bool fpa::Image::RegionGrowWithMultipleThresholds< I >::
63 _UpdateResult( _TNode& n )
65 bool ret = this->Superclass::_UpdateResult( n );
69 TPixel v = TPixel( this->_Cost( n.Vertex, n.Vertex ) );
71 typename THistogram::reverse_iterator hIt = this->m_Histogram.rbegin( );
72 while( hIt != this->m_Histogram.rend( ) )
80 hIt = this->m_Histogram.rend( );
83 this->GetOutput( )->SetPixel( n.Vertex, v );
89 // -------------------------------------------------------------------------
91 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
95 typename THistogram::iterator prevIt = this->m_Histogram.begin( );
96 typename THistogram::iterator currIt = prevIt; currIt++;
97 typename THistogram::iterator nextIt = currIt; nextIt++;
98 double prev_d1 = double( 0 );
99 for( ; nextIt != this->m_Histogram.end( ); ++prevIt, ++currIt, ++nextIt )
101 double d1 = double( nextIt->second ) - double( prevIt->second );
102 d1 /= double( nextIt->first ) - double( prevIt->first );
105 << currIt->first << " "
106 << currIt->second << " "
108 << ( d1 - prev_d1 ) << std::endl;
116 double prev = double( 0 );
117 while( hIt != this->m_Histogram.end( ) )
119 double curr = double( hIt->second );
120 double deri = curr - prev;
122 if( hIt != this->m_Histogram.begin( ) )
123 std::cout << hIt->first << " " << curr << " " << deri << std::endl;
130 this->Superclass::_AfterLoop( );
133 #endif // __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__