1 #include "BaseFunctions.h"
3 #include <fpa/Image/RandomWalker.h>
4 #include <fpa/Image/Functors/Dijkstra/Gaussian.h>
6 // -------------------------------------------------------------------------
7 const unsigned int Dim = 2;
9 typedef unsigned char TLabel;
10 typedef float TScalar;
12 typedef itk::Image< TPixel, Dim > TInputImage;
13 typedef itk::Image< TLabel, Dim > TLabelImage;
14 typedef fpa::Image::RandomWalker< TInputImage, TLabelImage, TScalar > TFilter;
15 typedef fpa::Image::Functors::Dijkstra::Gaussian< TInputImage, TScalar > TWeight;
17 // -------------------------------------------------------------------------
18 int main( int argc, char* argv[] )
24 << "Usage: " << argv[ 0 ]
25 << " input_image [labels_image] output_image output_costs"
26 << " alpha beta visual_debug"
31 int idx = ( argc == 7 )? 2: 3;
32 std::string input_image_filename = argv[ 1 ];
33 std::string labels_image_filename = ( argc == 8 )? argv[ 2 ]: "";
34 std::string output_image_filename = argv[ idx ];
35 std::string output_costs_filename = argv[ idx + 1 ];
36 double alpha = std::atof( argv[ idx + 2 ] );
37 double beta = std::atof( argv[ idx + 3 ] );
38 bool visual_debug = ( argv[ idx + 4 ][ 0 ] == '1' );
41 TInputImage::Pointer image;
42 std::string err0 = fpa::tests::image::Read( image, input_image_filename );
45 std::cerr << "Error caught: " << err0 << std::endl;
51 TLabelImage::Pointer labels;
52 if( labels_image_filename != "" )
54 std::string err1 = fpa::tests::image::Read( labels, labels_image_filename );
57 std::cerr << "Error caught: " << err1 << std::endl;
64 // Interact with image
65 fpa::tests::image::Viewer< TFilter > viewer( image );
68 if( labels.IsNull( ) )
69 viewer.ActivateBrushWidget( );
75 TWeight::Pointer weight = TWeight::New( );
76 weight->SetAlpha( alpha );
77 weight->SetBeta( beta );
80 TFilter::Pointer filter = TFilter::New( );
81 filter->SetInput( image );
82 filter->SetWeightFunction( weight );
83 if( labels.IsNull( ) )
84 viewer.AssociateLabelsTo( filter );
86 filter->SetLabels( labels );
88 // Prepare visual debug and update
90 viewer.ObserveFilter( filter );
95 catch( std::exception& err )
97 std::cerr << "Error caught: " << err.what( ) << std::endl;
104 fpa::tests::image::Write( filter->GetMarks( ), output_image_filename );
106 fpa::tests::image::Write( filter->GetOutput( ), output_costs_filename );
107 if( err1 != "" ) std::cerr << "Error caught: " << err1 << std::endl;
108 if( err2 != "" ) std::cerr << "Error caught: " << err2 << std::endl;