1 #ifndef __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__
2 #define __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__
6 // -------------------------------------------------------------------------
8 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
9 AddThreshold( const TPixel& v )
11 this->m_Thresholds.insert( v );
15 // -------------------------------------------------------------------------
17 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
18 AddThresholds( const TPixel& t0, const TPixel& t1, const unsigned int& s )
20 double o = ( double( t1 ) - double( t0 ) ) / ( double( s ) - double( 1 ) );
21 for( unsigned int i = 0; i < s; i++ )
22 this->AddThreshold( TPixel( ( double( i ) * o ) + double( t0 ) ) );
25 // -------------------------------------------------------------------------
27 fpa::Image::RegionGrowWithMultipleThresholds< I >::
28 RegionGrowWithMultipleThresholds( )
30 m_DerivativeThreshold( double( 3 ) )
34 fpa::Image::Functors::RegionGrowThresholdFunction< I >
36 typename TFunction::Pointer function = TFunction::New( );
37 this->SetMembershipFunction( function );
41 // -------------------------------------------------------------------------
43 fpa::Image::RegionGrowWithMultipleThresholds< I >::
44 ~RegionGrowWithMultipleThresholds( )
48 // -------------------------------------------------------------------------
50 bool fpa::Image::RegionGrowWithMultipleThresholds< I >::
51 _UpdateResult( _TNode& n )
53 bool ret = this->Superclass::_UpdateResult( n );
54 std::cout << "Image:UpdateResult " << ret << std::endl;
60 TPixel v = TPixel( this->_Cost( n.Vertex, n.Vertex ) );
62 typename THistogram::reverse_iterator hIt = this->m_Histogram.rbegin( );
63 while( hIt != this->m_Histogram.rend( ) )
71 hIt = this->m_Histogram.rend( );
74 this->GetOutput( )->SetPixel( n.Vertex, v );
81 // -------------------------------------------------------------------------
83 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
86 const I* img = this->GetInput( );
88 this->ClearMembershipFunctions( );
89 typename TThresholds::const_iterator tIt = this->m_Thresholds.begin( );
90 typename TThresholds::const_iterator prev_tIt = tIt;
91 for( ++tIt; tIt != this->m_Thresholds.end( ); ++tIt, ++prev_tIt )
93 typename TFunction::Pointer function = TFunction::New( );
94 function->SetInputImage( img );
95 function->SetLowerThreshold( *prev_tIt );
96 function->SetUpperThreshold( *tIt );
97 this->AddMembershipFunction( function );
98 std::cout << *prev_tIt << " " << *tIt << std::endl;
102 this->Superclass::_BeforeLoop( );
105 // -------------------------------------------------------------------------
107 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
111 typename THistogram::iterator prevIt = this->m_Histogram.begin( );
112 typename THistogram::iterator currIt = prevIt; currIt++;
113 typename THistogram::iterator nextIt = currIt; nextIt++;
114 double prev_d1 = double( 0 );
115 for( ; nextIt != this->m_Histogram.end( ); ++prevIt, ++currIt, ++nextIt )
117 double d1 = double( nextIt->second ) - double( prevIt->second );
118 d1 /= double( nextIt->first ) - double( prevIt->first );
121 << currIt->first << " "
122 << currIt->second << " "
124 << ( d1 - prev_d1 ) << std::endl;
132 double prev = double( 0 );
133 while( hIt != this->m_Histogram.end( ) )
135 double curr = double( hIt->second );
136 double deri = curr - prev;
138 if( hIt != this->m_Histogram.begin( ) )
139 std::cout << hIt->first << " " << curr << " " << deri << std::endl;
146 this->Superclass::_AfterLoop( );
149 #endif // __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__