]> Creatis software - FrontAlgorithms.git/blob - appli/examples/example_HausdorffDistance.cxx
Big bug stamped on wall
[FrontAlgorithms.git] / appli / examples / example_HausdorffDistance.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 <itkHausdorffDistanceImageFilter.h>
9
10 // -------------------------------------------------------------------------
11 const unsigned int Dim = 3;
12 typedef unsigned short                 TPixel;
13 typedef float                          TScalar;
14 typedef itk::Image< TPixel, Dim >      TImage;
15 typedef itk::ImageFileReader< TImage > TImageReader;
16 typedef itk::HausdorffDistanceImageFilter< TImage, TImage > TDistance;
17
18 // -------------------------------------------------------------------------
19 int main( int argc, char* argv[] )
20 {
21   if( argc < 3 )
22   {
23     std::cerr
24       << "Usage: " << argv[ 0 ]
25       << " first_image second_image"
26       << std::endl;
27     return( 1 );
28
29   } // fi
30   std::string first_image_fn = argv[ 1 ];
31   std::string second_image_fn = argv[ 2 ];
32
33   // Read image
34   TImageReader::Pointer first_image_reader = TImageReader::New( );
35   TImageReader::Pointer second_image_reader = TImageReader::New( );
36   first_image_reader->SetFileName( first_image_fn );
37   second_image_reader->SetFileName( second_image_fn );
38   try
39   {
40     first_image_reader->Update( );
41     second_image_reader->Update( );
42   }
43   catch( itk::ExceptionObject& err )
44   {
45     std::cerr << "Error caught: " << err << std::endl;
46     return( 1 );
47
48   } // yrt
49
50   TDistance::Pointer distance = TDistance::New( );
51   distance->SetInput1( first_image_reader->GetOutput( ) );
52   distance->SetInput2( second_image_reader->GetOutput( ) );
53   distance->Update( );
54   std::cout << "Hausdorff distance = " << distance->GetHausdorffDistance( ) << std::endl;
55
56   return( 0 );
57 }
58
59 // eof - $RCSfile$