1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
7 #include <itkImageFileReader.h>
8 #include <itkImageFileWriter.h>
9 #include <fpa/Filters/Image/RandomWalker.h>
10 #include <fpa/Functors/Dijkstra/Image/Gaussian.h>
12 // -------------------------------------------------------------------------
13 const unsigned int Dim = 2;
14 typedef unsigned char TInputPixel;
15 typedef unsigned char TInputLabel;
16 typedef float TOutputPixel;
17 typedef itk::Image< TInputPixel, Dim > TInputImage;
18 typedef itk::Image< TInputLabel, Dim > TInputLabelImage;
19 typedef itk::Image< TOutputPixel, Dim > TOutputImage;
21 // -------------------------------------------------------------------------
22 int main( int argc, char* argv[] )
28 << "Usage: " << argv[ 0 ]
29 << " input_image input_labels output_image output_costs alpha beta"
34 std::string input_image_filename = argv[ 1 ];
35 std::string input_labels_filename = argv[ 2 ];
36 std::string output_image_filename = argv[ 3 ];
37 std::string output_costs_filename = argv[ 4 ];
38 double alpha = std::atof( argv[ 5 ] );
39 double beta = std::atof( argv[ 6 ] );
42 typedef itk::ImageFileReader< TInputImage > TInputImageReader;
43 TInputImageReader::Pointer input_image_reader = TInputImageReader::New( );
44 input_image_reader->SetFileName( input_image_filename );
47 typedef itk::ImageFileReader< TInputLabelImage > TInputLabelImageReader;
48 TInputLabelImageReader::Pointer input_labels_reader =
49 TInputLabelImageReader::New( );
50 input_labels_reader->SetFileName( input_labels_filename );
52 // Prepare weight functor
53 typedef fpa::Functors::Dijkstra::Image::Gaussian< TInputImage, TOutputPixel > TWeight;
54 TWeight::Pointer weight = TWeight::New( );
55 weight->SetAlpha( alpha );
56 weight->SetBeta( beta );
59 typedef fpa::Filters::Image::RandomWalker< TInputImage, TInputLabelImage, TOutputImage > TFilter;
60 TFilter::Pointer filter = TFilter::New( );
61 filter->SetInputImage( input_image_reader->GetOutput( ) );
62 filter->SetInputLabels( input_labels_reader->GetOutput( ) );
63 filter->SetWeightFunction( weight );
69 typedef itk::ImageFileWriter< TFilter::TOutputLabels > TOutputWriter;
70 TOutputWriter::Pointer output_writer = TOutputWriter::New( );
71 output_writer->SetInput( filter->GetOutputLabels( ) );
72 output_writer->SetFileName( output_image_filename );
74 typedef itk::ImageFileWriter< TFilter::TCostsImage > TCostsWriter;
75 TCostsWriter::Pointer costs_writer = TCostsWriter::New( );
76 costs_writer->SetInput( filter->GetOutputCosts( ) );
77 costs_writer->SetFileName( output_costs_filename );
81 output_writer->Update( );
82 costs_writer->Update( );
84 catch( std::exception& err )
86 std::cerr << "Error caught: " << err.what( ) << std::endl;