1 #include "GraphDenseExt.h" 2 #include "GraphDense.h" 3 #include "EdgeModelPotts.h" 35 Mat feature(1, 2, CV_32FC1);
36 float *pFeature = feature.ptr<
float>(0);
37 for (
int y = 0; y <
m_size.height; y++)
38 for (
int x = 0; x <
m_size.width; x++) {
39 pFeature[0] = x / sigma.val[0];
40 pFeature[1] = y / sigma.val[1];
41 features.push_back(feature);
44 m_graph.
addEdgeModel(std::make_shared<CEdgeModelPotts>(features, weight, semiMetricFunction));
49 const word nFeatures = featureVectors.channels();
51 DGM_ASSERT_MSG(featureVectors.size() ==
m_size,
"Resilution of the train image does not equal to the graph size");
53 Mat feature(1, 2 + nFeatures, CV_32FC1);
54 float *pFeature = feature.ptr<
float>(0);
55 for (
int y = 0; y <
m_size.height; y++) {
56 const byte *pFv = featureVectors.ptr<byte>(y);
57 for (
int x = 0; x <
m_size.width; x++) {
58 pFeature[0] = x / sigma.val[0];
59 pFeature[1] = y / sigma.val[1];
60 for (word f = 0; f < nFeatures; f++)
61 pFeature[2 + f] = pFv[nFeatures * x + f] / sigma_opt;
62 features.push_back(feature);
65 m_graph.
addEdgeModel(std::make_shared<CEdgeModelPotts>(features, weight, semiMetricFunction));
68 void CGraphDenseExt::addBilateralEdgeModel(
const vec_mat_t &featureVectors, Vec2f sigma,
float sigma_opt,
float weight,
const std::function<
void(
const Mat& src, Mat& dst)> &semiMetricFunction)
70 const word nFeatures =
static_cast<word
>(featureVectors.size());
72 DGM_ASSERT_MSG(!featureVectors.empty(),
"The train image is empty");
73 DGM_ASSERT_MSG(featureVectors[0].size() ==
m_size,
"Resilution of the train image does not equal to the graph size");
75 Mat feature(1, 2 + nFeatures, CV_32FC1);
76 float *pFeature = feature.ptr<
float>(0);
77 for (
int y = 0; y <
m_size.height; y++) {
78 byte
const **pFv =
new const byte *[nFeatures];
79 for (word f = 0; f < nFeatures; f++) pFv[f] = featureVectors[f].ptr<byte>(y);
80 for (
int x = 0; x <
m_size.width; x++) {
81 pFeature[0] = x / sigma.val[0];
82 pFeature[1] = y / sigma.val[1];
83 for (
int f = 0; f < nFeatures; f++)
84 pFeature[2 + f] = pFv[f][x] / sigma_opt;
85 features.push_back(feature);
88 m_graph.
addEdgeModel(std::make_shared<CEdgeModelPotts>(features, weight, semiMetricFunction));
byte getNumStates(void) const
Returns number of states (classes)
void buildGraph(Size graphSize) override
Builds a 2D graph of size corresponding to the image resolution.
size_t getNumNodes(void) const override
Returns the number of nodes in the graph.
void addNodes(const Mat &pots) override
Adds the graph nodes with potentials.
void addEdgeModel(const ptr_edgeModel_t &pEdgeModel)
Adds an edge model.
void setNodes(size_t start_node, const Mat &pots) override
Fills the graph nodes with new potentials.
void reset(void) override
Resets the graph.
CGraphDense & m_graph
The graph.
Size m_size
Size of the 2D graph.
void addGaussianEdgeModel(Vec2f sigma, float weight=1.0f, const std::function< void(const Mat &src, Mat &dst)> &semiMetricFunction={})
Add a Gaussian potential model with standard deviation sigma.
void setGraph(const Mat &pots) override
Fills an existing 2D graph with potentials or builds a new 2D graph of size corresponding to pots...
void addBilateralEdgeModel(const Mat &featureVectors, Vec2f sigma, float sigma_opt=1.0f, float weight=1.0f, const std::function< void(const Mat &src, Mat &dst)> &semiMetricFunction={})
Add a Bilateral pairwise potential with spacial standard deviations sigma and color standard deviatio...