1 #include "EdgeModelPotts.h" 5 CEdgeModelPotts::CEdgeModelPotts(
const Mat& features,
float weight,
const std::function<
void(
const Mat& src, Mat& dst)>& semiMetricFunction,
bool perPixelNormalization)
7 , m_pLattice(
std::make_unique<CPermutohedral>())
9 , m_norm(features.rows, 1, CV_32FC1, Scalar(1))
10 , m_function(semiMetricFunction)
17 if (perPixelNormalization)
18 for (
int n = 0; n <
m_norm.rows; n++)
19 m_norm.at<
float>(n, 0) = 1.0f / (
m_norm.at<
float>(n, 0) + FLT_EPSILON);
21 float mean_norm =
static_cast<float>(sum(
m_norm)[0]);
22 mean_norm =
m_norm.rows / mean_norm;
33 concurrency::parallel_for(0, dst.rows, [&](
int n) {
35 for (int n = 0; n < dst.rows; n++) {
37 if (m_function) m_function(dst.row(n), lvalue_cast(dst.row(n)));
41 float* pDst = dst.ptr<float>(n);
42 float k = m_weight * m_norm.at<float>(n, 0);
43 for (int s = 0; s < dst.cols; s++) pDst[s] *= k;
std::unique_ptr< CPermutohedral > m_pLattice
Pointer to the permutohedral lattice.
Interface class for edge models used in dense graphical models.
void apply(const Mat &src, Mat &dst) const override
Applies an edge model to the node potentials of a dense graph.
Mat m_norm
Array with normalization factors.
CEdgeModelPotts(const Mat &features, float weight=1.0f, const std::function< void(const Mat &src, Mat &dst)> &semiMetricFunction={}, bool perPixelNormalization=true)
Constructor.