| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkMaximumRatioDecisionRule.cxx.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:41 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
DEF |
=========================================================================*/ |
| 17 |
|
#include "itkMaximumRatioDecisionRule.h" |
| 18 |
|
|
| 19 |
|
namespace itk { |
| 20 |
|
|
| 21 |
|
MaximumRatioDecisionRule::MaximumRatioDecisionRule() |
| 22 |
|
{ |
| 23 |
|
} |
| 24 |
|
|
| 25 |
|
|
| 26 |
|
void MaximumRatioDecisionRule::SetAPriori(APrioriVectorType& values) |
| 27 |
|
{ |
| 28 |
SEM |
m_NumberOfClasses = values.size() ; |
| 29 |
SEM |
m_APrioriRatioMatrix.set_size(values.size(), values.size()) ; |
| 30 |
SEM |
unsigned int i, j ; |
| 31 |
SEM |
double APrioriRatio ; |
| 32 |
SEM,SEM |
for (i = 0 ; i < m_NumberOfClasses ; i++) |
| 33 |
|
{ |
| 34 |
SEM,SEM |
for (j = 0 ; j < m_NumberOfClasses ; j++) |
| 35 |
|
{ |
| 36 |
|
if ( values[i] > 0 ) |
| 37 |
|
{ |
| 38 |
|
APrioriRatio = (double)values[j] / |
| 39 |
SEM,IND |
**********(double)values[i] ; |
| 40 |
|
} |
| 41 |
|
else |
| 42 |
|
{ |
| 43 |
SEM |
APrioriRatio = NumericTraits< double >::max() ; |
| 44 |
|
} |
| 45 |
SEM |
m_APrioriRatioMatrix.put(i, j, APrioriRatio) ; |
| 46 |
|
} |
| 47 |
|
} |
| 48 |
|
} |
| 49 |
|
|
| 50 |
|
|
| 51 |
|
unsigned int |
| 52 |
|
MaximumRatioDecisionRule::Evaluate(const VectorType &discriminantScores) const |
| 53 |
|
{ |
| 54 |
SEM |
unsigned int i, j ; |
| 55 |
SEM |
double temp ; |
| 56 |
|
|
| 57 |
SEM,SEM |
for (i = 0 ; i < m_NumberOfClasses ; i++) |
| 58 |
|
{ |
| 59 |
SEM |
j = 0 ; |
| 60 |
|
while ( j < m_NumberOfClasses ) |
| 61 |
|
{ |
| 62 |
|
if ( j != i ) |
| 63 |
|
{ |
| 64 |
|
if ( discriminantScores[j] != 0.0 ) |
| 65 |
|
{ |
| 66 |
SEM |
temp = discriminantScores[i] / discriminantScores[j] ; |
| 67 |
|
} |
| 68 |
|
else |
| 69 |
|
{ |
| 70 |
SEM |
temp = NumericTraits< double >::max() ; |
| 71 |
|
} |
| 72 |
|
|
| 73 |
|
if ( temp < m_APrioriRatioMatrix.get(i,j) ) |
| 74 |
|
{ |
| 75 |
SEM |
break ; |
| 76 |
|
} |
| 77 |
|
} |
| 78 |
|
|
| 79 |
SEM |
++j ; |
| 80 |
|
|
| 81 |
|
if ( j == m_NumberOfClasses ) |
| 82 |
|
{ |
| 83 |
SEM |
return i ; |
| 84 |
|
} |
| 85 |
|
} |
| 86 |
|
} |
| 87 |
|
|
| 88 |
SEM |
return i ; |
| 89 |
|
} |
| 90 |
|
|
| 91 |
|
|
| 92 |
|
unsigned int |
| 93 |
|
MaximumRatioDecisionRule::Evaluate(const ArrayType &discriminantScores) const |
| 94 |
|
{ |
| 95 |
SEM |
unsigned int i, j ; |
| 96 |
SEM |
double temp ; |
| 97 |
|
|
| 98 |
SEM,SEM |
for (i = 0 ; i < m_NumberOfClasses ; i++) |
| 99 |
|
{ |
| 100 |
SEM |
j = 0 ; |
| 101 |
|
while ( j < m_NumberOfClasses ) |
| 102 |
|
{ |
| 103 |
|
if ( j != i ) |
| 104 |
|
{ |
| 105 |
|
if ( discriminantScores[j] != 0.0 ) |
| 106 |
|
{ |
| 107 |
SEM |
temp = discriminantScores[i] / discriminantScores[j] ; |
| 108 |
|
} |
| 109 |
|
else |
| 110 |
|
{ |
| 111 |
SEM |
temp = NumericTraits< double >::max() ; |
| 112 |
|
} |
| 113 |
|
|
| 114 |
|
if ( temp < m_APrioriRatioMatrix.get(i,j) ) |
| 115 |
|
{ |
| 116 |
SEM |
break ; |
| 117 |
|
} |
| 118 |
|
} |
| 119 |
|
|
| 120 |
SEM |
++j ; |
| 121 |
|
|
| 122 |
|
if ( j == m_NumberOfClasses ) |
| 123 |
|
{ |
| 124 |
SEM |
return i ; |
| 125 |
|
} |
| 126 |
|
} |
| 127 |
|
} |
| 128 |
|
|
| 129 |
SEM |
return i ; |
| 130 |
|
} |
| 131 |
|
|
| 132 |
|
|
| 133 |
|
} // end of namespace |
| 134 |
|
|
| 135 |
EOF |
|
| 136 |
EOF,EML |
|
| 137 |
EOF,EML |
|
| 138 |
EOF,EML |
|
| 139 |
EOF,EML |
|
| 140 |
EOF,EML |
|
| 141 |
EOF,EML |
|
| 142 |
EOF,EML |
|