#include "BaseFunctions.h"
+#include <chrono>
#include <itkImage.h>
#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 < 9 + Dim )
{
std::cerr
<< "Usage: " << argv[ 0 ]
- << " input_image output_image output_levels"
- << " init_threshold end_threshold number_of_threshold seed_x seed_y"
+ << " input_image output_image output_marks output_signal"
+ << " init_threshold end_threshold delta [index/point] seed"
<< std::endl;
return( 1 );
} // fi
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 ] );
+ std::string output_marks_filename = argv[ 3 ];
+ std::string output_signal_filename = argv[ 4 ];
+ TPixel init_threshold = std::atoi( argv[ 5 ] );
+ TPixel end_threshold = std::atoi( argv[ 6 ] );
+ TPixel delta = std::atoi( argv[ 7 ] );
+ std::string seed_type = argv[ 8 ];
+
+ TInputImage::IndexType iseed;
+ TInputImage::PointType pseed;
+ for( unsigned int i = 0; i < Dim; ++i )
+ {
+ if( seed_type == "index" )
+ iseed[ i ] = std::atoi( argv[ 9 + i ] );
+ else
+ pseed[ i ] = std::atof( argv[ 9 + 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 );
+ filter->SetSignalKernelSize( 20 );
+ filter->SetSignalThreshold( 500 );
+ filter->SetSignalInfluence( 0.5 );
+ filter->SetMinimumThreshold( -850 );
// Execute filter
+ std::chrono::time_point< std::chrono::high_resolution_clock > tstart, tend;
+ tstart = std::chrono::high_resolution_clock::now( );
filter->Update( );
+ tend = std::chrono::high_resolution_clock::now( );
+ std::chrono::duration< double > telapsed = tend - tstart;
// Save results
std::string err1 =
- fpa::tests::image::Write( filter->GetOutput( ), output_image_filename );
+ fpa::tests::image::Write( filter->GetThresholdedOutput( ), output_image_filename );
std::string err2 =
- fpa::tests::image::Write( filter->GetOutputLevels( ), output_levels_filename );
+ fpa::tests::image::Write( filter->GetMarks( ), output_marks_filename );
if( err1 != "" ) std::cerr << err1 << std::endl;
if( err2 != "" ) std::cerr << err2 << std::endl;
+ std::ofstream osignal( output_signal_filename.c_str( ) );
+ unsigned long nThr = filter->GetNumberOfEvaluatedThresholds( );
+ for( unsigned long i = 0; i < nThr; ++i )
+ {
+ double x, y;
+ TFilter::TPeak p;
+ filter->GetSignalValues( i, x, y, p );
+ osignal << x << " " << y << std::endl;
+
+ } // rof
+ osignal.close( );
+
+ std::cout
+ << "------------------------------------------------------" << std::endl
+ << "Elapsed time: " << telapsed.count( ) << " s" << std::endl
+ << "Optimum threshold: " << filter->GetOptimumThreshold( ) << std::endl
+ << "Number of evaluated thresholds: " << nThr << std::endl
+ << "------------------------------------------------------"
+ << std::endl;
+
return( 0 );
}