#ifndef __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__ #define __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__ #include // ------------------------------------------------------------------------- template< class I > void fpa::Image::RegionGrowWithMultipleThresholds< I >:: AddThreshold( const TPixel& v ) { this->m_Thresholds.insert( v ); this->Modified( ); } // ------------------------------------------------------------------------- template< class I > void fpa::Image::RegionGrowWithMultipleThresholds< I >:: AddThresholds( const TPixel& t0, const TPixel& t1, const unsigned int& s ) { double o = ( double( t1 ) - double( t0 ) ) / ( double( s ) - double( 1 ) ); for( unsigned int i = 0; i < s; i++ ) this->AddThreshold( TPixel( ( double( i ) * o ) + double( t0 ) ) ); } // ------------------------------------------------------------------------- template< class I > fpa::Image::RegionGrowWithMultipleThresholds< I >:: RegionGrowWithMultipleThresholds( ) : Superclass( ), m_DerivativeThreshold( double( 3 ) ) { /* TODO typedef fpa::Image::Functors::RegionGrowThresholdFunction< I > TFunction; typename TFunction::Pointer function = TFunction::New( ); this->SetMembershipFunction( function ); */ } // ------------------------------------------------------------------------- template< class I > fpa::Image::RegionGrowWithMultipleThresholds< I >:: ~RegionGrowWithMultipleThresholds( ) { } // ------------------------------------------------------------------------- template< class I > bool fpa::Image::RegionGrowWithMultipleThresholds< I >:: _UpdateResult( _TNode& n ) { bool ret = this->Superclass::_UpdateResult( n ); std::cout << "Image:UpdateResult " << ret << std::endl; /* TODO if( ret ) { TPixel v = TPixel( this->_Cost( n.Vertex, n.Vertex ) ); typename THistogram::reverse_iterator hIt = this->m_Histogram.rbegin( ); while( hIt != this->m_Histogram.rend( ) ) { if( v <= hIt->first ) { hIt->second += 1; hIt++; } else hIt = this->m_Histogram.rend( ); } // elihw this->GetOutput( )->SetPixel( n.Vertex, v ); } // fi */ return( ret ); } // ------------------------------------------------------------------------- template< class I > void fpa::Image::RegionGrowWithMultipleThresholds< I >:: _BeforeLoop( ) { const I* img = this->GetInput( ); this->ClearMembershipFunctions( ); typename TThresholds::const_iterator tIt = this->m_Thresholds.begin( ); typename TThresholds::const_iterator prev_tIt = tIt; for( ++tIt; tIt != this->m_Thresholds.end( ); ++tIt, ++prev_tIt ) { typename TFunction::Pointer function = TFunction::New( ); function->SetInputImage( img ); function->SetLowerThreshold( *prev_tIt ); function->SetUpperThreshold( *tIt ); this->AddMembershipFunction( function ); std::cout << *prev_tIt << " " << *tIt << std::endl; } // rof this->Superclass::_BeforeLoop( ); } // ------------------------------------------------------------------------- template< class I > void fpa::Image::RegionGrowWithMultipleThresholds< I >:: _AfterLoop( ) { /* typename THistogram::iterator prevIt = this->m_Histogram.begin( ); typename THistogram::iterator currIt = prevIt; currIt++; typename THistogram::iterator nextIt = currIt; nextIt++; double prev_d1 = double( 0 ); for( ; nextIt != this->m_Histogram.end( ); ++prevIt, ++currIt, ++nextIt ) { double d1 = double( nextIt->second ) - double( prevIt->second ); d1 /= double( nextIt->first ) - double( prevIt->first ); std::cout << currIt->first << " " << currIt->second << " " << d1 << " " << ( d1 - prev_d1 ) << std::endl; prev_d1 = d1; } // rof */ /* double prev = double( 0 ); while( hIt != this->m_Histogram.end( ) ) { double curr = double( hIt->second ); double deri = curr - prev; if( hIt != this->m_Histogram.begin( ) ) std::cout << hIt->first << " " << curr << " " << deri << std::endl; prev = curr; hIt++; } // rof */ this->Superclass::_AfterLoop( ); } #endif // __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__ // eof - $RCSfile$