]> Creatis software - FrontAlgorithms.git/blob - tests/image/RegionGrow_BinaryThreshold.cxx
...
[FrontAlgorithms.git] / tests / image / RegionGrow_BinaryThreshold.cxx
1 #include "BaseFunctions.h"
2 #include <itkImage.h>
3 #include <fpa/Image/RegionGrow.h>
4 #include <fpa/Base/Functors/RegionGrow/BinaryThreshold.h>
5
6 // -------------------------------------------------------------------------
7 const unsigned int Dim = 3;
8 typedef short         TInputPixel;
9 typedef unsigned char TOutputPixel;
10
11 typedef itk::Image< TInputPixel, Dim >                      TInputImage;
12 typedef itk::Image< TOutputPixel, Dim >                     TOutputImage;
13 typedef fpa::Image::RegionGrow< TInputImage, TOutputImage > TFilter;
14 typedef fpa::Base::Functors::RegionGrow::BinaryThreshold< TInputPixel > TPredicate;
15
16 // -------------------------------------------------------------------------
17 int main( int argc, char* argv[] )
18 {
19   // Get arguments
20   if( argc < 8 + Dim )
21   {
22     std::cerr
23       << "Usage: " << argv[ 0 ]
24       << " input_image output_image output_marks"
25       << " lower upper strict [index/point] ..."
26       << std::endl;
27     return( 1 );
28
29   } // fi
30   std::string input_image_filename = argv[ 1 ];
31   std::string output_image_filename = argv[ 2 ];
32   std::string output_marks_filename = argv[ 3 ];
33   TInputPixel lower = TInputPixel( std::atof( argv[ 4 ] ) );
34   TInputPixel upper = TInputPixel( std::atof( argv[ 5 ] ) );
35   bool strict = ( argv[ 6 ][ 0 ] == '1' );
36   std::string seeds_type = argv[ 7 ];
37
38   // Create image
39   TInputImage::Pointer input_image;
40   std::string err0 =
41     fpa::tests::image::Read( input_image, input_image_filename );
42   if( err0 != "" ) std::cerr << err0 << std::endl;
43
44   // Prepare predicate
45   TPredicate::Pointer predicate = TPredicate::New( );
46   predicate->SetLower( lower );
47   predicate->SetUpper( upper );
48   predicate->SetStrict( strict );
49
50   // Prepare filter
51   TFilter::Pointer filter = TFilter::New( );
52   filter->SetInput( input_image );
53   filter->SetPredicate( predicate );
54   filter->SetInsideValue( 255 );
55   filter->SetOutsideValue( 0 );
56
57   // Get all seeds
58   for( int i = 8; i < argc; i += Dim )
59   {
60     if( seeds_type == "index" )
61     {
62       TInputImage::IndexType seed;
63       for( unsigned int d = 0; d < Dim; ++d )
64         seed[ d ] = std::atoi( argv[ i + d ] );
65       filter->AddSeed( seed );
66     }
67     else
68     {
69       TInputImage::PointType seed;
70       for( unsigned int d = 0; d < Dim; ++d )
71         seed[ d ] = std::atof( argv[ i + d ] );
72       filter->AddSeed( seed );
73
74     } // fi
75   } // rof
76
77   // Execute filter
78   filter->Update( );
79
80   // Save results
81   std::string err1 =
82     fpa::tests::image::Write( filter->GetOutput( ), output_image_filename );
83   std::string err2 =
84     fpa::tests::image::Write( filter->GetMarks( ), output_marks_filename );
85   if( err1 != "" ) std::cerr << err1 << std::endl;
86   if( err2 != "" ) std::cerr << err2 << std::endl;
87
88   return( 0 );
89 }
90
91 // eof - $RCSfile$