6 #include <itkImageFileReader.h>
7 #include <itkImageFileWriter.h>
8 #include <itkInvertIntensityImageFilter.h>
9 #include <itkMinimumMaximumImageCalculator.h>
10 #include <itkDanielssonDistanceMapImageFilter.h>
12 // -------------------------------------------------------------------------
13 const unsigned int Dim = 3;
14 typedef unsigned char TPixel;
15 typedef float TScalar;
16 typedef itk::Image< TPixel, Dim > TImage;
17 typedef itk::Image< TScalar, Dim > TScalarImage;
18 typedef itk::ImageFileReader< TImage > TImageReader;
19 typedef itk::ImageFileWriter< TScalarImage > TImageWriter;
21 // -------------------------------------------------------------------------
22 int main( int argc, char* argv[] )
27 << "Usage: " << argv[ 0 ]
28 << " input_image output_image"
33 std::string input_image_fn = argv[ 1 ];
34 std::string output_image_fn = argv[ 2 ];
37 TImageReader::Pointer input_image_reader = TImageReader::New( );
38 input_image_reader->SetFileName( input_image_fn );
41 input_image_reader->Update( );
43 catch( itk::ExceptionObject& err )
45 std::cerr << "Error caught: " << err << std::endl;
51 typedef itk::MinimumMaximumImageCalculator< TImage > TMinMax;
52 TMinMax::Pointer minmax = TMinMax::New( );
53 minmax->SetImage( input_image_reader->GetOutput( ) );
56 typedef itk::InvertIntensityImageFilter< TImage > TInvert;
57 TInvert::Pointer invert = TInvert::New( );
58 invert->SetInput( input_image_reader->GetOutput( ) );
59 invert->SetMaximum( minmax->GetMaximum( ) );
61 typedef itk::DanielssonDistanceMapImageFilter< TImage, TScalarImage > TDistance;
62 TDistance::Pointer distance = TDistance::New( );
63 distance->SetInput( invert->GetOutput( ) );
64 distance->InputIsBinaryOn( );
65 distance->SquaredDistanceOn( );
66 std::clock_t start = std::clock( );
68 std::clock_t end = std::clock( );
69 double seconds = double( end - start ) / double( CLOCKS_PER_SEC );
70 std::cout << "Distance map time = " << seconds << std::endl;
72 TImageWriter::Pointer writer = TImageWriter::New( );
73 writer->SetInput( distance->GetOutput( ) );
74 writer->SetFileName( output_image_fn );