]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Algorithms/IterativeGaussianModelEstimator.h
...
[cpPlugins.git] / lib / cpExtensions / Algorithms / IterativeGaussianModelEstimator.h
1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
4
5 #ifndef __CPEXTENSIONS__ALGORITHMS__ITERATIVEGAUSSIANMODELESTIMATOR__H__
6 #define __CPEXTENSIONS__ALGORITHMS__ITERATIVEGAUSSIANMODELESTIMATOR__H__
7
8 #include <vector>
9 #include <itkConceptChecking.h>
10 #include <itkObject.h>
11 #include <itkObjectFactory.h>
12
13 #include <itkCovariantVector.h>
14 #include <itkMatrix.h>
15 #include <itkPoint.h>
16 #include <itkVector.h>
17
18 namespace cpExtensions
19 {
20   namespace Algorithms
21   {
22     /**
23      * Recursive formulation taken from:
24      * http://lmb.informatik.uni-freiburg.de/lectures/mustererkennung/Englische_Folien/07_c_ME_en.pdf
25      */
26     template< class _TScalar, unsigned int _VDimension >
27     class IterativeGaussianModelEstimator
28       : public itk::Object
29     {
30     public:
31       typedef IterativeGaussianModelEstimator Self;
32       typedef itk::Object                     Superclass;
33       typedef itk::SmartPointer< Self >       Pointer;
34       typedef itk::SmartPointer< const Self > ConstPointer;
35
36       typedef _TScalar TScalar;
37       itkStaticConstMacro( Dimension, unsigned int, _VDimension );
38
39       // Begin concept checking
40 #ifdef ITK_USE_CONCEPT_CHECKING
41       itkConceptMacro(
42         ScalarTypeHasFloatResolution,
43         ( itk::Concept::IsFloatingPoint< _TScalar > )
44         );
45 #endif
46       // End concept checking
47
48       typedef itk::Matrix< TScalar, Dimension, Dimension > TMatrix;
49       typedef itk::Vector< TScalar, Dimension > TVector;
50
51     public:
52       itkNewMacro( Self );
53       itkTypeMacro( IterativeGaussianModelEstimator, itkObject );
54
55       itkGetConstMacro( Mean, TVector );
56       itkGetConstMacro( Covariance, TMatrix );
57       itkGetConstMacro( UnbiasedCovariance, TMatrix );
58       itkGetConstMacro( NumberOfSamples, unsigned long );
59
60       itkSetMacro( Mean, TVector );
61       itkSetMacro( Covariance, TMatrix );
62       itkSetMacro( NumberOfSamples, unsigned long );
63
64     public:
65       void Clear( );
66
67       template< class _TOtherScalar >
68       void AddSample( const _TOtherScalar& x1, ... );
69
70       template< class _TOtherScalar >
71       void AddSample( const _TOtherScalar* array );
72
73       template< class _TOtherScalar >
74       void AddSample( const vnl_vector< _TOtherScalar >& v );
75
76       template< class _TOtherScalar >
77       void AddSample(
78         const itk::CovariantVector< _TOtherScalar, _VDimension >& v
79         );
80
81       template< class _TOtherScalar >
82       void AddSample( const itk::Point< _TOtherScalar, _VDimension >& p );
83
84       template< class _TOtherScalar >
85       void AddSample( const itk::Vector< _TOtherScalar, _VDimension >& v );
86
87       template< class _TOtherScalar >
88       _TScalar SquaredMahalanobis( const _TOtherScalar& x1, ... ) const;
89
90       template< class _TOtherScalar >
91       _TScalar SquaredMahalanobis( const _TOtherScalar* array ) const;
92
93       template< class _TOtherScalar >
94       _TScalar SquaredMahalanobis(
95         const vnl_vector< _TOtherScalar >& v
96         ) const;
97
98       template< class _TOtherScalar >
99       _TScalar SquaredMahalanobis(
100         const itk::CovariantVector< _TOtherScalar, _VDimension >& v
101         ) const;
102
103       template< class _TOtherScalar >
104       _TScalar SquaredMahalanobis(
105         const itk::Point< _TOtherScalar, _VDimension >& p
106         ) const;
107
108       template< class _TOtherScalar >
109       _TScalar SquaredMahalanobis(
110         const itk::Vector< _TOtherScalar, _VDimension >& v
111         ) const;
112
113     protected:
114       IterativeGaussianModelEstimator( );
115       virtual ~IterativeGaussianModelEstimator( );
116
117     protected:
118       void _AddSample( const TVector& v ) const;
119       _TScalar _SquaredMahalanobis( const TVector& v ) const;
120
121     private:
122       // Purposely not implemented
123       IterativeGaussianModelEstimator( const Self& other );
124       void operator=( const Self& other );
125
126     protected:
127       // Recursive avg/cov values
128       mutable unsigned long m_NumberOfSamples;
129       mutable TVector m_Mean;
130       mutable TMatrix m_Covariance;
131       mutable TMatrix m_UnbiasedCovariance;
132       mutable bool m_InverseUpdated;
133       mutable TMatrix m_InverseUnbiasedCovariance;
134     };
135
136   } // ecapseman
137
138 } // ecapseman
139
140 #ifndef ITK_MANUAL_INSTANTIATION
141 #include <cpExtensions/Algorithms/IterativeGaussianModelEstimator.hxx>
142 #endif // ITK_MANUAL_INSTANTIATION
143
144 #endif // __CPEXTENSIONS__ALGORITHMS__ITERATIVEGAUSSIANMODELESTIMATOR__H__
145
146 // eof - $RCSfile$