void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { /* Input data */ double *A = mxGetPr(prhs[0]); double thre = *(mxGetPr(prhs[1])); int M = mxGetM(prhs[0]); int N = mxGetN(prhs[0]); int n_start = 1; if(nrhs>2) n_start = ROUND(*(mxGetPr(prhs[2]))); int n_search = 1; if(nrhs>3) n_search = ROUND(*(mxGetPr(prhs[3]))); /* call algorithm */ D = new double[M*N]; // DP matrix, D[y,x] is the cost of contour 1 at x links = new int[M*N]; // matching to contour 2 at y int *C = new int[M]; double T = 100000000; bool bSucc = false; if(n_start==1 && n_search==1) bSucc = DPMatchingFixStartPoint(C, T, A, thre, M, N); else bSucc = DPMatchingMultiStart(C,T, A,thre,M,N,n_start,n_search); //bSucc = DPMatchingCircular(C, T, A, thre, M, N, n_search); /* Output data */ mxArray *pMxC = mxCreateDoubleMatrix(1,M,mxREAL); double *pC = mxGetPr(pMxC); for(int ii=0;ii<M;++ii) pC[ii] = (double)C[ii]+1; mxArray *pMxT = mxCreateDoubleMatrix(1,1,mxREAL); *(mxGetPr(pMxT))= T; /* Return */ plhs[0] = pMxC; plhs[1] = pMxT; delete []C; delete []D; delete []links; }
void DPMatching( double *cvec, double *match_cost, double *A, double thre, int M, int N, int n_start, int n_search) { /* Input data */ /* call algorithm */ D = new double[M*N]; // DP matrix, D[y,x] is the cost of contour 1 at x links = new int[M*N]; // matching to contour 2 at y int *C = new int[M]; double T = 100000000; bool bSucc = false; if(n_start==1 && n_search==1) bSucc = DPMatchingFixStartPoint(C, T, A, thre, M, N); else bSucc = DPMatchingMultiStart(C,T, A,thre,M,N,n_start,n_search); //bSucc = DPMatchingCircular(C, T, A, thre, M, N, n_search); /* Output data */ for(int ii=0;ii<M;++ii) cvec[ii] = (double)C[ii]+1; *match_cost=T; /* Return */ delete []C; delete []D; delete []links; }