forked from np-csu/AlphaMatting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsharedmatting.h
103 lines (83 loc) · 2.16 KB
/
sharedmatting.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef SHAREDMSTTING_H
#define SHAREDMSTTING_H
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <cmath>
#include <vector>
//#include <cv.h>
//#include <highgui.h>
using namespace std;
struct labelPoint
{
int x;
int y;
int label;
};
struct Tuple
{
cv::Scalar f;
cv::Scalar b;
double sigmaf;
double sigmab;
int flag;
};
struct Ftuple
{
cv::Scalar f;
cv::Scalar b;
double alphar;
double confidence;
};
/*程序中认定cv::Point中 x为行,y为列,可能错误,但对程序结果没有影响*/
class SharedMatting
{
public:
SharedMatting();
~SharedMatting();
void loadImage(char * filename);
void loadTrimap(char * filename);
void expandKnown();
void sample(cv::Point p, vector<cv::Point>& f, vector<cv::Point>& b);
void gathering();
void refineSample();
void localSmooth();
void solveAlpha();
void save(char * filename);
void Sample(vector<vector<cv::Point> > &F, vector<vector<cv::Point> > &B);
void getMatte();
void release();
double mP(int i, int j, cv::Scalar f, cv::Scalar b);
double nP(int i, int j, cv::Scalar f, cv::Scalar b);
double eP(int i1, int j1, int i2, int j2);
double pfP(cv::Point p, vector<cv::Point>& f, vector<cv::Point>& b);
double aP(int i, int j, double pf, cv::Scalar f, cv::Scalar b);
double gP(cv::Point p, cv::Point fp, cv::Point bp, double pf);
double gP(cv::Point p, cv::Point fp, cv::Point bp, double dpf, double pf);
double dP(cv::Point s, cv::Point d);
double sigma2(cv::Point p);
double distanceColor2(cv::Scalar cs1, cv::Scalar cs2);
double comalpha(cv::Scalar c, cv::Scalar f, cv::Scalar b);
private:
// IplImage * pImg;
// IplImage * trimap;
// IplImage * matte;
cv::Mat pImg;
cv::Mat trimap;
cv::Mat matte;
vector<cv::Point> uT;
vector<struct Tuple> tuples;
vector<struct Ftuple> ftuples;
int height;
int width;
int kI;
int kG;
int ** unknownIndex;//Unknown的索引信息;
int ** tri;
int ** alpha;
double kC;
int step;
int channels;
uchar* data;
};
#endif