Direct Graphical Models  v.1.7.0
PriorEdge.cpp
1 #include "PriorEdge.h"
2 #include "macroses.h"
3 
4 namespace DirectGraphicalModels
5 {
6 void CPriorEdge::addEdgeGroundTruth(byte gt1, byte gt2)
7 {
8  DGM_ASSERT(gt1 < m_nStates);
9  DGM_ASSERT(gt2 < m_nStates);
10  m_histogramPrior.at<int>(gt2, gt1)++;
11 }
12 
14 {
15  byte x;
16  Mat H;
17  Mat res(m_nStates, m_nStates, CV_32FC1);
18 
19  m_histogramPrior.convertTo(H, CV_32FC1);
20 
21  switch (m_normApp) {
22  case eP_APP_NORM_STANDARD: { // standard approach
23  double Sum = sum(m_histogramPrior)[0];
24  m_histogramPrior.convertTo(res, res.type(), 1.0 / Sum);
25  break;
26  }
27  case eP_APP_NORM_SYMMETRIC: { // symetric approach
28  Mat tmp;
29  Mat Hd(H.size(), H.type()); Hd.setTo(0); // Hd - diagonal normalization matrix
30  for (x = 0; x < m_nStates; x++)
31  if (H.at<float>(x, x) >= 1.0f) Hd.at<float>(x, x) = 1.0f / sqrtf(H.at<float>(x, x));
32 
33  gemm(H, Hd, 1.0, Mat(), 0.0, tmp); // tmp = Prior * Hd;
34  gemm(Hd, tmp, 1.0, Mat(), 0.0, res); // res = Hd * (Prior * Hd);
35  tmp.release();
36  Hd.release();
37  break;
38  }
39  case eP_APP_NORM_ASYMMETRIC: { // assymetric approach
40  for (byte y = 0; y < m_nStates; y++) {
41  const float *pH = H.ptr<float>(y);
42  float *pRes = res.ptr<float>(y);
43  float max = 1.0f;
44  for (x = 0; x < m_nStates; x++) if (max < pH[x]) max = pH[x];
45  for (x = 0; x < m_nStates; x++) pRes[x] = pH[x] / max;
46  } // y
47  break;
48  }
49  }
50  return res;
51 }
52 
53 }
ePotNormApproach m_normApp
Flag specifying the co-occurance histogram matrix normalization approach (Ref. ePotNormApproach) ...
Definition: PriorEdge.h:70
Mat calculatePrior(void) const
Returns the prior edge probability.
Definition: PriorEdge.cpp:13
Mat m_histogramPrior
The class cooccurance histogram.
Definition: Prior.h:51
void addEdgeGroundTruth(byte gt1, byte gt2)
Adds the groud-truth value to the co-occurance histogram matrix.
Definition: PriorEdge.cpp:6
byte m_nStates
The number of states (classes)