1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
5 #ifndef __CPEXTENSIONS__ALGORITHMS__ITERATIVEGAUSSIANMODELESTIMATOR__H__
6 #define __CPEXTENSIONS__ALGORITHMS__ITERATIVEGAUSSIANMODELESTIMATOR__H__
9 #include <itkConceptChecking.h>
10 #include <itkObject.h>
11 #include <itkObjectFactory.h>
13 #include <itkCovariantVector.h>
14 #include <itkMatrix.h>
16 #include <itkVector.h>
18 namespace cpExtensions
23 * Recursive formulation taken from:
24 * http://lmb.informatik.uni-freiburg.de/lectures/mustererkennung/Englische_Folien/07_c_ME_en.pdf
26 template< class _TScalar, unsigned int _VDimension >
27 class IterativeGaussianModelEstimator
31 typedef IterativeGaussianModelEstimator Self;
32 typedef itk::Object Superclass;
33 typedef itk::SmartPointer< Self > Pointer;
34 typedef itk::SmartPointer< const Self > ConstPointer;
36 typedef _TScalar TScalar;
37 itkStaticConstMacro( Dimension, unsigned int, _VDimension );
39 // Begin concept checking
40 #ifdef ITK_USE_CONCEPT_CHECKING
42 ScalarTypeHasFloatResolution,
43 ( itk::Concept::IsFloatingPoint< _TScalar > )
46 // End concept checking
48 typedef itk::Matrix< TScalar, Dimension, Dimension > TMatrix;
49 typedef itk::Vector< TScalar, Dimension > TVector;
53 itkTypeMacro( IterativeGaussianModelEstimator, itkObject );
55 itkGetConstMacro( Mean, TVector );
56 itkGetConstMacro( Covariance, TMatrix );
57 itkGetConstMacro( UnbiasedCovariance, TMatrix );
58 itkGetConstMacro( NumberOfSamples, unsigned long );
60 itkSetMacro( Mean, TVector );
61 itkSetMacro( Covariance, TMatrix );
62 itkSetMacro( NumberOfSamples, unsigned long );
67 template< class _TOtherScalar >
68 void AddSample( const _TOtherScalar& x1, ... );
70 template< class _TOtherScalar >
71 void AddSample( const _TOtherScalar* array );
73 template< class _TOtherScalar >
74 void AddSample( const vnl_vector< _TOtherScalar >& v );
76 template< class _TOtherScalar >
78 const itk::CovariantVector< _TOtherScalar, _VDimension >& v
81 template< class _TOtherScalar >
82 void AddSample( const itk::Point< _TOtherScalar, _VDimension >& p );
84 template< class _TOtherScalar >
85 void AddSample( const itk::Vector< _TOtherScalar, _VDimension >& v );
87 template< class _TOtherScalar >
88 _TScalar SquaredMahalanobis( const _TOtherScalar& x1, ... ) const;
90 template< class _TOtherScalar >
91 _TScalar SquaredMahalanobis( const _TOtherScalar* array ) const;
93 template< class _TOtherScalar >
94 _TScalar SquaredMahalanobis(
95 const vnl_vector< _TOtherScalar >& v
98 template< class _TOtherScalar >
99 _TScalar SquaredMahalanobis(
100 const itk::CovariantVector< _TOtherScalar, _VDimension >& v
103 template< class _TOtherScalar >
104 _TScalar SquaredMahalanobis(
105 const itk::Point< _TOtherScalar, _VDimension >& p
108 template< class _TOtherScalar >
109 _TScalar SquaredMahalanobis(
110 const itk::Vector< _TOtherScalar, _VDimension >& v
114 IterativeGaussianModelEstimator( );
115 virtual ~IterativeGaussianModelEstimator( );
118 void _AddSample( const TVector& v ) const;
119 _TScalar _SquaredMahalanobis( const TVector& v ) const;
122 // Purposely not implemented
123 IterativeGaussianModelEstimator( const Self& other );
124 void operator=( const Self& other );
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;
140 #ifndef ITK_MANUAL_INSTANTIATION
141 #include <cpExtensions/Algorithms/IterativeGaussianModelEstimator.hxx>
142 #endif // ITK_MANUAL_INSTANTIATION
144 #endif // __CPEXTENSIONS__ALGORITHMS__ITERATIVEGAUSSIANMODELESTIMATOR__H__