]> Creatis software - FrontAlgorithms.git/blob - tests/image/MoriSegmentation.cxx
e02b359edc6231e1b6cfccc91671add0c3940988
[FrontAlgorithms.git] / tests / image / MoriSegmentation.cxx
1 #include "BaseFunctions.h"
2 #include <itkImage.h>
3 #include <fpa/Image/Mori.h>
4
5 // -------------------------------------------------------------------------
6 const unsigned int Dim = 2;
7 typedef unsigned char TPixel;
8
9 typedef itk::Image< TPixel, Dim >          TImage;
10 typedef fpa::Image::Mori< TImage, TImage > TFilter;
11
12 // -------------------------------------------------------------------------
13 int main( int argc, char* argv[] )
14 {
15   // Get arguments
16   if( argc < 9 )
17   {
18     std::cerr
19       << "Usage: " << argv[ 0 ]
20       << " input_image output_image output_levels"
21       << " init_threshold end_threshold number_of_threshold seed_x seed_y"
22       << std::endl;
23     return( 1 );
24
25   } // fi
26   std::string input_image_filename = argv[ 1 ];
27   std::string output_image_filename = argv[ 2 ];
28   std::string output_levels_filename = argv[ 3 ];
29   unsigned char init_threshold = std::atoi( argv[ 4 ] );
30   unsigned char end_threshold = std::atoi( argv[ 5 ] );
31   unsigned char number_of_thresholds = std::atoi( argv[ 6 ] );
32   TImage::IndexType seed;
33   seed[ 0 ] = std::atoi( argv[ 7 ] );
34   seed[ 1 ] = std::atoi( argv[ 8 ] );
35
36   // Create image
37   TImage::Pointer input_image;
38   std::string err0 =
39     fpa::tests::image::Read( input_image, input_image_filename );
40   if( err0 != "" ) std::cerr << err0 << std::endl;
41
42   // Prepare filter
43   TFilter::Pointer filter = TFilter::New( );
44   filter->SetInput( input_image );
45   filter->SetSeed( seed );
46   filter->SetThresholds( init_threshold, end_threshold, number_of_thresholds );
47   filter->SetInsideValue( 255 );
48   filter->SetOutsideValue( 0 );
49
50   // Execute filter
51   filter->Update( );
52
53   // Save results
54   std::string err1 =
55     fpa::tests::image::Write( filter->GetOutput( ), output_image_filename );
56   std::string err2 =
57     fpa::tests::image::Write( filter->GetOutputLevels( ), output_levels_filename );
58   if( err1 != "" ) std::cerr << err1 << std::endl;
59   if( err2 != "" ) std::cerr << err2 << std::endl;
60
61   return( 0 );
62 }
63
64 // eof - $RCSfile$