From b6fa7f73265dc1f5bf2fb8dc07c747ae0060d3bb Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Tue, 17 Mar 2015 15:12:49 -0500 Subject: [PATCH] More tests --- appli/examples/CMakeLists.txt | 2 + appli/examples/example_BinaryDistanceMap.cxx | 102 ++++++++++++++++++ .../example_ImageAlgorithmDijkstra_03.cxx | 43 ++++---- 3 files changed, 126 insertions(+), 21 deletions(-) create mode 100644 appli/examples/example_BinaryDistanceMap.cxx diff --git a/appli/examples/CMakeLists.txt b/appli/examples/CMakeLists.txt index 62f894b..a112096 100644 --- a/appli/examples/CMakeLists.txt +++ b/appli/examples/CMakeLists.txt @@ -1,6 +1,8 @@ IF(BUILD_EXAMPLES) SET( APPLIS + example + example_BinaryDistanceMap example_ImageAlgorithmRegionGrow_00 example_ImageAlgorithmDijkstra_00 example_ImageAlgorithmFastMarching_00 diff --git a/appli/examples/example_BinaryDistanceMap.cxx b/appli/examples/example_BinaryDistanceMap.cxx new file mode 100644 index 0000000..5fac440 --- /dev/null +++ b/appli/examples/example_BinaryDistanceMap.cxx @@ -0,0 +1,102 @@ +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +/* +#include +#include +#include +#include + +#include +#include +#include + + +#include +#include +#include +#include +#include + +#include +#include +#include +*/ + +// ------------------------------------------------------------------------- +const unsigned int Dim = 3; +typedef unsigned char TPixel; +typedef float TScalar; +typedef itk::Image< TPixel, Dim > TImage; +typedef itk::Image< TScalar, Dim > TScalarImage; +typedef itk::ImageFileReader< TImage > TImageReader; +typedef itk::ImageFileWriter< TScalarImage > TImageWriter; + +// ------------------------------------------------------------------------- +int main( int argc, char* argv[] ) +{ + if( argc < 3 ) + { + std::cerr + << "Usage: " << argv[ 0 ] + << " input_image output_image" + << std::endl; + return( 1 ); + + } // fi + std::string input_image_fn = argv[ 1 ]; + std::string output_image_fn = argv[ 2 ]; + + // Read image + TImageReader::Pointer input_image_reader = TImageReader::New( ); + input_image_reader->SetFileName( input_image_fn ); + try + { + input_image_reader->Update( ); + } + catch( itk::ExceptionObject& err ) + { + std::cerr << "Error caught: " << err << std::endl; + return( 1 ); + + } // yrt + + // Invert intensity + typedef itk::MinimumMaximumImageCalculator< TImage > TMinMax; + TMinMax::Pointer minmax = TMinMax::New( ); + minmax->SetImage( input_image_reader->GetOutput( ) ); + minmax->Compute( ); + + typedef itk::InvertIntensityImageFilter< TImage > TInvert; + TInvert::Pointer invert = TInvert::New( ); + invert->SetInput( input_image_reader->GetOutput( ) ); + invert->SetMaximum( minmax->GetMaximum( ) ); + + typedef itk::DanielssonDistanceMapImageFilter< TImage, TScalarImage > TDistance; + TDistance::Pointer distance = TDistance::New( ); + distance->SetInput( invert->GetOutput( ) ); + distance->InputIsBinaryOn( ); + distance->SquaredDistanceOn( ); + std::clock_t start = std::clock( ); + distance->Update( ); + std::clock_t end = std::clock( ); + double seconds = double( end - start ) / double( CLOCKS_PER_SEC ); + std::cout << "Distance map time = " << seconds << std::endl; + + TImageWriter::Pointer writer = TImageWriter::New( ); + writer->SetInput( distance->GetOutput( ) ); + writer->SetFileName( output_image_fn ); + writer->Update( ); + + return( 0 ); +} + +// eof - $RCSfile$ diff --git a/appli/examples/example_ImageAlgorithmDijkstra_03.cxx b/appli/examples/example_ImageAlgorithmDijkstra_03.cxx index c07dc8e..185991f 100644 --- a/appli/examples/example_ImageAlgorithmDijkstra_03.cxx +++ b/appli/examples/example_ImageAlgorithmDijkstra_03.cxx @@ -14,6 +14,9 @@ #include #include +#include +#include + #include #include #include @@ -26,13 +29,13 @@ // ------------------------------------------------------------------------- const unsigned int Dim = 3; -typedef double TPixel; -typedef double TScalar; +typedef float TPixel; +typedef float TScalar; typedef itk::Image< TPixel, Dim > TImage; typedef itk::ImageToVTKImageFilter< TImage > TVTKImage; typedef itk::ImageFileReader< TImage > TImageReader; -typedef itk::ImageFileWriter< TImage > TImageWriter; +typedef itk::ImageFileWriter< TImage > TImageWriter; typedef fpa::Image::DijkstraWithSphereBacktracking< TImage, TScalar > TDijkstra; typedef fpa::VTK::ImageMPR TMPR; @@ -41,23 +44,25 @@ typedef fpa::VTK::Image3DObserver< TDijkstra, vtkRenderWindow > TDijkstraObs; // ------------------------------------------------------------------------- int main( int argc, char* argv[] ) { - if( argc < 4 ) + if( argc < 6 ) { std::cerr << "Usage: " << argv[ 0 ] - << " input_image output_image" - << " neighborhood_order" + << " input_image x y z output_image" << " visual_debug" << std::endl; return( 1 ); } // fi std::string input_image_fn = argv[ 1 ]; - std::string output_image_fn = argv[ 2 ]; - unsigned int neighborhood_order = std::atoi( argv[ 3 ] ); + TImage::PointType seed_pnt; + seed_pnt[ 0 ] = std::atof( argv[ 2 ] ); + seed_pnt[ 1 ] = std::atof( argv[ 3 ] ); + seed_pnt[ 2 ] = std::atof( argv[ 4 ] ); + std::string output_image_fn = argv[ 5 ]; bool visual_debug = false; - if( argc > 4 ) - visual_debug = ( std::atoi( argv[ 4 ] ) == 1 ); + if( argc > 6 ) + visual_debug = ( std::atoi( argv[ 6 ] ) == 1 ); // Read image TImageReader::Pointer input_image_reader = TImageReader::New( ); @@ -84,25 +89,21 @@ int main( int argc, char* argv[] ) view.SetSize( 800, 800 ); view.SetImage( vtk_image->GetOutput( ) ); - // Wait for a seed to be given - while( view.GetNumberOfSeeds( ) == 0 ) - view.Start( ); + // Allow some interaction + view.Start( ); - // Get seed from user - double seed[ 3 ]; - view.GetSeed( 0, seed ); - TImage::PointType seed_pnt; - seed_pnt[ 0 ] = seed[ 0 ]; - seed_pnt[ 1 ] = seed[ 1 ]; - seed_pnt[ 2 ] = seed[ 2 ]; TImage::IndexType seed_idx; input_image->TransformPhysicalPointToIndex( seed_pnt, seed_idx ); + std::cout << seed_idx << " " << seed_pnt << std::endl; + seed_idx[ 0 ] = 256; + seed_idx[ 1 ] = 313; + seed_idx[ 2 ] = 381; // Extract paths TDijkstra::Pointer paths = TDijkstra::New( ); paths->AddSeed( seed_idx, TScalar( 0 ) ); paths->SetInput( input_image ); - paths->SetNeighborhoodOrder( neighborhood_order ); + paths->SetNeighborhoodOrder( 2 ); if( visual_debug ) { -- 2.47.1