virtual void GenerateData( ) override;
virtual void _BeforeGenerateData( );
virtual void _AfterGenerateData( );
+ virtual void _FinishOneLoop( );
virtual void _QueueInit( );
virtual TInputValue _GetInputValue( const TVertex& v ) const = 0;
virtual TOutputValue _GetOutputValue( const TVertex& v ) const = 0;
- virtual TOutputValue _ComputeOutputValue( const TNode& n ) = 0;
+ virtual bool _ComputeOutputValue( TNode& n ) = 0;
virtual void _UpdateOutputValue( const TNode& n ) = 0;
virtual void _QueueClear( ) = 0;
virtual void _QueuePush( const TNode& node ) = 0;
nnode.Vertex = *nIt;
nnode.Parent = node.Vertex;
nnode.FrontId = node.FrontId;
- nnode.Value = this->_ComputeOutputValue( nnode );
- this->_QueuePush( nnode );
- this->InvokeEvent( TEvent( nnode.Vertex, nnode.FrontId, true ) );
+ if( this->_ComputeOutputValue( nnode ) )
+ {
+ this->_QueuePush( nnode );
+ this->InvokeEvent( TEvent( nnode.Vertex, nnode.FrontId, true ) );
+
+ } // fi
} // fi
++nIt;
} // fi
} // fi
+ this->_FinishOneLoop( );
} // elihw
{
}
+// -------------------------------------------------------------------------
+template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
+void fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::
+_FinishOneLoop( )
+{
+}
+
// -------------------------------------------------------------------------
template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
void fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::
itk::FunctionBase
);
+ itkBooleanMacro( Strict );
+
itkGetConstMacro( Lower, _TValue );
itkGetConstMacro( Upper, _TValue );
+ itkGetConstMacro( Strict, bool );
itkSetMacro( Lower, _TValue );
itkSetMacro( Upper, _TValue );
+ itkSetMacro( Strict, bool );
public:
virtual bool Evaluate( const _TValue& input ) const override
{
- return( this->m_Lower < input && input < this->m_Upper );
+ if( this->m_Strict )
+ return( this->m_Lower < input && input < this->m_Upper );
+ else
+ return( this->m_Lower <= input && input <= this->m_Upper );
}
protected:
BinaryThreshold( )
- : Superclass( )
+ : Superclass( ),
+ m_Strict( true )
{
this->m_Upper = std::numeric_limits< _TValue >::max( );
if( std::numeric_limits< _TValue >::is_integer )
protected:
_TValue m_Lower;
_TValue m_Upper;
+ bool m_Strict;
};
} // ecapseman
#include <deque>
#include <set>
+#include <map>
#include <itkConceptChecking.h>
#include <itkFunctionBase.h>
#include <fpa/Base/Functors/RegionGrow/BinaryThreshold.h>
typedef std::deque< TNode > TQueue;
typedef std::set< TInputValue > TThresholds;
+ typedef std::pair< TInputValue, unsigned long > TSignalData;
+ typedef std::map< TFrontId, TSignalData > TSignal;
typedef fpa::Base::Functors::RegionGrow::BinaryThreshold< TInputValue > TPredicate;
public:
void SetThresholds(
const TInputValue& init,
const TInputValue& end,
- unsigned long number_of_thresholds
+ const TInputValue& delta
);
protected:
virtual void _BeforeGenerateData( ) override;
virtual void _AfterGenerateData( ) override;
- virtual TOutputValue _ComputeOutputValue( const TNode& n ) override;
+ virtual void _FinishOneLoop( ) override;
+ virtual bool _ComputeOutputValue( TNode& n ) override;
virtual void _QueueClear( ) override;
virtual TNode _QueuePop( ) override;
virtual void _QueuePush( const TNode& node ) override;
protected:
typename TPredicate::Pointer m_Predicate;
TThresholds m_Thresholds;
+ typename TThresholds::const_iterator m_CurrentThreshold;
TQueue m_Queues[ 2 ];
unsigned int m_CurrentQueue;
+ unsigned long m_Count;
+ TSignal m_Signal;
TOutputValue m_InsideValue;
};
SetThresholds(
const TInputValue& init,
const TInputValue& end,
- unsigned long number_of_thresholds
+ const TInputValue& delta
)
{
- double i = double( init );
- double e = double( end );
- double n = double( number_of_thresholds );
- double d = ( e - i ) / n;
- for( unsigned long c = 0; c <= number_of_thresholds; ++c )
- this->AddThreshold( TInputValue( i + ( d * double( c ) ) ) );
+ for( TInputValue thr = init; thr <= end; thr += delta )
+ this->AddThreshold( thr );
}
// -------------------------------------------------------------------------
{
this->SetInitValue( TOutputValue( 0 ) );
this->m_Predicate = TPredicate::New( );
+ this->m_Predicate->StrictOff( );
}
// -------------------------------------------------------------------------
this->_QueueClear( );
this->m_CurrentQueue = 0;
+ this->m_CurrentThreshold = this->m_Thresholds.begin( );
+ this->m_Predicate->SetLower( *( this->m_CurrentThreshold ) );
+ this->m_CurrentThreshold++;
+ this->m_Predicate->SetUpper( *( this->m_CurrentThreshold ) );
+ this->m_Count = 0;
+ this->m_Signal.clear( );
}
// -------------------------------------------------------------------------
void fpa::Base::Mori< _TAlgorithm >::
_AfterGenerateData( )
{
+ // https://stackoverflow.com/questions/22583391/peak-signal-detection-in-realtime-timeseries-data
this->Superclass::_AfterGenerateData( );
+
+ typename TSignal::const_iterator sIt = this->m_Signal.begin( );
+ for( ; sIt != this->m_Signal.end( ); ++sIt )
+ {
+ std::cout << int( sIt->first ) << " " << int( sIt->second.first ) << " " << sIt->second.second << std::endl;
+
+ } // rof
+ std::cerr << ( this->m_CurrentThreshold != this->m_Thresholds.end( ) ) << std::endl;
}
// -------------------------------------------------------------------------
template< class _TAlgorithm >
-typename fpa::Base::Mori< _TAlgorithm >::
-TOutputValue fpa::Base::Mori< _TAlgorithm >::
-_ComputeOutputValue( const TNode& n )
+void fpa::Base::Mori< _TAlgorithm >::
+_FinishOneLoop( )
+{
+ if( this->m_Queues[ this->m_CurrentQueue ].size( ) == 0 )
+ {
+ this->m_Signal[ this->m_Signal.size( ) + 1 ] =
+ TSignalData( *this->m_CurrentThreshold, this->m_Count );
+ std::cerr << *( this->m_CurrentThreshold ) << std::endl;
+ this->m_CurrentThreshold++;
+ this->m_CurrentQueue = ( this->m_CurrentQueue + 1 ) % 2;
+ if( this->m_CurrentThreshold != this->m_Thresholds.end( ) )
+ {
+ this->m_Predicate->SetUpper( *( this->m_CurrentThreshold ) );
+ this->m_Count = 0;
+ }
+ else
+ this->_QueueClear( );
+
+ } // fi
+}
+
+// -------------------------------------------------------------------------
+template< class _TAlgorithm >
+bool fpa::Base::Mori< _TAlgorithm >::
+_ComputeOutputValue( TNode& n )
{
TInputValue value = this->_GetInputValue( n.Vertex );
bool inside = this->m_Predicate->Evaluate( value );
+ n.Value = this->m_InsideValue;
if( !inside )
{
- // TODO: Update new queue
- return( this->m_InitValue );
+ n.FrontId++;
+ this->m_Queues[ ( this->m_CurrentQueue + 1 ) % 2 ].push_back( n );
}
else
- return( this->m_InsideValue );
+ this->m_Count++;
+ return( inside );
}
// -------------------------------------------------------------------------
void fpa::Base::Mori< _TAlgorithm >::
_QueuePush( const TNode& node )
{
- // TODO: Update mark
this->m_Queues[ this->m_CurrentQueue ].push_back( node );
}
nIt->Value = this->m_InsideValue;
}
-/* TODO
- typename TPredicate::Pointer m_Predicate;
- TThresholds m_Thresholds;
- TQueue m_Queues[ 2 ];
- unsigned int m_CurrentQueue;
- TOutputValue m_InsideValue;
-*/
-
#endif // __fpa__Base__Mori__hxx__
// eof - $RCSfile$
RegionGrow( );
virtual ~RegionGrow( );
- virtual TOutputValue _ComputeOutputValue( const TNode& n ) override;
+ virtual bool _ComputeOutputValue( TNode& n ) override;
virtual void _QueueClear( ) override;
virtual TNode _QueuePop( ) override;
virtual void _QueuePush( const TNode& node ) override;
// -------------------------------------------------------------------------
template< class _TAlgorithm >
-typename fpa::Base::RegionGrow< _TAlgorithm >::
-TOutputValue fpa::Base::RegionGrow< _TAlgorithm >::
-_ComputeOutputValue( const TNode& n )
+bool fpa::Base::RegionGrow< _TAlgorithm >::
+_ComputeOutputValue( TNode& n )
{
TInputValue value = this->_GetInputValue( n.Vertex );
bool inside = false;
inside = this->m_ValuePredicate->Evaluate( value );
if( this->m_VertexPredicate.IsNotNull( ) )
inside &= this->m_VertexPredicate->Evaluate( n.Vertex );
- return( ( inside )? this->m_InsideValue: this->m_InitValue );
+ n.Value = ( inside )? this->m_InsideValue: this->m_InitValue;
+ return( inside );
}
// -------------------------------------------------------------------------
}
else
sIt->IsUnified = false;
-
+
} // rof
return( nodes );
{
/**
*/
- template< class _TInputImage, class _TOutputImage, class _TFrontId = unsigned char >
+ template< class _TInputImage, class _TOutputImage >
class Mori
- : public fpa::Base::Mori< fpa::Image::Algorithm< _TInputImage, _TOutputImage, fpa::Base::MarksInterface< typename _TInputImage::IndexType >, fpa::Base::SingleSeedInterface< typename _TInputImage::IndexType, typename _TInputImage::PointType, typename _TInputImage::PixelType, typename _TOutputImage::PixelType, _TFrontId, typename _TInputImage::IndexType::LexicographicCompare > > >
+ : public fpa::Base::Mori< fpa::Image::Algorithm< _TInputImage, _TOutputImage, fpa::Base::MarksInterface< typename _TInputImage::IndexType >, fpa::Base::SingleSeedInterface< typename _TInputImage::IndexType, typename _TInputImage::PointType, typename _TInputImage::PixelType, typename _TOutputImage::PixelType, typename _TOutputImage::PixelType, typename _TInputImage::IndexType::LexicographicCompare > > >
{
public:
typedef _TInputImage TInputImage;
typedef _TOutputImage TOutputImage;
- typedef _TFrontId TFrontId;
typedef typename TInputImage::IndexType TVertex;
typedef typename TInputImage::PointType TPoint;
typedef typename TVertex::LexicographicCompare TVertexCompare;
typedef typename TInputImage::PixelType TInputValue;
typedef typename TOutputImage::PixelType TOutputValue;
+ typedef typename TOutputImage::PixelType TFrontId;
typedef fpa::Base::MarksInterface< TVertex > TMarksInterface;
typedef fpa::Base::SingleSeedInterface< TVertex, TPoint, TInputValue, TOutputValue, TFrontId, TVertexCompare > TSeedsInterface;
#include <fpa/Image/Mori.h>
// -------------------------------------------------------------------------
-const unsigned int Dim = 2;
-typedef unsigned char TPixel;
+const unsigned int Dim = 3;
+typedef short TPixel;
+typedef unsigned short TLabel;
-typedef itk::Image< TPixel, Dim > TImage;
-typedef fpa::Image::Mori< TImage, TImage > TFilter;
+typedef itk::Image< TPixel, Dim > TInputImage;
+typedef itk::Image< TLabel, Dim > TLabelImage;
+typedef fpa::Image::Mori< TInputImage, TLabelImage > TFilter;
// -------------------------------------------------------------------------
int main( int argc, char* argv[] )
{
// Get arguments
- if( argc < 9 )
+ if( argc < 8 + Dim )
{
std::cerr
<< "Usage: " << argv[ 0 ]
<< " input_image output_image output_levels"
- << " init_threshold end_threshold number_of_threshold seed_x seed_y"
+ << " init_threshold end_threshold delta [index/point] seed"
<< std::endl;
return( 1 );
std::string input_image_filename = argv[ 1 ];
std::string output_image_filename = argv[ 2 ];
std::string output_levels_filename = argv[ 3 ];
- unsigned char init_threshold = std::atoi( argv[ 4 ] );
- unsigned char end_threshold = std::atoi( argv[ 5 ] );
- unsigned char number_of_thresholds = std::atoi( argv[ 6 ] );
- TImage::IndexType seed;
- seed[ 0 ] = std::atoi( argv[ 7 ] );
- seed[ 1 ] = std::atoi( argv[ 8 ] );
+ TPixel init_threshold = std::atoi( argv[ 4 ] );
+ TPixel end_threshold = std::atoi( argv[ 5 ] );
+ TPixel delta = std::atoi( argv[ 6 ] );
+ std::string seed_type = argv[ 7 ];
+
+ TInputImage::IndexType iseed;
+ TInputImage::PointType pseed;
+ for( unsigned int i = 0; i < Dim; ++i )
+ {
+ if( seed_type == "index" )
+ iseed[ i ] = std::atoi( argv[ 8 + i ] );
+ else
+ pseed[ i ] = std::atof( argv[ 8 + i ] );
+
+ } // rof
// Create image
- TImage::Pointer input_image;
+ TInputImage::Pointer input_image;
std::string err0 =
fpa::tests::image::Read( input_image, input_image_filename );
if( err0 != "" ) std::cerr << err0 << std::endl;
// Prepare filter
TFilter::Pointer filter = TFilter::New( );
filter->SetInput( input_image );
- filter->SetSeed( seed );
- filter->SetThresholds( init_threshold, end_threshold, number_of_thresholds );
+ if( seed_type == "index" )
+ filter->SetSeed( iseed );
+ else
+ filter->SetSeed( pseed );
+ filter->SetThresholds( init_threshold, end_threshold, delta );
filter->SetInsideValue( 255 );
filter->SetOutsideValue( 0 );