]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/Image/RegionGrowWithMultipleThresholds.hxx
Some visualizaton added
[FrontAlgorithms.git] / lib / fpa / Image / RegionGrowWithMultipleThresholds.hxx
index 387a833bcab9bda89bba8d05e36eb9ec76fdeeae..e9ea4566b6ef59791d567f8d86b5a14f659e51aa 100644 (file)
@@ -2,6 +2,7 @@
 #define __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__
 
 #include <limits>
+#include <itkBinaryThresholdImageFilter.h>
 #include <itkConstNeighborhoodIterator.h>
 
 // -------------------------------------------------------------------------
@@ -27,6 +28,8 @@ template< class I >
 fpa::Image::RegionGrowWithMultipleThresholds< I >::
 RegionGrowWithMultipleThresholds( )
   : Superclass( ),
+    m_InsideValue( TPixel( 1 ) ),
+    m_OutsideValue( TPixel( 0 ) ),
     m_DifferenceThreshold( double( 3 ) ),
     m_TotalCount( 0 ),
     m_LastDiff( double( 0 ) ),
@@ -108,6 +111,26 @@ template< class I >
 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
 _AfterMainLoop( )
 {
+  typedef itk::BinaryThresholdImageFilter< I, I > _TBinFilter;
+
+  // Binarize, inplace, the grown region
+  if( this->m_Histogram.size( ) > 1 )
+  {
+    typename _TBinFilter::Pointer bin = _TBinFilter::New( );
+    bin->SetInput( this->GetOutput( ) );
+    bin->SetInsideValue( this->m_InsideValue );
+    bin->SetOutsideValue( this->m_OutsideValue );
+    bin->InPlaceOn( );
+    if( this->m_StopForced )
+      bin->SetUpperThreshold( this->m_StopThreshold );
+    else
+      bin->SetUpperThreshold( this->m_Histogram.rbegin( )->first );
+    bin->GraftOutput( this->GetOutput( ) );
+    bin->Update( );
+    this->GraftOutput( bin->GetOutput( ) );
+
+  } // fi
+
   this->Superclass::_AfterMainLoop( );
 }