1 #ifndef __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__
2 #define __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__
5 #include <fpa/Image/Functors/RegionGrowThresholdFunction.h>
7 // -------------------------------------------------------------------------
9 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
10 AddThreshold( const TPixel& v )
13 fpa::Image::Functors::RegionGrowThresholdFunction< I >
15 typename TFunction::Pointer function = TFunction::New( );
17 if( this->GetNumberOfMembershipFunctions( ) > 0 )
21 function->SetLowerThreshold( std::numeric_limits< TPixel >::min( ) );
23 << typeid( TPixel ).name( ) << " <<<----->>> "
24 << function->GetLowerThreshold( )
27 function->SetUpperThreshold( v );
28 this->AddMembershipFunction( function );
31 this->m_Histogram[ v ] = 0;
34 dynamic_cast< TFunction* >( this->GetMembershipFunction( ) );
35 if( function != NULL )
37 function->SetLowerThreshold( this->m_Histogram.begin( )->first );
44 // -------------------------------------------------------------------------
46 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
47 AddThresholds( const TPixel& t0, const TPixel& t1, const unsigned int& s )
49 double o = ( double( t1 ) - double( t0 ) ) / ( double( s ) - double( 1 ) );
50 for( unsigned int i = 0; i < s; i++ )
51 this->AddThreshold( TPixel( ( double( i ) * o ) + double( t0 ) ) );
54 // -------------------------------------------------------------------------
56 fpa::Image::RegionGrowWithMultipleThresholds< I >::
57 RegionGrowWithMultipleThresholds( )
59 m_DerivativeThreshold( double( 3 ) )
63 fpa::Image::Functors::RegionGrowThresholdFunction< I >
65 typename TFunction::Pointer function = TFunction::New( );
66 this->SetMembershipFunction( function );
70 // -------------------------------------------------------------------------
72 fpa::Image::RegionGrowWithMultipleThresholds< I >::
73 ~RegionGrowWithMultipleThresholds( )
77 // -------------------------------------------------------------------------
79 bool fpa::Image::RegionGrowWithMultipleThresholds< I >::
80 _UpdateResult( _TNode& n )
82 bool ret = this->Superclass::_UpdateResult( n );
87 TPixel v = TPixel( this->_Cost( n.Vertex, n.Vertex ) );
89 typename THistogram::reverse_iterator hIt = this->m_Histogram.rbegin( );
90 while( hIt != this->m_Histogram.rend( ) )
98 hIt = this->m_Histogram.rend( );
101 this->GetOutput( )->SetPixel( n.Vertex, v );
108 // -------------------------------------------------------------------------
110 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
113 std::cout << "**1" << std::endl;
114 const I* img = this->GetInput( );
115 std::cout << "**2" << std::endl;
116 typename TFunctions::iterator fIt = this->m_Functions.begin( );
117 for( ; fIt != this->m_Functions.end( ); ++fIt )
119 TMembershipFunction* f =
120 dynamic_cast< TMembershipFunction* >( fIt->GetPointer( ) );
122 f->SetInputImage( this->GetInput( ) );
125 this->Superclass::_BeforeLoop( );
128 // -------------------------------------------------------------------------
130 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
134 typename THistogram::iterator prevIt = this->m_Histogram.begin( );
135 typename THistogram::iterator currIt = prevIt; currIt++;
136 typename THistogram::iterator nextIt = currIt; nextIt++;
137 double prev_d1 = double( 0 );
138 for( ; nextIt != this->m_Histogram.end( ); ++prevIt, ++currIt, ++nextIt )
140 double d1 = double( nextIt->second ) - double( prevIt->second );
141 d1 /= double( nextIt->first ) - double( prevIt->first );
144 << currIt->first << " "
145 << currIt->second << " "
147 << ( d1 - prev_d1 ) << std::endl;
155 double prev = double( 0 );
156 while( hIt != this->m_Histogram.end( ) )
158 double curr = double( hIt->second );
159 double deri = curr - prev;
161 if( hIt != this->m_Histogram.begin( ) )
162 std::cout << hIt->first << " " << curr << " " << deri << std::endl;
169 this->Superclass::_AfterLoop( );
172 #endif // __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__