]> Creatis software - FrontAlgorithms.git/commitdiff
More tests
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 17 Mar 2015 20:12:49 +0000 (15:12 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 17 Mar 2015 20:12:49 +0000 (15:12 -0500)
appli/examples/CMakeLists.txt
appli/examples/example_BinaryDistanceMap.cxx [new file with mode: 0644]
appli/examples/example_ImageAlgorithmDijkstra_03.cxx

index 62f894b4ad06f961a37416f4691f7c580a302fbe..a112096765d893af7c7c873d6d91e6bac6983763 100644 (file)
@@ -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 (file)
index 0000000..5fac440
--- /dev/null
@@ -0,0 +1,102 @@
+#include <ctime>
+#include <iostream>
+#include <string>
+
+#include <itkImage.h>
+#include <itkImageFileReader.h>
+#include <itkImageFileWriter.h>
+#include <itkInvertIntensityImageFilter.h>
+#include <itkMinimumMaximumImageCalculator.h>
+#include <itkDanielssonDistanceMapImageFilter.h>
+
+/*
+#include <cmath>
+#include <deque>
+#include <limits>
+#include <map>
+
+#include <itkConstNeighborhoodIterator.h>
+#include <itkNeighborhoodIterator.h>
+#include <itkImageToVTKImageFilter.h>
+
+
+#include <vtkPoints.h>
+#include <vtkCellArray.h>
+#include <vtkFloatArray.h>
+#include <vtkPolyData.h>
+#include <vtkSmartPointer.h>
+
+#include <fpa/Image/DijkstraWithSphereBacktracking.h>
+#include <fpa/VTK/ImageMPR.h>
+#include <fpa/VTK/Image3DObserver.h>
+*/
+
+// -------------------------------------------------------------------------
+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$
index c07dc8ef3d23b5303bee7c4c5bc261f558086f6e..185991f46e96b45c0cab430e823e8276969ccd4b 100644 (file)
@@ -14,6 +14,9 @@
 #include <itkImageFileWriter.h>
 #include <itkImageToVTKImageFilter.h>
 
+#include <itkMinimumMaximumImageCalculator.h>
+#include <itkInvertIntensityImageFilter.h>
+
 #include <vtkPoints.h>
 #include <vtkCellArray.h>
 #include <vtkFloatArray.h>
 
 // -------------------------------------------------------------------------
 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 )
   {