]> Creatis software - FrontAlgorithms.git/blob - tests/image/RegionGrow/Tautology.cxx
...
[FrontAlgorithms.git] / tests / image / RegionGrow / Tautology.cxx
1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5
6 #include <itkImage.h>
7 #include <itkImageFileWriter.h>
8 #include <fpa/Filters/Image/RegionGrow.h>
9 #include <fpa/Functors/RegionGrow/Tautology.h>
10
11 // -------------------------------------------------------------------------
12 const unsigned int Dim = 2;
13 typedef unsigned char TPixel;
14 typedef itk::Image< TPixel, Dim > TImage;
15
16 // -------------------------------------------------------------------------
17 int main( int argc, char* argv[] )
18 {
19   // Get arguments
20   if( argc < 4 )
21   {
22     std::cerr
23       << "Usage: " << argv[ 0 ]
24       << " output_image output_marks size [seeds]"
25       << std::endl;
26     return( 1 );
27
28   } // fi
29   std::string output_image_filename = argv[ 1 ];
30   std::string output_marks_filename = argv[ 2 ];
31   TImage::SizeType size;
32   size.Fill( std::atoi( argv[ 3 ] ) );
33
34   // Create image
35   TImage::Pointer image = TImage::New( );
36   image->SetRegions( size );
37   image->Allocate( );
38   image->FillBuffer( TPixel( 0 ) );
39
40   // Prepare predicate
41   typedef fpa::Functors::RegionGrow::Tautology< TPixel > TPredicate;
42   TPredicate::Pointer predicate = TPredicate::New( );
43
44   // Prepare filter
45   typedef fpa::Filters::Image::RegionGrow< TImage, TImage > TFilter;
46   TFilter::Pointer filter = TFilter::New( );
47   filter->SetInput( image );
48   filter->SetPredicate( predicate );
49   filter->SetInsideValue( std::numeric_limits< TPixel >::max( ) );
50   filter->SetOutsideValue( TPixel( 0 ) );
51
52   // Get all seeds
53   for( int i = 4; i < argc; i += Dim )
54   {
55     TImage::IndexType seed;
56     for( int j = 0; j < Dim; ++j )
57       if( i + j < argc )
58         seed[ j ] = std::atoi( argv[ i + j ] );
59     filter->AddSeed( seed );
60
61   } // rof
62
63   // Execute filter
64   filter->Update( );
65
66   // Save results
67   typedef itk::ImageFileWriter< TFilter::TOutputImage > TOutputWriter;
68   TOutputWriter::Pointer output_writer = TOutputWriter::New( );
69   output_writer->SetInput( filter->GetOutput( ) );
70   output_writer->SetFileName( output_image_filename );
71
72   typedef itk::ImageFileWriter< TFilter::TMarksImage > TMarksWriter;
73   TMarksWriter::Pointer marks_writer = TMarksWriter::New( );
74   marks_writer->SetInput( filter->GetMarks( ) );
75   marks_writer->SetFileName( output_marks_filename );
76
77   try
78   {
79     output_writer->Update( );
80     marks_writer->Update( );
81   }
82   catch( std::exception& err )
83   {
84     std::cerr << "Error caught: " << err.what( ) << std::endl;
85     return( 1 );
86
87   } // yrt
88
89   return( 0 );
90 }
91
92 // eof - $RCSfile$