MCPcopy Create free account
hub / github.com/HiLab-git/SimpleCRF / mexFunction

Function mexFunction

maxflow_matlab/automaxflowmex.cpp:16–119  ·  view source on GitHub ↗

[flow label]=automaxflowmex(I,fgProb, bgProb,lambda,sigma)

Source from the content-addressed store, hash-verified

14
15// [flow label]=automaxflowmex(I,fgProb, bgProb,lambda,sigma)
16void mexFunction(int nlhs, /* number of expected outputs */
17 mxArray *plhs[], /* mxArray output pointer array */
18 int nrhs, /* number of inputs */
19 const mxArray *prhs[] /* mxArray input pointer array */)
20{
21 // input checks
22 if (nrhs != 5 )
23 {
24 mexErrMsgTxt ("USAGE: [flow label]=automaxflowmex(I,fgProb, bgProb,lambda,sigma);");
25 }
26 const mxArray *I = prhs[0];
27 const mxArray *fgProb = prhs[1];
28 const mxArray *bgProb = prhs[2];
29 double lamda= * mxGetPr(prhs[3]);
30 double sigma= * mxGetPr(prhs[4]);
31
32 unsigned char * IPr=(unsigned char *)mxGetPr(I);
33 double * fgProbPr=mxGetPr(fgProb);
34 double * bgProbPr=mxGetPr(bgProb);
35 // size of image
36 mwSize m = mxGetM(I);//height
37 mwSize n = mxGetN(I);//width
38
39 //construct graph
40 typedef Graph<float,float,float> GraphType;
41 GraphType *g = new GraphType(/*estimated # of nodes*/ m*n, /*estimated # of edges*/ 2*m*n);
42 g->add_node(m*n);
43
44 float maxWeight=-10000;
45 for(int x=0;x<n;x++)
46 {
47 for(int y=0;y<m;y++)
48 {
49 //n-link
50 float pValue=(float)*(IPr+x*m+y);
51 int uperPointx=x;
52 int uperPointy=y-1;
53 int LeftPointx=x-1;
54 int LeftPointy=y;
55 float n_weight=0;
56 if(uperPointy>=0 && uperPointy<m)
57 {
58 float qValue=(float)*(IPr+uperPointx*m+uperPointy);
59 n_weight=lamda*exp(-(pValue-qValue)*(pValue-qValue)/(2*sigma*sigma));
60 int pIndex=x*m+y;
61 int qIndex=uperPointx*m+uperPointy;
62
63 g->add_edge(qIndex,pIndex,n_weight,n_weight);
64 }
65 if(n_weight>maxWeight)
66 {
67 maxWeight=n_weight;
68 }
69
70 if(LeftPointx>=0 && LeftPointx<n)
71 {
72 float qValue=(float)*(IPr+LeftPointx*m+LeftPointy);
73 n_weight=lamda*exp(-(pValue-qValue)*(pValue-qValue)/(2*sigma*sigma));

Callers

nothing calls this directly

Calls 7

add_nodeMethod · 0.80
add_edgeMethod · 0.80
add_tweightsMethod · 0.80
maxflowMethod · 0.80
what_segmentMethod · 0.80
expFunction · 0.50
logFunction · 0.50

Tested by

no test coverage detected