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;
14 fpa::Image::Functors::RegionGrowThresholdFunction< I >
17 dynamic_cast< TFunction* >( this->GetMembershipFunction( ) );
18 if( function != NULL )
20 function->SetLowerThreshold( this->m_Histogram.begin( )->first );
21 function->SetUpperThreshold( this->m_Histogram.rbegin( )->first );
27 // -------------------------------------------------------------------------
29 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
33 const unsigned int& samples
37 ( double( t1 ) - double( t0 ) ) / ( double( samples ) - double( 1 ) );
38 for( unsigned int s = 0; s < samples; s++ )
39 this->AddThreshold( TPixel( ( double( s ) * off ) + double( t0 ) ) );
42 // -------------------------------------------------------------------------
44 fpa::Image::RegionGrowWithMultipleThresholds< I >::
45 RegionGrowWithMultipleThresholds( )
47 m_DerivativeThreshold( double( 3 ) )
50 fpa::Image::Functors::RegionGrowThresholdFunction< I >
52 typename TFunction::Pointer function = TFunction::New( );
53 this->SetMembershipFunction( function );
56 // -------------------------------------------------------------------------
58 fpa::Image::RegionGrowWithMultipleThresholds< I >::
59 ~RegionGrowWithMultipleThresholds( )
63 // -------------------------------------------------------------------------
65 bool fpa::Image::RegionGrowWithMultipleThresholds< I >::
66 _UpdateResult( _TNode& n )
68 bool ret = this->Superclass::_UpdateResult( n );
72 TPixel v = TPixel( this->_Cost( n.Vertex, n.Vertex ) );
74 typename THistogram::reverse_iterator hIt = this->m_Histogram.rbegin( );
75 while( hIt != this->m_Histogram.rend( ) )
83 hIt = this->m_Histogram.rend( );
86 this->GetOutput( )->SetPixel( n.Vertex, v );
92 // -------------------------------------------------------------------------
94 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
97 typename THistogram::iterator prevIt = this->m_Histogram.begin( );
98 typename THistogram::iterator currIt = prevIt; currIt++;
99 typename THistogram::iterator nextIt = currIt; nextIt++;
100 double prev_d1 = double( 0 );
101 for( ; nextIt != this->m_Histogram.end( ); ++prevIt, ++currIt, ++nextIt )
103 double d1 = double( nextIt->second ) - double( prevIt->second );
104 d1 /= double( nextIt->first ) - double( prevIt->first );
107 << currIt->first << " "
108 << currIt->second << " "
110 << ( d1 - prev_d1 ) << std::endl;
118 double prev = double( 0 );
119 while( hIt != this->m_Histogram.end( ) )
121 double curr = double( hIt->second );
122 double deri = curr - prev;
124 if( hIt != this->m_Histogram.begin( ) )
125 std::cout << hIt->first << " " << curr << " " << deri << std::endl;
132 this->Superclass::_AfterLoop( );
135 #endif // __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__