--- /dev/null
+#include <climits>
+#include <cstdlib>
+#include <fstream>
+#include <iostream>
+#include <string>
+
+#include <itkImage.h>
+#include <itkImageFileReader.h>
+#include <itkImageFileWriter.h>
+
+#include <fpa/Image/RegionGrow.h>
+#include <fpa/Image/Functors/RegionGrow/BinaryThreshold.h>
+
+// -------------------------------------------------------------------------
+static const unsigned int Dim = 3;
+typedef short TPixel;
+typedef itk::Image< TPixel, Dim > TImage;
+
+// -------------------------------------------------------------------------
+std::string GetFullPath( const std::string& filename )
+{
+ /* On windows:
+ #include <windows.h>
+ TCHAR full_path[MAX_PATH];
+ GetFullPathName(_T("foo.dat"), MAX_PATH, full_path, NULL);
+ */
+
+ char* buffer = realpath( filename.c_str( ), NULL );
+ std::string path = buffer;
+ std::free( buffer );
+ return( path );
+}
+
+// -------------------------------------------------------------------------
+std::string GetFullPathToDirectory( const std::string& filename )
+{
+ std::string path = GetFullPath( filename );
+ std::size_t found = path.find_last_of( "/\\" );
+ return( path.substr( 0, found + 1 ) );
+}
+
+// -------------------------------------------------------------------------
+int main( int argc, char* argv[] )
+{
+ // Command configuration
+ if( argc < 5 )
+ {
+ std::cerr
+ << "Usage: " << argv[ 0 ] << " input_image output_image lower upper"
+ << std::endl;
+ return( 1 );
+
+ } // fi
+ std::string input_image_filename = GetFullPath( argv[ 1 ] );
+ std::string output_image_filename = argv[ 2 ];
+ std::string output_auxiliary_image_filename = output_image_filename + "_aux.mhd";
+ TPixel lower = std::atoi( argv[ 3 ] );
+ TPixel upper = std::atoi( argv[ 4 ] );
+
+ // Try to guess initial seed
+ std::string seed_filename = GetFullPathToDirectory( argv[ 1 ] ) + "seed.txt";
+ std::ifstream seed_str( seed_filename.c_str( ) );
+ if( !seed_str )
+ {
+ std::cerr
+ << "No \"seed.txt\" file in the same input image directory."
+ << std::endl;
+ return( 1 );
+
+ } // fi
+ TImage::IndexType seed;
+ seed_str >> seed[ 0 ] >> seed[ 1 ] >> seed[ 2 ];
+ seed_str.close( );
+
+ // Read image
+ typedef itk::ImageFileReader< TImage > TReader;
+ TReader::Pointer reader = TReader::New( );
+ reader->SetFileName( input_image_filename );
+
+ // Growing predicate
+ typedef fpa::Image::Functors::RegionGrow::BinaryThreshold< TImage, TImage::PixelType > TPredicate;
+ TPredicate::Pointer predicate = TPredicate::New( );
+ predicate->SetLower( lower );
+ predicate->SetUpper( upper );
+
+ // RegionGrow algorithm
+ typedef fpa::Image::RegionGrow< TImage, TImage > TFilter;
+ TFilter::Pointer filter = TFilter::New( );
+ filter->SetInput( reader->GetOutput( ) );
+ filter->AddSeed( seed, 1 );
+ filter->SetInsideValue( 1 );
+ filter->SetOutsideValue( 0 );
+ filter->SetGrowFunction( predicate );
+
+ // Write results
+ typedef itk::ImageFileWriter< TImage > TWriter;
+ TWriter::Pointer writer = TWriter::New( );
+ writer->SetInput( filter->GetOutput( ) );
+ writer->SetFileName( output_image_filename );
+
+ // Execute pipeline
+ try
+ {
+ writer->Update( );
+ }
+ catch( std::exception& err )
+ {
+ std::cerr << "Error caught: " << err.what( ) << std::endl;
+ return( 1 );
+
+ } // yrt
+
+ return( 0 );
+}
+
+// eof - $RCSfile$
} // fi
std::string input_image_filename = GetFullPath( argv[ 1 ] );
std::string output_image_filename = argv[ 2 ];
+ std::string output_auxiliary_image_filename = output_image_filename + "_aux.mhd";
// Try to guess initial seed
std::string seed_filename = GetFullPathToDirectory( argv[ 1 ] ) + "seed.txt";
} // fi
TImage::IndexType seed;
seed_str >> seed[ 0 ] >> seed[ 1 ] >> seed[ 2 ];
+ seed_str.close( );
// Read image
typedef itk::ImageFileReader< TImage > TReader;
TFilter::Pointer filter = TFilter::New( );
filter->SetInput( reader->GetOutput( ) );
filter->SetSeed( seed );
- filter->SetThresholdRange( -1024, 0 );
+ filter->SetThresholdRange( -200, 100, 1 );
filter->SetInsideValue( 1 );
filter->SetOutsideValue( 0 );
return( 1 );
} // yrt
+
+ // Write auxiliary image
+ typedef itk::ImageFileWriter< TFilter::TAuxImage > TAuxWriter;
+ TAuxWriter::Pointer aux_writer = TAuxWriter::New( );
+ aux_writer->SetInput( filter->GetAuxiliaryImage( ) );
+ aux_writer->SetFileName( output_auxiliary_image_filename );
+
+ // Execute pipeline
+ try
+ {
+ aux_writer->Update( );
+ }
+ catch( std::exception& err )
+ {
+ std::cerr << "Error caught: " << err.what( ) << std::endl;
+ return( 1 );
+
+ } // yrt
+
+ // Write result signal
+ std::string output_signal_filename = output_image_filename + ".csv";
+ std::ofstream output_signal_str( output_signal_filename.c_str( ) );
+ TFilter::TCurve curve = filter->GetCurve( );
+ unsigned long max_count = 0;
+ for( TFilter::TCurve::value_type d : curve )
+ {
+ output_signal_str << d.first << " " << d.second << std::endl;
+ if( max_count < d.second )
+ max_count = d.second;
+
+ } // rof
+ output_signal_str.close( );
+
+ // Write gnuplot script
+ std::string output_gnuplot_filename = output_image_filename + ".gnuplot";
+ std::ofstream output_gnuplot_str( output_gnuplot_filename.c_str( ) );
+ unsigned int thr_pos = filter->GetOptimumThreshold( );
+ int thr = curve[ thr_pos ].first;
+ output_gnuplot_str
+ << "set term png" << std::endl
+ << "set output \"" << output_image_filename << ".png\"" << std::endl
+ << "set arrow 1 from " << thr
+ << ",0 to " << thr << "," << max_count
+ << std::endl
+ << "show arrow 1" << std::endl
+ << "plot \"" << output_signal_filename
+ << "\" using 1:2 with linespoints title \"Evolution ("
+ << thr << "," << thr_pos << ") " << "\""
+ << std::endl;
+ output_gnuplot_str.close( );
+
return( 0 );
}
IF(BUILD_EXAMPLES)
SET(
_examples
+ CreateMoriInputImage
BronchiiInitialSegmentationWithMori
+ BronchiiInitialSegmentationWithBinaryThresholdRegionGrow
)
INCLUDE_DIRECTORIES(
${PROJECT_SOURCE_DIR}/libs
--- /dev/null
+#include <queue>
+#include <itkImage.h>
+#include <itkImageFileReader.h>
+#include <itkSignedMaurerDistanceMapImageFilter.h>
+#include <itkImageFileWriter.h>
+
+// -------------------------------------------------------------------------
+static const unsigned int Dim = 2;
+typedef short TInputPixel;
+typedef float TOutputPixel;
+typedef itk::Image< TInputPixel, Dim > TInputImage;
+typedef itk::Image< TOutputPixel, Dim > TOutputImage;
+
+// -------------------------------------------------------------------------
+int main( int argc, char* argv[] )
+{
+ // Command configuration
+ if( argc < 3 )
+ {
+ std::cerr
+ << "Usage: " << argv[ 0 ] << " input_image output_image"
+ << std::endl;
+ return( 1 );
+
+ } // fi
+ std::string input_image_filename = argv[ 1 ];
+ std::string output_image_filename = argv[ 2 ];
+
+ // Read image
+ typedef itk::ImageFileReader< TInputImage > TReader;
+ TReader::Pointer reader = TReader::New( );
+ reader->SetFileName( input_image_filename );
+
+ // Distance map
+ typedef itk::SignedMaurerDistanceMapImageFilter< TInputImage, TOutputImage > TFilter;
+ TFilter::Pointer filter = TFilter::New( );
+ filter->SetInput( reader->GetOutput( ) );
+ filter->SetBackgroundValue( 0 );
+ filter->InsideIsPositiveOn( );
+ filter->SquaredDistanceOff( );
+ filter->UseImageSpacingOn( );
+
+ // Write image
+ typedef itk::ImageFileWriter< TOutputImage > TWriter;
+ TWriter::Pointer writer = TWriter::New( );
+ writer->SetInput( filter->GetOutput( ) );
+ writer->SetFileName( output_image_filename );
+
+ // Execute pipeline
+ try
+ {
+ writer->Update( );
+ }
+ catch( std::exception& err )
+ {
+ std::cerr << "Error caught: " << err.what( ) << std::endl;
+ return( 1 );
+
+ } // yrt
+
+ return( 0 );
+}
+
+// eof - $RCSfile$
virtual bool _ValidLoop( ) const;
virtual void _UpdateCollisions( const TVertex& a, const TVertex& b );
- virtual _TOutput _GetInputValue( const _TQueueNode& v, const _TQueueNode& p );
+ virtual _TOutput _GetInputValue( const TVertex& v, const TVertex& p );
+ virtual bool _UpdateResult( _TQueueNode& n );
virtual void _InitMarks( ) = 0;
virtual void _InitResults( const TOutput& init_value ) = 0;
virtual bool _IsMarked( const _TVertex& v ) const = 0;
virtual void _Mark( const _TQueueNode& n ) = 0;
virtual TFrontId _GetMark( const _TVertex& v ) const = 0;
- virtual void _UpdateResult( const _TQueueNode& n ) = 0;
virtual TOutput _GetResult( const _TVertex& v ) const = 0;
virtual unsigned int _GetNumberOfDimensions( ) const = 0;
if( this->_IsMarked( node.Vertex ) )
continue;
this->_Mark( node );
- this->_UpdateResult( node );
this->InvokeEvent( TMarkEvent( node.Vertex, node.FrontId ) );
+ if( !( this->_UpdateResult( node ) ) )
+ continue;
// Add neighbors to queue
TNeighborhood neighs = this->m_NeighborhoodFunction->Evaluate( node.Vertex );
// -------------------------------------------------------------------------
template < class _TFilter, class _TVertex, class _TOutput >
_TOutput fpa::Base::Algorithm< _TFilter, _TVertex, _TOutput >::
-_GetInputValue( const _TQueueNode& v, const _TQueueNode& p )
+_GetInputValue( const TVertex& v, const TVertex& p )
{
_TOutput res = this->m_InitResult;
if( this->m_VertexFunction.IsNotNull( ) )
- res = this->m_VertexFunction->Evaluate( v.Vertex, p.Vertex );
+ res = this->m_VertexFunction->Evaluate( v, p );
if( this->m_ConversionFunction.IsNotNull( ) )
res = this->m_ConversionFunction->Evaluate( res );
return( res );
}
+// -------------------------------------------------------------------------
+template < class _TFilter, class _TVertex, class _TOutput >
+bool fpa::Base::Algorithm< _TFilter, _TVertex, _TOutput >::
+_UpdateResult( _TQueueNode& n )
+{
+ return( true );
+}
+
#endif // __fpa__Base__Algorithm__hxx__
// eof - $RCSfile$
virtual bool _UpdateValue(
_TQueueNode& v, const _TQueueNode& p
) override;
- virtual TOutput _GetInputValue( const _TQueueNode& v, const _TQueueNode& p ) override
- {
- TOutput res = this->m_InitResult;
- if( this->m_GrowFunction.IsNotNull( ) )
- res = this->m_GrowFunction->Evaluate( v.Vertex, p.Vertex );
- return( res );
- }
+ virtual TOutput _GetInputValue(
+ const TVertex& v, const TVertex& p
+ ) override;
+ virtual bool _UpdateResult( _TQueueNode& n ) override;
private:
TGrowFunction* fpa::Base::RegionGrow< _TSuperclass >::
GetGrowFunction( )
{
- // TODO: return( dynamic_cast< TGrowFunction* >( this->GetVertexFunction( ) ) );
return( this->m_GrowFunction );
}
TGrowFunction* fpa::Base::RegionGrow< _TSuperclass >::
GetGrowFunction( ) const
{
- /* TODO
- return(
- dynamic_cast< const TGrowFunction* >( this->GetVertexFunction( ) )
- );
- */
return( this->m_GrowFunction );
}
bool fpa::Base::RegionGrow< _TSuperclass >::
_UpdateValue( _TQueueNode& v, const _TQueueNode& p )
{
- v.Result = this->_GetInputValue( v, p );
- return( v.Result == this->GetInsideValue( ) );
+ return( true );
+}
+
+// -------------------------------------------------------------------------
+template< class _TSuperclass >
+typename fpa::Base::RegionGrow< _TSuperclass >::
+TOutput fpa::Base::RegionGrow< _TSuperclass >::
+_GetInputValue( const TVertex& v, const TVertex& p )
+{
+ TOutput res = this->m_InitResult;
+ if( this->m_GrowFunction.IsNotNull( ) )
+ res = this->m_GrowFunction->Evaluate( v, p );
+ return( res );
+}
+
+// -------------------------------------------------------------------------
+template< class _TSuperclass >
+bool fpa::Base::RegionGrow< _TSuperclass >::
+_UpdateResult( _TQueueNode& n )
+{
+ n.Result = this->_GetInputValue( n.Vertex, n.Parent );
+ this->Superclass::_UpdateResult( n );
+ return( n.Result == this->GetInsideValue( ) );
}
#endif // __fpa__Base__RegionGrow__hxx__
virtual bool _IsMarked( const TVertex& v ) const override;
virtual void _Mark( const _TQueueNode& n ) override;
virtual TFrontId _GetMark( const TVertex& v ) const override;
- virtual void _UpdateResult( const _TQueueNode& n ) override;
+ virtual bool _UpdateResult( _TQueueNode& n ) override;
virtual TOutput _GetResult( const TVertex& v ) const override;
virtual unsigned int _GetNumberOfDimensions( ) const override;
// -------------------------------------------------------------------------
template< class _TInputImage, class _TOutputImage >
-void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
-_UpdateResult( const _TQueueNode& n )
+bool fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
+_UpdateResult( _TQueueNode& n )
{
+ bool res = this->Superclass::_UpdateResult( n );
+ std::cout << n.Vertex << " " << n.Result << std::endl;
this->GetOutput( )->SetPixel( n.Vertex, n.Result );
+ return( res );
}
// -------------------------------------------------------------------------
if( im != NULL )
{
TPixel v = im->GetPixel( b );
+
+ std::cout << a << " " << v << " " << this->m_Lower << " " << this->m_Upper << std::endl;
+
return(
( this->m_Lower < v && v < this->m_Upper )?
this->m_InsideValue:
: public itk::ImageToImageFilter< _TInputImage, _TOutputImage >
{
public:
- typedef MoriFilter Self;
+ typedef MoriFilter Self;
typedef itk::ImageToImageFilter< _TInputImage, _TOutputImage > Superclass;
typedef itk::SmartPointer< Self > Pointer;
typedef itk::SmartPointer< const Self > ConstPointer;
typedef itk::Image< _TAuxPixel, _TInputImage::ImageDimension > TAuxImage;
- typedef fpa::Image::MoriFilterHelper< _TInputImage, TAuxImage > THelper;
+ typedef fpa::Image::MoriFilterHelper< _TInputImage, TAuxImage > THelper;
typedef itk::BinaryThresholdImageFilter< TAuxImage, _TOutputImage > TThreshold;
typedef typename _TInputImage::IndexType TIndex;
typedef typename _TInputImage::PixelType TInputPixel;
typedef typename _TOutputImage::PixelType TOutputPixel;
+ typedef typename THelper::TCurve TCurve;
public:
itkNewMacro( Self );
TInputPixel GetStep( ) const;
TOutputPixel GetInsideValue( ) const;
TOutputPixel GetOutsideValue( ) const;
+ TOutputPixel GetOptimumThreshold( ) const;
+ TCurve GetCurve( ) const;
void SetLower( const TInputPixel& v );
void SetUpper( const TInputPixel& v );
void SetInsideValue( const TOutputPixel& v );
void SetOutsideValue( const TOutputPixel& v );
-
- /* TODO
- itkGetConstMacro( Lower, TPixel );
- itkGetConstMacro( Upper, TPixel );
- itkGetConstMacro( Step, TPixel );
- itkGetConstMacro( Sensitivity, double );
- itkSetMacro( Lower, TPixel );
- itkSetMacro( Upper, TPixel );
- itkSetMacro( Step, TPixel );
- itkSetMacro( Sensitivity, double );
- */
-
protected:
MoriFilter( );
virtual ~MoriFilter( );
return( this->m_Threshold->GetInsideValue( ) );
}
+// -------------------------------------------------------------------------
+template< class _TInputImage, class _TOutputImage, class _TAuxPixel >
+typename
+fpa::Image::MoriFilter< _TInputImage, _TOutputImage, _TAuxPixel >::
+TOutputPixel
+fpa::Image::MoriFilter< _TInputImage, _TOutputImage, _TAuxPixel >::
+GetOptimumThreshold( ) const
+{
+ return( this->m_Helper->GetOptimumThreshold( ) );
+}
+
+// -------------------------------------------------------------------------
+template< class _TInputImage, class _TOutputImage, class _TAuxPixel >
+typename
+fpa::Image::MoriFilter< _TInputImage, _TOutputImage, _TAuxPixel >::
+TCurve fpa::Image::MoriFilter< _TInputImage, _TOutputImage, _TAuxPixel >::
+GetCurve( ) const
+{
+ return( this->m_Helper->GetCurve( ) );
+}
+
// -------------------------------------------------------------------------
template< class _TInputImage, class _TOutputImage, class _TAuxPixel >
void fpa::Image::MoriFilter< _TInputImage, _TOutputImage, _TAuxPixel >::
void fpa::Image::MoriFilter< _TInputImage, _TOutputImage, _TAuxPixel >::
GenerateData( )
{
- this->m_Helper->ClearSeeds( );
- this->m_Helper->AddSeed( this->m_Seed, this->GetOutsideValue( ) );
+ this->m_Helper->SetSeed( this->m_Seed );
this->m_Helper->SetInput( this->GetInput( ) );
this->m_Helper->Update( );
#ifndef __fpa__Image__MoriFilterHelper__h__
#define __fpa__Image__MoriFilterHelper__h__
+/* TODO
+ #include <fpa/Image/RegionGrow.h>
+ #include <fpa/Image/Functors/RegionGrow/BinaryThreshold.h>
+*/
#include <utility>
#include <vector>
-#include <fpa/Image/RegionGrow.h>
-#include <fpa/Image/Functors/RegionGrow/BinaryThreshold.h>
+#include <itkImageToImageFilter.h>
namespace fpa
{
*/
template< class _TInputImage, class _TOutputImage >
class MoriFilterHelper
- : public fpa::Image::RegionGrow< _TInputImage, _TOutputImage >
+ : public itk::ImageToImageFilter< _TInputImage, _TOutputImage >
{
public:
- typedef MoriFilterHelper Self;
- typedef fpa::Image::RegionGrow< _TInputImage, _TOutputImage > Superclass;
- typedef itk::SmartPointer< Self > Pointer;
- typedef itk::SmartPointer< const Self > ConstPointer;
-
- typedef typename Superclass::TOutput TOutput;
- typedef typename Superclass::TVertex TVertex;
- typedef typename Superclass::TGrowFunction TGrowFunction;
- typedef typename _TInputImage::PixelType TPixel;
- typedef fpa::Image::Functors::RegionGrow::BinaryThreshold< _TInputImage, TOutput > TBinThresholdFunction;
-
- protected:
- typedef typename Superclass::_TQueueNode _TQueueNode;
- typedef typename Superclass::_TQueue _TQueue;
-
- typedef std::pair< TPixel, unsigned long > TCurveData;
- typedef std::vector< TCurveData > TCurve;
+ typedef MoriFilterHelper Self;
+ typedef itk::ImageToImageFilter< _TInputImage, _TOutputImage > Superclass;
+ typedef itk::SmartPointer< Self > Pointer;
+ typedef itk::SmartPointer< const Self > ConstPointer;
+
+ typedef _TInputImage TInputImage;
+ typedef _TOutputImage TOutputImage;
+ typedef typename TInputImage::IndexType TIndex;
+ typedef typename TInputImage::PixelType TInputPixel;
+ typedef typename TOutputImage::PixelType TOutputPixel;
+
+ typedef std::pair< TInputPixel, unsigned long > TCurveData;
+ typedef std::vector< TCurveData > TCurve;
+
+ /* TODO
+ typedef typename Superclass::TOutput TOutput;
+ typedef typename Superclass::TVertex TVertex;
+ typedef typename Superclass::TGrowFunction TGrowFunction;
+ typedef typename _TInputImage::PixelType TPixel;
+ typedef fpa::Image::Functors::RegionGrow::BinaryThreshold< _TInputImage, TOutput > TBinThresholdFunction;
+ protected:
+ typedef typename Superclass::_TQueueNode _TQueueNode;
+ typedef typename Superclass::_TQueue _TQueue;
+ */
public:
itkNewMacro( Self );
- itkTypeMacro( fpa::Image::MoriFilterHelper, fpa::Image::RegionGrow );
+ itkTypeMacro( fpa::Image::MoriFilterHelper, itk::ImageToImageFilter );
- itkGetConstMacro( Lower, TPixel );
- itkGetConstMacro( Upper, TPixel );
- itkGetConstMacro( Step, TPixel );
+ itkGetConstMacro( Seed, TIndex );
+ itkGetConstMacro( Lower, TInputPixel );
+ itkGetConstMacro( Upper, TInputPixel );
+ itkGetConstMacro( Step, TInputPixel );
itkGetConstMacro( OptimumThreshold, typename _TOutputImage::PixelType );
+ itkGetConstMacro( Curve, TCurve );
- itkSetMacro( Lower, TPixel );
- itkSetMacro( Upper, TPixel );
- itkSetMacro( Step, TPixel );
-
+ itkSetMacro( Seed, TIndex );
+ itkSetMacro( Lower, TInputPixel );
+ itkSetMacro( Upper, TInputPixel );
+ itkSetMacro( Step, TInputPixel );
protected:
- MoriFilterHelper( );
- virtual ~MoriFilterHelper( );
-
- virtual bool _ContinueGenerateData( ) override;
- virtual void _BeforeGenerateData( ) override;
- virtual void _AfterGenerateData( ) override;
- virtual void _BeforeLoop( ) override;
- virtual void _AfterLoop( ) override;
- virtual bool _UpdateValue( _TQueueNode& v, const _TQueueNode& p ) override;
- virtual void _UpdateResult( const _TQueueNode& n ) override;
+ MoriFilterHelper( )
+ : Superclass( )
+ {
+ }
+ virtual ~MoriFilterHelper( )
+ {
+ }
+
+ /* TODO
+ virtual bool _ContinueGenerateData( ) override;
+ virtual void _BeforeGenerateData( ) override;
+ virtual void _AfterGenerateData( ) override;
+ virtual void _BeforeLoop( ) override;
+ virtual void _AfterLoop( ) override;
+ virtual bool _UpdateValue( _TQueueNode& v, const _TQueueNode& p ) override;
+ virtual bool _UpdateResult( _TQueueNode& n ) override;
+ */
private:
// Purposely not defined
Self& operator=( const Self& other );
protected:
- TPixel m_Lower;
- TPixel m_Upper;
- TPixel m_Step;
+ TIndex m_Seed;
+ TInputPixel m_Lower;
+ TInputPixel m_Upper;
+ TInputPixel m_Step;
typename _TOutputImage::PixelType m_OptimumThreshold;
- _TQueue m_NextQueue;
unsigned long m_ActualCount;
TCurve m_Curve;
};
} // ecapseman
-#ifndef ITK_MANUAL_INSTANTIATION
-# include <fpa/Image/MoriFilterHelper.hxx>
-#endif // ITK_MANUAL_INSTANTIATION
+/* TODO
+ #ifndef ITK_MANUAL_INSTANTIATION
+ # include <fpa/Image/MoriFilterHelper.hxx>
+ #endif // ITK_MANUAL_INSTANTIATION
+*/
#endif // __fpa__Image__MoriFilterHelper__h__
{
TBinThresholdFunction* functor =
dynamic_cast< TBinThresholdFunction* >( this->GetGrowFunction( ) );
- TPixel u = functor->GetUpper( );
// Update flooding data
+ TPixel u = functor->GetUpper( );
this->m_Curve.push_back( TCurveData( u, this->m_ActualCount ) );
- std::cout << u << " " << this->m_ActualCount << std::endl;
// Update thresholds
if( u < this->m_Upper )
if( u > this->m_Upper )
u = this->m_Upper;
functor->SetUpper( u );
- this->m_Queue = this->m_NextQueue;
+
+ while( this->m_Queue.size( ) > 0 )
+ this->m_Queue.pop( );
+ // TODO: std::cout << "-----> " << this->m_NextQueue.size( ) << " " << u << std::endl;
while( this->m_NextQueue.size( ) > 0 )
+ {
+ this->m_Queue.push( this->m_NextQueue.front( ) );
+ // TODO: std::cout << "\t" << this->m_NextQueue.front( ).Vertex << std::endl;
this->m_NextQueue.pop( );
+
+ } // elihw
+
+ /* TODO: ensure pixels belong to new threshold?
+ while( this->m_Queue.size( ) > 0 )
+ this->m_Queue.pop( );
+ while( this->m_NextQueue.size( ) > 0 )
+ {
+ _TQueueNode n = this->m_NextQueue.front( );
+ this->m_NextQueue.pop( );
+
+ if( ??? )
+ this->m_Queue.push( n );
+ }
+ */
return( true );
}
else
bool fpa::Image::MoriFilterHelper< _TInputImage, _TOutputImage >::
_UpdateValue( _TQueueNode& v, const _TQueueNode& p )
{
- typedef typename _TOutputImage::PixelType _TOut;
-
- bool ret = this->Superclass::_UpdateValue( v, p );
- v.Result = _TOut( this->m_Curve.size( ) + 1 );
- if( !ret )
- this->m_NextQueue.push( v );
- return( ret );
+ return( this->Superclass::_UpdateValue( v, p ) );
+ /* TODO
+ typedef typename _TOutputImage::PixelType _TOut;
+
+ bool ret = this->Superclass::_UpdateValue( v, p );
+ v.Result = _TOut( this->m_Curve.size( ) + 1 );
+ if( !ret )
+ this->m_NextQueue.push( v );
+ return( ret );
+ */
}
// -------------------------------------------------------------------------
template< class _TInputImage, class _TOutputImage >
-void fpa::Image::MoriFilterHelper< _TInputImage, _TOutputImage >::
-_UpdateResult( const _TQueueNode& n )
+bool fpa::Image::MoriFilterHelper< _TInputImage, _TOutputImage >::
+_UpdateResult( _TQueueNode& n )
{
- this->Superclass::_UpdateResult( n );
- this->m_ActualCount += 1;
+ typedef typename _TOutputImage::PixelType _TOut;
+
+ n.Result = _TOut( this->m_Curve.size( ) + 1 );
+ if( this->Superclass::_UpdateResult( n ) )
+ {
+ this->m_ActualCount += 1;
+ std::cout << this->m_ActualCount << std::endl;
+ return( true );
+ }
+ else
+ {
+ this->m_NextQueue.push( n );
+ return( false );
+
+ } // fi
}
#endif // __fpa__Image__MoriFilterHelper__hxx__