- /* 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 );
+ // Clear all states
+ this->ClearMembershipFunctions( );
+ this->m_Histogram.clear( );
+ this->m_TotalCount = img->GetLargestPossibleRegion( ).GetNumberOfPixels( );
+ this->m_LastDiff = double( -1 );
+ this->m_StopForced = false;
+
+ // Initialize thresholding functors
+ typename TThresholds::const_iterator tIt = this->m_Thresholds.begin( );
+ TPixel min_thr = std::numeric_limits< TPixel >::min( );
+ for( ; tIt != this->m_Thresholds.end( ); ++tIt )
+ {
+ typename TFunction::Pointer function = TFunction::New( );
+ function->SetInputImage( img );
+ function->SetLowerThreshold( min_thr );
+ function->SetUpperThreshold( *tIt );
+ this->AddMembershipFunction( function );
+
+ } // rof
+
+ // Correct seeds
+ typename I::SizeType radius;
+ radius.Fill( 3 );
+ itk::ConstNeighborhoodIterator< I > it(
+ radius, img, img->GetRequestedRegion( )
+ );
+ for( unsigned int s = 0; s < this->m_Seeds.size( ); ++s )
+ {
+ _TNode seed = this->m_Seeds[ s ];
+ it.SetLocation( seed.Vertex );
+
+ typename I::SizeType size = it.GetSize( );
+ unsigned int nN = 1;
+ for( unsigned int d = 0; d < I::ImageDimension; ++d )
+ nN *= size[ d ];
+ TPixel min_value = img->GetPixel( seed.Vertex );
+ for( unsigned int i = 0; i < nN; ++i )
+ {
+ if( it.GetPixel( i ) < min_value )
+ {
+ seed.Vertex = it.GetIndex( i );
+ seed.Parent = seed.Vertex;
+ min_value = it.GetPixel( i );
+
+ } // fi
+
+ } // rof
+ this->m_Seeds[ s ] = seed;
+
+ } // rof
+
+ // Continue all initializations
+ this->Superclass::_BeforeMainLoop( );