]> Creatis software - FrontAlgorithms.git/blob - tests/image/RegionGrow_Tautology.cxx
7cdffa53628c5109e54d2303be412053adec7691
[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 < 6 )
19   {
20     std::cerr
21       << "Usage: " << argv[ 0 ]
22       << " output_image output_marks width height visual_debug ..."
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   bool visual_debug = ( argv[ 5 ][ 0 ] == '1' );
32
33   // Create image
34   TImage::Pointer image;
35   fpa::tests::image::CreateImage( image, 0, width, height, 1.0, 1.0 );
36
37   // Interact with image
38   fpa::tests::image::Viewer< TFilter > viewer( image );
39   if( visual_debug )
40   {
41     viewer.ActivateSeedWidget( );
42     viewer.Show( );
43
44   } // fi
45
46   // Prepare predicate
47   TPredicate::Pointer predicate = TPredicate::New( );
48
49   // Prepare filter
50   TFilter::Pointer filter = TFilter::New( );
51   filter->SetInput( image );
52   filter->SetPredicate( predicate );
53   filter->SetInsideValue( 255 );
54   filter->SetOutsideValue( 0 );
55
56   // Get all seeds
57   for( int i = 6; i < argc; i += 2 )
58   {
59     if( i + 1 < argc )
60     {
61       TImage::IndexType seed;
62       seed[ 0 ] = std::atoi( argv[ i ] );
63       seed[ 1 ] = std::atoi( argv[ i + 1 ] );
64       filter->AddSeed( seed );
65
66     } // fi
67
68   } // rof
69   viewer.AssociateSeedsTo( filter );
70
71   // Prepare visual debug and update
72   if( visual_debug )
73     viewer.ObserveFilter( filter );
74   filter->Update( );
75
76   // Save results
77   std::string err1 =
78     fpa::tests::image::Write( filter->GetOutput( ), output_image_filename );
79   std::string err2 =
80     fpa::tests::image::Write( filter->GetMarks( ), output_marks_filename );
81   if( err1 != "" ) std::cerr << err1 << std::endl;
82   if( err2 != "" ) std::cerr << err2 << std::endl;
83
84   return( 0 );
85 }
86
87 // eof - $RCSfile$