3 #include <itkImageFileReader.h>
4 #include <itkImageFileWriter.h>
6 #include <fpa/Image/RandomWalker.h>
7 #include <fpa/Image/Functors/Dijkstra/Gaussian.h>
9 // -------------------------------------------------------------------------
10 const unsigned int Dim = 3;
12 typedef unsigned short TLabel;
13 typedef double TScalar;
15 typedef itk::Image< TPixel, Dim > TInputImage;
16 typedef itk::Image< TLabel, Dim > TLabelImage;
18 typedef fpa::Image::RandomWalker< TInputImage, TLabelImage, TScalar > TFilter;
19 typedef fpa::Image::Functors::Dijkstra::Gaussian< TInputImage, TScalar > TWeight;
21 // -------------------------------------------------------------------------
22 int main( int argc, char* argv[] )
28 << "Usage: " << argv[ 0 ] << std::endl
29 << " input_image label_image output_image" << std::endl
30 << " alpha(0) beta(100)"
35 std::string input_image_filename = argv[ 1 ];
36 std::string label_image_filename = argv[ 2 ];
37 std::string output_image_filename = argv[ 3 ];
38 double alpha = std::atof( argv[ 4 ] );
39 double beta = std::atof( argv[ 5 ] );
42 itk::ImageFileReader< TInputImage >::Pointer input_image_reader =
43 itk::ImageFileReader< TInputImage >::New( );
44 input_image_reader->SetFileName( input_image_filename );
46 itk::ImageFileReader< TLabelImage >::Pointer label_image_reader =
47 itk::ImageFileReader< TLabelImage >::New( );
48 label_image_reader->SetFileName( label_image_filename );
51 TWeight::Pointer weight = TWeight::New( );
52 weight->SetAlpha( alpha );
53 weight->SetBeta( beta );
56 TFilter::Pointer filter = TFilter::New( );
57 filter->SetInput( input_image_reader->GetOutput( ) );
58 filter->SetLabels( label_image_reader->GetOutput( ) );
59 filter->SetWeightFunction( weight );
61 // Show some information
62 std::cout << "----------------------------------------------" << std::endl;
63 std::cout << "Image: " << input_image_filename << std::endl;
66 std::chrono::time_point< std::chrono::high_resolution_clock > ts, te;
67 std::chrono::duration< double > tr;
70 ts = std::chrono::high_resolution_clock::now( );
71 input_image_reader->Update( );
72 te = std::chrono::high_resolution_clock::now( );
74 std::cout << "Raw read time: " << tr.count( ) << " s" << std::endl;
76 ts = std::chrono::high_resolution_clock::now( );
77 label_image_reader->Update( );
78 te = std::chrono::high_resolution_clock::now( );
80 std::cout << "Label read time: " << tr.count( ) << " s" << std::endl;
82 ts = std::chrono::high_resolution_clock::now( );
84 te = std::chrono::high_resolution_clock::now( );
87 << "Labelling time: " << tr.count( ) << " s" << std::endl;
89 catch( std::exception& err )
91 std::cerr << "Error caught: " << err.what( ) << std::endl;
97 itk::ImageFileWriter< TLabelImage >::Pointer output_image_writer =
98 itk::ImageFileWriter< TLabelImage >::New( );
99 output_image_writer->SetInput( filter->GetMarks( ) );
100 output_image_writer->SetFileName( output_image_filename );
103 ts = std::chrono::high_resolution_clock::now( );
104 output_image_writer->Update( );
105 te = std::chrono::high_resolution_clock::now( );
107 std::cout << "Write time: " << tr.count( ) << " s" << std::endl;
109 catch( std::exception& err )
111 std::cerr << "Error caught: " << err.what( ) << std::endl;
115 std::cout << "----------------------------------------------" << std::endl;