ITK  4.6.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< typename TVector >
47  public DistanceMetric< TVector >
48 {
49 public:
55 
58  itkNewMacro(Self);
60 
63 
66 
69 
71  typedef vnl_matrix< double > CovarianceMatrixType;
72 
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 
114 protected:
116  virtual ~MahalanobisDistanceMetric(void) {}
117  void PrintSelf(std::ostream & os, Indent indent) const;
118 
119 private:
121  CovarianceMatrixType m_Covariance; // covariance matrix
122 
123  // inverse covariance matrix which is automatically calculated
124  // when covariace matirx is set. This speed up the GetProbability()
126 
127  double m_Epsilon;
128  double m_DoubleMax;
129 
131 };
132 } // end of namespace Statistics
133 } // end namespace itk
134 
135 #ifndef ITK_MANUAL_INSTANTIATION
136 #include "itkMahalanobisDistanceMetric.hxx"
137 #endif
138 
139 #endif
Light weight base class for most itk classes.
Superclass::MeasurementVectorType MeasurementVectorType
virtual void SetMeasurementVectorSize(MeasurementVectorSizeType)
void SetCovariance(const CovarianceMatrixType &cov)
this class declares common interfaces for distance functions.
const MeanVectorType & GetMean() const
void PrintSelf(std::ostream &os, Indent indent) const
double Evaluate(const MeasurementVectorType &measurement) const
void SetInverseCovariance(const CovarianceMatrixType &invcov)
void SetMean(const MeanVectorType &mean)
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Superclass::MeasurementVectorSizeType MeasurementVectorSizeType
MahalanobisDistanceMetric class computes a Mahalanobis distance given a mean and covariance.