6 #include <itkImageFileReader.h>
7 #include <itkImageRegionConstIterator.h>
9 #include <itkRGBPixel.h>
10 #include <itkVector.h>
12 #include <cpPlugins/Extensions/Algorithms/IterativeGaussianModelEstimator.h>
14 // -------------------------------------------------------------------------
15 const unsigned int Dim = 2;
16 typedef double TScalar;
17 typedef unsigned char TChannel;
18 typedef itk::RGBPixel< TChannel > TPixel;
19 typedef itk::Image< TPixel, Dim > TImage;
21 // -------------------------------------------------------------------------
22 int main( int argc, char* argv[] )
27 << "Usage: " << argv[ 0 ]
28 << " input_image" << std::endl;
32 std::string input_image_file = argv[ 1 ];
35 itk::ImageFileReader< TImage >::Pointer reader =
36 itk::ImageFileReader< TImage >::New( );
37 reader->SetFileName( input_image_file );
42 catch( itk::ExceptionObject& err )
44 std::cerr << "Error caught: " << err << std::endl;
48 TImage::ConstPointer input_image = reader->GetOutput( );
50 // Compute gaussian model
51 typedef cpPlugins::Extensions::Algorithms::IterativeGaussianModelEstimator< TScalar, 3 > TEstimator;
53 TEstimator::Pointer estimator = TEstimator::New( );
56 itk::ImageRegionConstIterator< TImage > it(
58 input_image->GetRequestedRegion( )
60 for( it.GoToBegin( ); !it.IsAtEnd( ); ++it )
63 TScalar( it.Get( ).GetRed( ) ),
64 TScalar( it.Get( ).GetGreen( ) ),
65 TScalar( it.Get( ).GetBlue( ) )
70 itk::Vector< TScalar, 3 > mean;
71 itk::Matrix< TScalar, 3, 3 > cova;
73 estimator->GetModel( mean, cova );
75 << "Covariance = " << std::endl << cova << std::endl;
77 << "Inverse covariance = "
78 << std::endl << cova.GetInverse( ) << std::endl;
80 << "Mean = " << std::endl << mean << std::endl;