00001 /*========================================================================= 00002 00003 Library : Image Registration Toolkit (IRTK) 00004 Module : $Id: irtkMLSimilarityMetric.h 2 2008-12-23 12:40:14Z dr $ 00005 Copyright : Imperial College, Department of Computing 00006 Visual Information Processing (VIP), 2008 onwards 00007 Date : $Date: 2008-12-23 12:40:14 +0000 (Tue, 23 Dec 2008) $ 00008 Version : $Revision: 2 $ 00009 Changes : $Author: dr $ 00010 00011 =========================================================================*/ 00012 00013 #ifndef _IRTKMLSIMILARITYMETRIC_H 00014 00015 #define _IRTKMLSIMILARITYMETRIC_H 00016 00017 #include <irtkEMClassificationTemplateBiasCorrection.h> 00018 00024 class irtkMLSimilarityMetric : public irtkSimilarityMetric 00025 { 00026 00027 private: 00028 00030 double _ll; 00032 int _n; 00033 00034 public: 00036 irtkEMClassification *_classification; 00037 00038 00039 public: 00040 00042 irtkMLSimilarityMetric(irtkEMClassification *); 00043 00045 virtual void Add(int, int); 00046 00048 virtual void Delete(int, int); 00049 00051 virtual void Combine(irtkSimilarityMetric *); 00052 00054 virtual void Reset(); 00055 00057 virtual void Reset(irtkSimilarityMetric *); 00058 00060 virtual double Evaluate(); 00061 00062 }; 00063 00064 inline irtkMLSimilarityMetric::irtkMLSimilarityMetric(irtkEMClassification *classification) 00065 { 00066 _ll = 0; 00067 _n=0; 00068 cerr<<"member"; 00069 _classification=classification; 00070 cerr<<"GInit"; 00071 _classification->GInit(); 00072 cerr<<"done."<<endl; 00073 00074 } 00075 00076 00077 inline void irtkMLSimilarityMetric::Reset() 00078 { 00079 _ll = 0; 00080 _n=0; 00081 } 00082 00083 inline void irtkMLSimilarityMetric::Add(int x, int y) 00084 { 00085 //cerr<<"Add"<<endl; 00086 //if ((x>0)&&(y>0)) 00087 _ll += _classification->PointLogLikelihoodGMM(x,y); 00088 //_ll += (y-x)*(y-x); 00089 _n ++; 00090 } 00091 00092 inline void irtkMLSimilarityMetric::Delete(int x, int y) 00093 { 00094 _ll -= _classification->PointLogLikelihoodGMM(x,y); 00095 // _ll -= (y-x)*(y-x); 00096 _n--; 00097 } 00098 00099 inline void irtkMLSimilarityMetric::Combine(irtkSimilarityMetric *metric) 00100 { 00101 cerr << "irtkMLSimilarityMetric::Combine: Not implemented" << endl; 00102 exit(1); 00103 } 00104 00105 inline void irtkMLSimilarityMetric::Reset(irtkSimilarityMetric *metric) 00106 { 00107 irtkMLSimilarityMetric *m = dynamic_cast<irtkMLSimilarityMetric *>(metric); 00108 00109 if (m == NULL) { 00110 cerr << "irtkMLSimilarityMetric::Reset: Dynamic cast failed" << endl; 00111 exit(1); 00112 } 00113 00114 _ll = m->_ll; 00115 _classification = m->_classification; 00116 _n=m->_n; 00117 } 00118 00119 inline double irtkMLSimilarityMetric::Evaluate() 00120 { 00121 return -_ll/_n; 00122 } 00123 00124 #endif