ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkMahalanobisDistanceMetric.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkMahalanobisDistanceMetric_h
19 #define __itkMahalanobisDistanceMetric_h
20 
21 #include "vnl/vnl_vector.h"
22 #include "vnl/vnl_vector_ref.h"
23 #include "vnl/vnl_transpose.h"
24 #include "vnl/vnl_matrix.h"
25 #include "vnl/algo/vnl_matrix_inverse.h"
26 #include "vnl/algo/vnl_determinant.h"
27 #include "itkArray.h"
28 
29 #include "itkDistanceMetric.h"
30 
31 namespace itk
32 {
33 namespace Statistics
34 {
45 template< class TVector >
46 class ITK_EXPORT MahalanobisDistanceMetric:
47  public DistanceMetric< TVector >
48 {
49 public:
55 
58  itkNewMacro(Self);
60 
62  typedef typename Superclass::MeasurementVectorType MeasurementVectorType;
63 
65  typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType;
66 
68  typedef typename Superclass::OriginType MeanVectorType;
69 
72 
74  virtual void SetMeasurementVectorSize(MeasurementVectorSizeType);
75 
77  void SetMean(const MeanVectorType & mean);
78 
80  const MeanVectorType & GetMean() const;
81 
86  void SetCovariance(const CovarianceMatrixType & cov);
87 
89  itkGetConstReferenceMacro(Covariance, CovarianceMatrixType);
90 
93  void SetInverseCovariance(const CovarianceMatrixType & invcov);
94 
96  itkGetConstReferenceMacro(InverseCovariance, CovarianceMatrixType);
97 
101  double Evaluate(const MeasurementVectorType & measurement) const;
102 
104  double Evaluate(const MeasurementVectorType & x1, const MeasurementVectorType & x2) const;
105 
107  itkSetMacro(Epsilon, double);
108  itkGetConstMacro(Epsilon, double);
110 
111  itkSetMacro(DoubleMax, double);
112  itkGetConstMacro(DoubleMax, double);
113 protected:
115  virtual ~MahalanobisDistanceMetric(void) {}
116  void PrintSelf(std::ostream & os, Indent indent) const;
117 
118 private:
120  CovarianceMatrixType m_Covariance; // covariance matrix
121 
122  // inverse covariance matrix which is automatically calculated
123  // when covariace matirx is set. This speed up the GetProbability()
125 
126  double m_Epsilon;
127  double m_DoubleMax;
128 
129  void CalculateInverseCovariance();
130 };
131 } // end of namespace Statistics
132 } // end namespace itk
133 
134 #ifndef ITK_MANUAL_INSTANTIATION
135 #include "itkMahalanobisDistanceMetric.hxx"
136 #endif
137 
138 #endif
139