]> Creatis software - FrontAlgorithms.git/blob - examples/RegionGrow_Tautology.cxx
...
[FrontAlgorithms.git] / examples / RegionGrow_Tautology.cxx
1 #include <itkImage.h>
2 #include <itkImageFileWriter.h>
3
4 #include <fpa/Image/RegionGrow.h>
5 #include <fpa/Image/Functors/RegionGrow/Tautology.h>
6
7 // -------------------------------------------------------------------------
8 typedef unsigned char                  TPixel;
9 typedef itk::Image< TPixel, 2 >        TImage;
10 typedef itk::ImageFileWriter< TImage > TWriter;
11
12 typedef fpa::Image::RegionGrow< TImage, TImage > TFilter;
13 typedef fpa::Image::Functors::RegionGrow::Tautology< TPixel > TPredicate;
14
15 // -------------------------------------------------------------------------
16 int main( int argc, char* argv[] )
17 {
18   // Get arguments
19   if( argc < 6 )
20   {
21     std::cerr
22       << "Usage: " << argv[ 0 ]
23       << " output_image width height s0x s0y s1x s1y ..."
24       << std::endl;
25     return( 1 );
26
27   } // fi
28   std::string output_image_filename = argv[ 1 ];
29   TImage::SizeType size;
30   size[ 0 ] = std::atoi( argv[ 2 ] );
31   size[ 1 ] = std::atoi( argv[ 3 ] );
32
33   TImage::Pointer input = TImage::New( );
34   input->SetRegions( size );
35   input->Allocate( );
36   input->FillBuffer( 0 );
37
38   TPredicate::Pointer predicate = TPredicate::New( );
39
40   TFilter::Pointer filter = TFilter::New( );
41   filter->SetInput( input );
42   filter->SetPredicate( predicate );
43   for( int i = 4; i < argc; i += 2 )
44   {
45     if( i + 1 < argc )
46     {
47       TImage::IndexType seed;
48       seed[ 0 ] = std::atoi( argv[ i ] );
49       seed[ 1 ] = std::atoi( argv[ i + 1 ] );
50       filter->AddSeed( seed );
51
52     } // fi
53
54   } // rof
55   filter->SetInsideValue( 255 );
56   filter->SetOutsideValue( 0 );
57
58   TWriter::Pointer writer = TWriter::New( );
59   writer->SetInput( filter->GetOutput( ) );
60   writer->SetFileName( output_image_filename );
61   try
62   {
63     writer->Update( );
64   }
65   catch( std::exception& err )
66   {
67     std::cerr << "ERROR: " << err.what( ) << std::endl;
68     return( 1 );
69
70   } // yrt
71   return( 0 );
72 }
73
74 // eof - $RCSfile$