From 721b19efb3da24f38076b689517b6ed1ddbd03d2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leonardo=20Fl=C3=B3rez-Valencia?= Date: Wed, 5 Jul 2017 23:22:31 -0500 Subject: [PATCH] ... --- tests/image/CMakeLists.txt | 1 + tests/image/RegionGrow_BinaryThreshold.cxx | 91 ++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 tests/image/RegionGrow_BinaryThreshold.cxx diff --git a/tests/image/CMakeLists.txt b/tests/image/CMakeLists.txt index ac3f2f6..06dfae8 100644 --- a/tests/image/CMakeLists.txt +++ b/tests/image/CMakeLists.txt @@ -2,6 +2,7 @@ set(_pfx test_fpa_image_) set( _examples RegionGrow_Tautology + RegionGrow_BinaryThreshold MoriSegmentation # Dijkstra_Identity # Dijkstra_Gaussian diff --git a/tests/image/RegionGrow_BinaryThreshold.cxx b/tests/image/RegionGrow_BinaryThreshold.cxx new file mode 100644 index 0000000..b40f25a --- /dev/null +++ b/tests/image/RegionGrow_BinaryThreshold.cxx @@ -0,0 +1,91 @@ +#include "BaseFunctions.h" +#include +#include +#include + +// ------------------------------------------------------------------------- +const unsigned int Dim = 3; +typedef short TInputPixel; +typedef unsigned char TOutputPixel; + +typedef itk::Image< TInputPixel, Dim > TInputImage; +typedef itk::Image< TOutputPixel, Dim > TOutputImage; +typedef fpa::Image::RegionGrow< TInputImage, TOutputImage > TFilter; +typedef fpa::Base::Functors::RegionGrow::BinaryThreshold< TInputPixel > TPredicate; + +// ------------------------------------------------------------------------- +int main( int argc, char* argv[] ) +{ + // Get arguments + if( argc < 8 + Dim ) + { + std::cerr + << "Usage: " << argv[ 0 ] + << " input_image output_image output_marks" + << " lower upper strict [index/point] ..." + << std::endl; + return( 1 ); + + } // fi + std::string input_image_filename = argv[ 1 ]; + std::string output_image_filename = argv[ 2 ]; + std::string output_marks_filename = argv[ 3 ]; + TInputPixel lower = TInputPixel( std::atof( argv[ 4 ] ) ); + TInputPixel upper = TInputPixel( std::atof( argv[ 5 ] ) ); + bool strict = ( argv[ 6 ][ 0 ] == '1' ); + std::string seeds_type = argv[ 7 ]; + + // Create 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 predicate + TPredicate::Pointer predicate = TPredicate::New( ); + predicate->SetLower( lower ); + predicate->SetUpper( upper ); + predicate->SetStrict( strict ); + + // Prepare filter + TFilter::Pointer filter = TFilter::New( ); + filter->SetInput( input_image ); + filter->SetPredicate( predicate ); + filter->SetInsideValue( 255 ); + filter->SetOutsideValue( 0 ); + + // Get all seeds + for( int i = 8; i < argc; i += Dim ) + { + if( seeds_type == "index" ) + { + TInputImage::IndexType seed; + for( unsigned int d = 0; d < Dim; ++d ) + seed[ d ] = std::atoi( argv[ i + d ] ); + filter->AddSeed( seed ); + } + else + { + TInputImage::PointType seed; + for( unsigned int d = 0; d < Dim; ++d ) + seed[ d ] = std::atof( argv[ i + d ] ); + filter->AddSeed( seed ); + + } // fi + } // rof + + // Execute filter + filter->Update( ); + + // Save results + std::string err1 = + fpa::tests::image::Write( filter->GetOutput( ), output_image_filename ); + std::string err2 = + fpa::tests::image::Write( filter->GetMarks( ), output_marks_filename ); + if( err1 != "" ) std::cerr << err1 << std::endl; + if( err2 != "" ) std::cerr << err2 << std::endl; + + return( 0 ); +} + +// eof - $RCSfile$ -- 2.45.0