1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
7 #include <itkImageFileWriter.h>
8 #include <fpa/Filters/Image/RegionGrow.h>
9 #include <fpa/Functors/RegionGrow/Tautology.h>
11 // -------------------------------------------------------------------------
12 const unsigned int Dim = 2;
13 typedef unsigned char TPixel;
14 typedef unsigned short TMark;
15 typedef itk::Image< TPixel, Dim > TImage;
17 // -------------------------------------------------------------------------
18 int main( int argc, char* argv[] )
24 << "Usage: " << argv[ 0 ]
25 << " output_image output_marks size stop [seeds]"
30 std::string output_image_filename = argv[ 1 ];
31 std::string output_marks_filename = argv[ 2 ];
32 TImage::SizeType size;
33 size.Fill( std::atoi( argv[ 3 ] ) );
34 bool stop = ( argv[ 4 ][ 0 ] == '1' );
37 TImage::Pointer image = TImage::New( );
38 image->SetRegions( size );
40 image->FillBuffer( TPixel( 0 ) );
43 typedef fpa::Functors::RegionGrow::Tautology< TPixel > TPredicate;
44 TPredicate::Pointer predicate = TPredicate::New( );
47 typedef fpa::Filters::Image::RegionGrow< TImage, TImage, TMark > TFilter;
48 TFilter::Pointer filter = TFilter::New( );
49 filter->SetInput( image );
50 filter->SetPredicate( predicate );
51 filter->SetInsideValue( std::numeric_limits< TPixel >::max( ) );
52 filter->SetOutsideValue( TPixel( 0 ) );
53 filter->SetStopAtOneFront( stop );
56 for( int i = 5; i < argc; i += Dim )
58 TImage::IndexType seed;
59 for( int j = 0; j < Dim; ++j )
61 seed[ j ] = std::atoi( argv[ i + j ] );
62 filter->AddSeed( seed );
70 typedef itk::ImageFileWriter< TFilter::TOutputImage > TOutputWriter;
71 TOutputWriter::Pointer output_writer = TOutputWriter::New( );
72 output_writer->SetInput( filter->GetOutput( ) );
73 output_writer->SetFileName( output_image_filename );
75 typedef itk::ImageFileWriter< TFilter::TMarksImage > TMarksWriter;
76 TMarksWriter::Pointer marks_writer = TMarksWriter::New( );
77 marks_writer->SetInput( filter->GetMarks( ) );
78 marks_writer->SetFileName( output_marks_filename );
82 output_writer->Update( );
83 marks_writer->Update( );
85 catch( std::exception& err )
87 std::cerr << "Error caught: " << err.what( ) << std::endl;