-
Notifications
You must be signed in to change notification settings - Fork 15
/
bayesian.h
41 lines (35 loc) · 1.66 KB
/
bayesian.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
#include <vector>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
#define BAYESIAN_NUMBER_NEAREST 500
#define BAYESIAN_SIGMA 8.f
#define BAYESIAN_SIGMA_C 5.f
#define BAYESIAN_MAX_CLUS 3
#define WIN_SIZE 1
class BayesianMatting
{
public:
BayesianMatting(Mat img, Mat trimap);
~BayesianMatting();
void setParameters(int n=BAYESIAN_NUMBER_NEAREST, double sigma=BAYESIAN_SIGMA, double sigmaC=BAYESIAN_SIGMA_C);
double solve();
private:
void initialize();
vector<Point> getContour(Mat trimap);
void CollectSampleSet(int x, int y, vector<pair<cv::Point, float> > &fg_set, vector<pair<cv::Point, float> > &bg_set);
void GetGMMModel(int x, int y, vector<float> &fg_weight, vector<Mat> &fg_mean, vector<Mat> inv_fg_cov, vector<float> &bg_weight, vector<Mat> bg_mean, vector<Mat> inv_bg_cov);
void CalculateNonNormalizeCov(Mat cImg, vector<pair<cv::Point, float> > &clus_set, Mat mean, Mat cov);
void CalculateMeanCov(Mat cImg, vector<pair<cv::Point, float> > &clus_set, Mat mean, Mat cov);
void CalculateWeightMeanCov(Mat cImg, vector<pair<cv::Point, float> > &clus_set, float &weight, Mat mean, Mat cov);
void InitializeAlpha(int x, int y, Mat unsolvedMask);
void SolveAlpha(int x, int y);
void SolveBF(int x, int y, Mat fg_mean, Mat inv_fg_cov, Mat bg_mean, Mat inv_bg_cov);
float computeLikelihood(int x, int y, Mat fg_mean, Mat inv_fg_cov, Mat bg_mean, Mat inv_bg_cov);
Mat img, fgImg, bgImg;
Mat maskFg, maskBg, maskUnknown, maskUnsolved;
Mat trimap, alphamap;
int nearest;
double sigma, sigmaC;
};