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( )
26 function->SetUpperThreshold( v );
27 this->AddMembershipFunction( function );
30 this->m_Histogram[ v ] = 0;
33 dynamic_cast< TFunction* >( this->GetMembershipFunction( ) );
34 if( function != NULL )
36 function->SetLowerThreshold( this->m_Histogram.begin( )->first );
43 // -------------------------------------------------------------------------
45 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
46 AddThresholds( const TPixel& t0, const TPixel& t1, const unsigned int& s )
48 double o = ( double( t1 ) - double( t0 ) ) / ( double( s ) - double( 1 ) );
49 for( unsigned int i = 0; i < s; i++ )
50 this->AddThreshold( TPixel( ( double( i ) * o ) + double( t0 ) ) );
53 // -------------------------------------------------------------------------
55 fpa::Image::RegionGrowWithMultipleThresholds< I >::
56 RegionGrowWithMultipleThresholds( )
58 m_DerivativeThreshold( double( 3 ) )
62 fpa::Image::Functors::RegionGrowThresholdFunction< I >
64 typename TFunction::Pointer function = TFunction::New( );
65 this->SetMembershipFunction( function );
69 // -------------------------------------------------------------------------
71 fpa::Image::RegionGrowWithMultipleThresholds< I >::
72 ~RegionGrowWithMultipleThresholds( )
76 // -------------------------------------------------------------------------
78 bool fpa::Image::RegionGrowWithMultipleThresholds< I >::
79 _UpdateResult( _TNode& n )
81 bool ret = this->Superclass::_UpdateResult( n );
86 TPixel v = TPixel( this->_Cost( n.Vertex, n.Vertex ) );
88 typename THistogram::reverse_iterator hIt = this->m_Histogram.rbegin( );
89 while( hIt != this->m_Histogram.rend( ) )
97 hIt = this->m_Histogram.rend( );
100 this->GetOutput( )->SetPixel( n.Vertex, v );
107 // -------------------------------------------------------------------------
109 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
112 std::cout << "**1" << std::endl;
113 const I* img = this->GetInput( );
114 std::cout << "**2" << std::endl;
115 typename TFunctions::iterator fIt = this->m_Functions.begin( );
116 for( ; fIt != this->m_Functions.end( ); ++fIt )
118 TMembershipFunction* f =
119 dynamic_cast< TMembershipFunction* >( fIt->GetPointer( ) );
121 f->SetInputImage( this->GetInput( ) );
124 this->Superclass::_BeforeLoop( );
127 // -------------------------------------------------------------------------
129 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
133 typename THistogram::iterator prevIt = this->m_Histogram.begin( );
134 typename THistogram::iterator currIt = prevIt; currIt++;
135 typename THistogram::iterator nextIt = currIt; nextIt++;
136 double prev_d1 = double( 0 );
137 for( ; nextIt != this->m_Histogram.end( ); ++prevIt, ++currIt, ++nextIt )
139 double d1 = double( nextIt->second ) - double( prevIt->second );
140 d1 /= double( nextIt->first ) - double( prevIt->first );
143 << currIt->first << " "
144 << currIt->second << " "
146 << ( d1 - prev_d1 ) << std::endl;
154 double prev = double( 0 );
155 while( hIt != this->m_Histogram.end( ) )
157 double curr = double( hIt->second );
158 double deri = curr - prev;
160 if( hIt != this->m_Histogram.begin( ) )
161 std::cout << hIt->first << " " << curr << " " << deri << std::endl;
168 this->Superclass::_AfterLoop( );
171 #endif // __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__