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