]> Creatis software - cpPlugins.git/blob - appli/examples/example_ParallelImageMean.cxx
...
[cpPlugins.git] / appli / examples / example_ParallelImageMean.cxx
1 #include <cstdlib>
2 #include <iostream>
3 #include <string>
4
5 #include <itkImage.h>
6 #include <itkImageFileReader.h>
7 #include <itkRGBPixel.h>
8
9 #include <cpPlugins/Extensions/Algorithms/ParallelImageMean.h>
10
11 // -------------------------------------------------------------------------
12 const unsigned int Dim = 2;
13 typedef itk::RGBPixel< unsigned char > TPixel;
14 typedef itk::Image< TPixel, Dim >      TImage;
15
16 // -------------------------------------------------------------------------
17 int main( int argc, char* argv[] )
18 {
19   if( argc < 2 )
20   {
21     std::cerr << "Usage: " << argv[ 0 ] << " image" << std::endl;
22     return( 1 );
23
24   } // fi
25   std::string image_fn = argv[ 1 ];
26
27   // Read image
28   itk::ImageFileReader< TImage >::Pointer image_reader =
29     itk::ImageFileReader< TImage >::New( );
30   image_reader->SetFileName( image_fn );
31   try
32   {
33     image_reader->Update( );
34   }
35   catch( itk::ExceptionObject& err )
36   {
37     std::cerr << "Error caught: " << err << std::endl;
38     return( 1 );
39
40   } // yrt
41   TImage::Pointer image = image_reader->GetOutput( );
42
43   // Compute mean
44   cpPlugins::Extensions::Algorithms::ParallelImageMean< TImage >::Pointer mean =
45     cpPlugins::Extensions::Algorithms::ParallelImageMean< TImage >::New( );
46   mean->Execute( image, image->GetRequestedRegion( ) );
47   std::cout << "Mean: " << mean->GetMean( ) << std::endl;
48
49   return( 0 );
50 }
51
52 // eof - $RCSfile$