]> Creatis software - FrontAlgorithms.git/blob - examples/CreateMoriInputImage.cxx
...
[FrontAlgorithms.git] / examples / CreateMoriInputImage.cxx
1 #include <queue>
2 #include <itkImage.h>
3 #include <itkImageFileReader.h>
4 #include <itkSignedMaurerDistanceMapImageFilter.h>
5 #include <itkImageFileWriter.h>
6
7 // -------------------------------------------------------------------------
8 static const unsigned int Dim = 2;
9 typedef short TInputPixel;
10 typedef float TOutputPixel;
11 typedef itk::Image< TInputPixel, Dim > TInputImage;
12 typedef itk::Image< TOutputPixel, Dim > TOutputImage;
13
14 // -------------------------------------------------------------------------
15 int main( int argc, char* argv[] )
16 {
17   // Command configuration
18   if( argc < 3 )
19   {
20     std::cerr
21       << "Usage: " << argv[ 0 ] << " input_image output_image"
22       << std::endl;
23     return( 1 );
24
25   } // fi
26   std::string input_image_filename = argv[ 1 ];
27   std::string output_image_filename = argv[ 2 ];
28
29   // Read image
30   typedef itk::ImageFileReader< TInputImage > TReader;
31   TReader::Pointer reader = TReader::New( );
32   reader->SetFileName( input_image_filename );
33
34   // Distance map
35   typedef itk::SignedMaurerDistanceMapImageFilter< TInputImage, TOutputImage > TFilter;
36   TFilter::Pointer filter = TFilter::New( );
37   filter->SetInput( reader->GetOutput( ) );
38   filter->SetBackgroundValue( 0 );
39   filter->InsideIsPositiveOn( );
40   filter->SquaredDistanceOff( );
41   filter->UseImageSpacingOn( );
42
43   // Write image
44   typedef itk::ImageFileWriter< TOutputImage > TWriter;
45   TWriter::Pointer writer = TWriter::New( );
46   writer->SetInput( filter->GetOutput( ) );
47   writer->SetFileName( output_image_filename );
48
49   // Execute pipeline
50   try
51   {
52     writer->Update( );
53   }
54   catch( std::exception& err )
55   {
56     std::cerr << "Error caught: " << err.what( ) << std::endl;
57     return( 1 );
58
59   } // yrt
60
61   return( 0 );
62 }
63
64 // eof - $RCSfile$