]> Creatis software - FrontAlgorithms.git/blob - appli/examples/example_BinaryDistanceMap.cxx
More tests
[FrontAlgorithms.git] / appli / examples / example_BinaryDistanceMap.cxx
1 #include <ctime>
2 #include <iostream>
3 #include <string>
4
5 #include <itkImage.h>
6 #include <itkImageFileReader.h>
7 #include <itkImageFileWriter.h>
8 #include <itkInvertIntensityImageFilter.h>
9 #include <itkMinimumMaximumImageCalculator.h>
10 #include <itkDanielssonDistanceMapImageFilter.h>
11
12 /*
13 #include <cmath>
14 #include <deque>
15 #include <limits>
16 #include <map>
17
18 #include <itkConstNeighborhoodIterator.h>
19 #include <itkNeighborhoodIterator.h>
20 #include <itkImageToVTKImageFilter.h>
21
22
23 #include <vtkPoints.h>
24 #include <vtkCellArray.h>
25 #include <vtkFloatArray.h>
26 #include <vtkPolyData.h>
27 #include <vtkSmartPointer.h>
28
29 #include <fpa/Image/DijkstraWithSphereBacktracking.h>
30 #include <fpa/VTK/ImageMPR.h>
31 #include <fpa/VTK/Image3DObserver.h>
32 */
33
34 // -------------------------------------------------------------------------
35 const unsigned int Dim = 3;
36 typedef unsigned char                        TPixel;
37 typedef float                                TScalar;
38 typedef itk::Image< TPixel, Dim >            TImage;
39 typedef itk::Image< TScalar, Dim >           TScalarImage;
40 typedef itk::ImageFileReader< TImage >       TImageReader;
41 typedef itk::ImageFileWriter< TScalarImage > TImageWriter;
42
43 // -------------------------------------------------------------------------
44 int main( int argc, char* argv[] )
45 {
46   if( argc < 3 )
47   {
48     std::cerr
49       << "Usage: " << argv[ 0 ]
50       << " input_image output_image"
51       << std::endl;
52     return( 1 );
53
54   } // fi
55   std::string input_image_fn = argv[ 1 ];
56   std::string output_image_fn = argv[ 2 ];
57
58   // Read image
59   TImageReader::Pointer input_image_reader = TImageReader::New( );
60   input_image_reader->SetFileName( input_image_fn );
61   try
62   {
63     input_image_reader->Update( );
64   }
65   catch( itk::ExceptionObject& err )
66   {
67     std::cerr << "Error caught: " << err << std::endl;
68     return( 1 );
69
70   } // yrt
71
72   // Invert intensity
73   typedef itk::MinimumMaximumImageCalculator< TImage > TMinMax;
74   TMinMax::Pointer minmax = TMinMax::New( );
75   minmax->SetImage( input_image_reader->GetOutput( ) );
76   minmax->Compute( );
77
78   typedef itk::InvertIntensityImageFilter< TImage > TInvert;
79   TInvert::Pointer invert = TInvert::New( );
80   invert->SetInput( input_image_reader->GetOutput( ) );
81   invert->SetMaximum( minmax->GetMaximum( ) );
82
83   typedef itk::DanielssonDistanceMapImageFilter< TImage, TScalarImage > TDistance;
84   TDistance::Pointer distance = TDistance::New( );
85   distance->SetInput( invert->GetOutput( ) );
86   distance->InputIsBinaryOn( );
87   distance->SquaredDistanceOn( );
88   std::clock_t start = std::clock( );
89   distance->Update( );
90   std::clock_t end = std::clock( );
91   double seconds = double( end - start ) / double( CLOCKS_PER_SEC );
92   std::cout << "Distance map time = " << seconds << std::endl;
93
94   TImageWriter::Pointer writer = TImageWriter::New( );
95   writer->SetInput( distance->GetOutput( ) );
96   writer->SetFileName( output_image_fn );
97   writer->Update( );
98
99   return( 0 );
100 }
101
102 // eof - $RCSfile$