]> Creatis software - FrontAlgorithms.git/blob - tests/image/RegionGrow_Tautology.cxx
d19969b735bb7a034066f9ff9e8fd5895ed43ceb
[FrontAlgorithms.git] / tests / image / RegionGrow_Tautology.cxx
1 #include "BaseFunctions.h"
2 #include <itkImage.h>
3 #include <fpa/Image/RegionGrow.h>
4 #include <fpa/Base/Functors/RegionGrow/Tautology.h>
5
6 // -------------------------------------------------------------------------
7 const unsigned int Dim = 2;
8 typedef unsigned char TPixel;
9
10 typedef itk::Image< TPixel, Dim >                            TImage;
11 typedef fpa::Image::RegionGrow< TImage, TImage >             TFilter;
12 typedef fpa::Base::Functors::RegionGrow::Tautology< TPixel > TPredicate;
13
14 // -------------------------------------------------------------------------
15 int main( int argc, char* argv[] )
16 {
17   // Get arguments
18   if( argc < 5 )
19   {
20     std::cerr
21       << "Usage: " << argv[ 0 ]
22       << " output_image output_marks width height ..."
23       << std::endl;
24     return( 1 );
25
26   } // fi
27   std::string output_image_filename = argv[ 1 ];
28   std::string output_marks_filename = argv[ 2 ];
29   int width = std::atoi( argv[ 3 ] );
30   int height = std::atoi( argv[ 4 ] );
31
32   // Create image
33   TImage::Pointer image;
34   fpa::tests::image::CreateImage( image, 0, width, height, 1.0, 1.0 );
35
36   // Prepare predicate
37   TPredicate::Pointer predicate = TPredicate::New( );
38
39   // Prepare filter
40   TFilter::Pointer filter = TFilter::New( );
41   filter->SetInput( image );
42   filter->SetPredicate( predicate );
43   filter->SetInsideValue( 255 );
44   filter->SetOutsideValue( 0 );
45
46   // Get all seeds
47   for( int i = 6; i < argc; i += 2 )
48   {
49     if( i + 1 < argc )
50     {
51       TImage::IndexType seed;
52       seed[ 0 ] = std::atoi( argv[ i ] );
53       seed[ 1 ] = std::atoi( argv[ i + 1 ] );
54       filter->AddSeed( seed );
55
56     } // fi
57
58   } // rof
59
60   // Execute filter
61   filter->Update( );
62
63   // Save results
64   std::string err1 =
65     fpa::tests::image::Write( filter->GetOutput( ), output_image_filename );
66   std::string err2 =
67     fpa::tests::image::Write( filter->GetMarks( ), output_marks_filename );
68   if( err1 != "" ) std::cerr << err1 << std::endl;
69   if( err2 != "" ) std::cerr << err2 << std::endl;
70
71   return( 0 );
72 }
73
74 // eof - $RCSfile$