ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkMahalanobisDistanceMetric.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkMahalanobisDistanceMetric_h
00019 #define __itkMahalanobisDistanceMetric_h
00020 
00021 #include "vnl/vnl_vector.h"
00022 #include "vnl/vnl_vector_ref.h"
00023 #include "vnl/vnl_transpose.h"
00024 #include "vnl/vnl_matrix.h"
00025 #include "vnl/algo/vnl_matrix_inverse.h"
00026 #include "vnl/algo/vnl_determinant.h"
00027 #include "itkArray.h"
00028 
00029 #include "itkDistanceMetric.h"
00030 
00031 namespace itk
00032 {
00033 namespace Statistics
00034 {
00045 template< class TVector >
00046 class ITK_EXPORT MahalanobisDistanceMetric:
00047   public DistanceMetric< TVector >
00048 {
00049 public:
00051   typedef MahalanobisDistanceMetric  Self;
00052   typedef DistanceMetric< TVector >  Superclass;
00053   typedef SmartPointer< Self >       Pointer;
00054   typedef SmartPointer< const Self > ConstPointer;
00055 
00057   itkTypeMacro(MahalanobisDistanceMetric, DistanceMetric);
00058   itkNewMacro(Self);
00060 
00062   typedef typename Superclass::MeasurementVectorType MeasurementVectorType;
00063 
00065   typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType;
00066 
00068   typedef typename Superclass::OriginType MeanVectorType;
00069 
00071   typedef vnl_matrix< double > CovarianceMatrixType;
00072 
00074   virtual void SetMeasurementVectorSize(MeasurementVectorSizeType);
00075 
00077   void SetMean(const MeanVectorType & mean);
00078 
00080   const MeanVectorType & GetMean() const;
00081 
00086   void SetCovariance(const CovarianceMatrixType & cov);
00087 
00089   itkGetConstReferenceMacro(Covariance, CovarianceMatrixType);
00090 
00093   void SetInverseCovariance(const CovarianceMatrixType & invcov);
00094 
00096   itkGetConstReferenceMacro(InverseCovariance, CovarianceMatrixType);
00097 
00101   double Evaluate(const MeasurementVectorType & measurement) const;
00102 
00104   double Evaluate(const MeasurementVectorType & x1, const MeasurementVectorType & x2) const;
00105 
00107   itkSetMacro(Epsilon, double);
00108   itkGetConstMacro(Epsilon, double);
00110 
00111   itkSetMacro(DoubleMax, double);
00112   itkGetConstMacro(DoubleMax, double);
00113 protected:
00114   MahalanobisDistanceMetric(void);
00115   virtual ~MahalanobisDistanceMetric(void) {}
00116   void PrintSelf(std::ostream & os, Indent indent) const;
00117 
00118 private:
00119   MeanVectorType       m_Mean;               // mean
00120   CovarianceMatrixType m_Covariance;         // covariance matrix
00121 
00122   // inverse covariance matrix which is automatically calculated
00123   // when covariace matirx is set.  This speed up the GetProbability()
00124   CovarianceMatrixType m_InverseCovariance;
00125 
00126   double m_Epsilon;
00127   double m_DoubleMax;
00128 
00129   void CalculateInverseCovariance();
00130 };
00131 } // end of namespace Statistics
00132 } // end namespace itk
00133 
00134 #ifndef ITK_MANUAL_INSTANTIATION
00135 #include "itkMahalanobisDistanceMetric.hxx"
00136 #endif
00137 
00138 #endif
00139