1 #include "TrainEdgePottsCS.h" 11 int nFeatures = featureVector1.rows;
13 featureVector1.convertTo(fv1, CV_32FC1);
14 featureVector2.convertTo(fv2, CV_32FC1);
17 subtract(fv1, fv2, dfv);
18 multiply(dfv, dfv, dfv);
19 for (
int i = 0; i < nFeatures; i++)
20 res += dfv.at<
float>(i, 0);
21 res = sqrtf(res / nFeatures);
33 float res = l / sqrt(l*l + x*x);
34 return MAX(FLT_EPSILON, res);
40 float res = l*l / (l*l + x*x);
41 return MAX(FLT_EPSILON, res);
47 float res = expf(-l * x*x);
48 return MAX(FLT_EPSILON, res);
54 DGM_ASSERT_MSG((vParams.size() == 2) || (vParams.size() ==
m_nStates + 1),
"Wrong number of parameters: %zu. It must be either %d or %u", vParams.size(), 2,
m_nStates + 1);
57 if (featureVector1.empty() || featureVector2.empty())
return res;
60 DGM_ASSERT_MSG((featureVector1.type() == CV_8UC1) && (featureVector2.type() == CV_8UC1),
61 "One (or both) of input feature vectors has either wrong depth or more than one channel");
62 DGM_ASSERT_MSG((featureVector1.size().width == 1) && (featureVector1.size().height ==
getNumFeatures()),
63 "The first input feature vector has wrong size:(%d, %d)", featureVector1.size().width, featureVector1.size().height);
64 DGM_ASSERT_MSG((featureVector2.size().width == 1) && (featureVector2.size().height ==
getNumFeatures()),
65 "The second input feature vector has wrong size:(%d, %d)", featureVector2.size().width, featureVector2.size().height);
75 for (byte s = 0; s <
m_nStates; s++) res.at<
float>(s, s) = MAX(1.0f, res.at<
float>(s, s) * penalty);
float penalizerExp(float x, float l)
Charbonnier penalization approach.
word getNumFeatures(void) const
Returns number of features.
Perrona-Malik penalization approach.
ePotPenalApproach m_penApproach
virtual Mat calculateEdgePotentials(const Mat &featureVector1, const Mat &featureVector2, const vec_float_t &vParams) const
Returns the data-independent edge potentials.
Exponential penalization approach.
float penalizerChar(float x, float l)
float calculateContrast(const Mat &featureVector1, const Mat &featureVector2)
byte m_nStates
The number of states (classes)
virtual Mat calculateEdgePotentials(const Mat &featureVector1, const Mat &featureVector2, const vec_float_t &vParams) const
Returns the contrast-sensitive edge potentials.
float penalizerPM(float x, float l)