]> Creatis software - FrontAlgorithms.git/blobdiff - examples/CreateMoriInputImage.cxx
...
[FrontAlgorithms.git] / examples / CreateMoriInputImage.cxx
diff --git a/examples/CreateMoriInputImage.cxx b/examples/CreateMoriInputImage.cxx
new file mode 100644 (file)
index 0000000..144ed6e
--- /dev/null
@@ -0,0 +1,64 @@
+#include <queue>
+#include <itkImage.h>
+#include <itkImageFileReader.h>
+#include <itkSignedMaurerDistanceMapImageFilter.h>
+#include <itkImageFileWriter.h>
+
+// -------------------------------------------------------------------------
+static const unsigned int Dim = 2;
+typedef short TInputPixel;
+typedef float TOutputPixel;
+typedef itk::Image< TInputPixel, Dim > TInputImage;
+typedef itk::Image< TOutputPixel, Dim > TOutputImage;
+
+// -------------------------------------------------------------------------
+int main( int argc, char* argv[] )
+{
+  // Command configuration
+  if( argc < 3 )
+  {
+    std::cerr
+      << "Usage: " << argv[ 0 ] << " input_image output_image"
+      << std::endl;
+    return( 1 );
+
+  } // fi
+  std::string input_image_filename = argv[ 1 ];
+  std::string output_image_filename = argv[ 2 ];
+
+  // Read image
+  typedef itk::ImageFileReader< TInputImage > TReader;
+  TReader::Pointer reader = TReader::New( );
+  reader->SetFileName( input_image_filename );
+
+  // Distance map
+  typedef itk::SignedMaurerDistanceMapImageFilter< TInputImage, TOutputImage > TFilter;
+  TFilter::Pointer filter = TFilter::New( );
+  filter->SetInput( reader->GetOutput( ) );
+  filter->SetBackgroundValue( 0 );
+  filter->InsideIsPositiveOn( );
+  filter->SquaredDistanceOff( );
+  filter->UseImageSpacingOn( );
+
+  // Write image
+  typedef itk::ImageFileWriter< TOutputImage > TWriter;
+  TWriter::Pointer writer = TWriter::New( );
+  writer->SetInput( filter->GetOutput( ) );
+  writer->SetFileName( output_image_filename );
+
+  // Execute pipeline
+  try
+  {
+    writer->Update( );
+  }
+  catch( std::exception& err )
+  {
+    std::cerr << "Error caught: " << err.what( ) << std::endl;
+    return( 1 );
+
+  } // yrt
+
+  return( 0 );
+}
+
+// eof - $RCSfile$