00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkMahalanobisDistanceMembershipFunction_h
00018 #define __itkMahalanobisDistanceMembershipFunction_h
00019
00020 #include <vnl/vnl_vector.h>
00021 #include <vnl/vnl_vector_ref.h>
00022 #include <vnl/vnl_transpose.h>
00023 #include <vnl/vnl_matrix.h>
00024 #include <vnl/algo/vnl_matrix_inverse.h>
00025 #include <vnl/algo/vnl_determinant.h>
00026 #include "itkArray.h"
00027
00028 #include "itkMembershipFunctionBase.h"
00029
00030
00031 namespace itk{
00032 namespace Statistics{
00033
00043 template< class TVector >
00044 class ITK_EXPORT MahalanobisDistanceMembershipFunction :
00045 public MembershipFunctionBase< TVector >
00046 {
00047 public:
00049 typedef MahalanobisDistanceMembershipFunction Self;
00050 typedef MembershipFunctionBase< TVector > Superclass ;
00051 typedef SmartPointer<Self> Pointer;
00052 typedef SmartPointer<const Self> ConstPointer;
00053
00055 itkTypeMacro(MahalanobisDistanceMembershipFunction, MembershipFunctionBase);
00056 itkNewMacro(Self);
00058
00060 typedef TVector MeasurementVectorType ;
00061
00063 typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType;
00064
00066 typedef vnl_vector<double> MeanVectorType;
00067
00069 typedef vnl_matrix<double> CovarianceMatrixType;
00070
00072 virtual void SetMeasurementVectorSize( const MeasurementVectorSizeType );
00073
00075 void SetMean(const MeanVectorType &mean) ;
00076 void SetMean(const Array< double > &mean) ;
00078
00080 const MeanVectorType & GetMean() const;
00081
00086 void SetCovariance(const CovarianceMatrixType &cov);
00087
00089 itkGetConstReferenceMacro( Covariance, CovarianceMatrixType );
00090
00095 void SetInverseCovariance(const CovarianceMatrixType &invcov);
00096
00098 itkGetConstReferenceMacro( InverseCovariance, CovarianceMatrixType );
00099
00101 itkSetMacro( NumberOfSamples, double );
00102
00104 itkGetMacro( NumberOfSamples, double );
00105
00109 double Evaluate(const MeasurementVectorType &measurement) const;
00110
00111 protected:
00112 MahalanobisDistanceMembershipFunction(void) ;
00113 virtual ~MahalanobisDistanceMembershipFunction(void) {}
00114 void PrintSelf(std::ostream& os, Indent indent) const;
00115
00116 private:
00117 MeanVectorType m_Mean;
00118 CovarianceMatrixType m_Covariance;
00119
00120
00121
00122 CovarianceMatrixType m_InverseCovariance;
00123
00124
00125 double m_NumberOfSamples;
00126
00127
00128 double m_PreFactor;
00129 double m_Epsilon;
00130 double m_DoubleMax;
00131
00132 mutable vnl_matrix< double > m_TempVec;
00133 mutable vnl_matrix< double > m_TempMat;
00134
00135 void CalculateInverseCovariance();
00136 };
00137
00138 }
00139 }
00140
00141 #ifndef ITK_MANUAL_INSTANTIATION
00142 #include "itkMahalanobisDistanceMembershipFunction.txx"
00143 #endif
00144
00145 #endif
00146