summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/toolbox/MultiNcut/multiIntensityWppc.c
diff options
context:
space:
mode:
authorLeo Chan <leochanj@live.unc.edu>2020-10-22 01:53:21 -0400
committerJoshua Bakita <jbakita@cs.unc.edu>2020-10-22 01:56:35 -0400
commitd17b33131c14864bd1eae275f49a3f148e21cf29 (patch)
tree0d8f77922e8d193cb0f6edab83018f057aad64a0 /SD-VBS/common/toolbox/MultiNcut/multiIntensityWppc.c
parent601ed25a4c5b66cb75315832c15613a727db2c26 (diff)
Squashed commit of the sb-vbs branch.
Includes the SD-VBS benchmarks modified to: - Use libextra to loop as realtime jobs - Preallocate memory before starting their main computation - Accept input via stdin instead of via argc Does not include the SD-VBS matlab code. Fixes libextra execution in LITMUS^RT.
Diffstat (limited to 'SD-VBS/common/toolbox/MultiNcut/multiIntensityWppc.c')
-rwxr-xr-xSD-VBS/common/toolbox/MultiNcut/multiIntensityWppc.c158
1 files changed, 158 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/MultiNcut/multiIntensityWppc.c b/SD-VBS/common/toolbox/MultiNcut/multiIntensityWppc.c
new file mode 100755
index 0000000..e01e516
--- /dev/null
+++ b/SD-VBS/common/toolbox/MultiNcut/multiIntensityWppc.c
@@ -0,0 +1,158 @@
1/*================================================================
2* function w = multiIntensityWppc(image,pi,pj,rMin,sigmaX,sigmaIntensite,valeurMinW,
3* subgrid,nrSubgrid,ncSubgrid,subpi)
4* Input:
5* [pi,pj] = index pair representation for MALTAB sparse matrices
6* Output:
7* w = affinity with IC at [pi,pj]
8*
9
10imageX,wiInOriginalImage,wwj,rMin,dataWpp.sigmaX,sigmaI,minW,subgrid{1,i},p(i),q(i),wi{i}
11
12
13pixels i and j (corresponding to the sampling in pi,pj) are fully connected when d(i,j) <= rmin;
14
15% test sequence
16f = synimg(10);
17[i,j] = cimgnbmap(size(f),2);
18[ex,ey,egx,egy] = quadedgep(f);
19a = affinityic(ex,ey,egx,egy,i,j)
20show_dist_w(f,a);
21
22* Stella X. Yu, Nov 19, 2001.
23*=================================================================*/
24
25# include "mex.h"
26# include "math.h"
27
28void mexFunction(
29 int nargout,
30 mxArray *out[],
31 int nargin,
32 const mxArray *in[]
33)
34{
35 /* declare variables */
36 int nr, nc, np, nW, total;
37 int i, j, k, t, ix, iy, jx, jy, nrSubgrid, ncSubgrid;
38 int *ir, *jc;
39 int squareDistance;
40 /* unsigned long *pi, *pj, *subpi; */
41 unsigned int *pi, *pj, *subpi;
42 double *w, *subgrid, *tmp;
43
44 double temp,a1,a2,wij;
45 double rMin;
46 double sigmaX, sigmaIntensite,valeurMinW;
47 double *image;
48
49 /* check argument */
50 if (nargin<11) {
51 mexErrMsgTxt("Eleven input arguments required");
52 }
53 if (nargout>1) {
54 mexErrMsgTxt("Too many output arguments");
55 }
56
57 /* get edgel information */
58 nr = mxGetM(in[0]);
59 nc = mxGetN(in[0]);
60 np = nr * nc;
61 /*printf("size: %d, %d, %d\n", nc, nr, np); */
62 image = mxGetPr(in[0]);
63
64
65 /*get subgrid information*/
66
67 tmp = mxGetData(in[8]);
68 nrSubgrid = (int)tmp[0];
69
70 /* printf("image end = %f ", image[np-1]); */
71
72 tmp = mxGetData(in[9]);
73 ncSubgrid = (int)tmp[0];
74
75 if (nrSubgrid* ncSubgrid != mxGetM(in[7])*mxGetN(in[7])) {
76 mexErrMsgTxt("Error in the size of the subgrid");
77 }
78 subgrid = mxGetData(in[7]);
79 nW = nrSubgrid * ncSubgrid;
80
81
82
83
84 /* get new index pair */
85 if (!mxIsUint32(in[1]) | !mxIsUint32(in[2])) {
86 mexErrMsgTxt("Index pair shall be of type UINT32");
87 }
88 if (mxGetM(in[2]) * mxGetN(in[2]) != nW + 1) {
89 mexErrMsgTxt("Wrong index representation");
90 }
91 pi = mxGetData(in[1]);
92 pj = mxGetData(in[2]);
93 subpi = mxGetData(in[10]);
94
95 /* create output */
96 out[0] = mxCreateSparse(nW,nW,pj[nW],mxREAL);
97 if (out[0]==NULL) {
98 mexErrMsgTxt("Not enough memory for the output matrix");
99 }
100
101 w = mxGetPr(out[0]);
102 ir = mxGetIr(out[0]);
103 jc = mxGetJc(out[0]);
104
105
106 rMin = mxGetScalar(in[3]);
107 sigmaX = mxGetScalar(in[4]);
108 sigmaIntensite= mxGetScalar(in[5]);
109 valeurMinW = mxGetScalar(in[6]);
110
111 a1 = 1.0/ (sigmaX*sigmaX);
112 a2 = 1.0 / (sigmaIntensite*sigmaIntensite );
113
114
115
116 /* computation */
117 total = 0;
118 for (j=0; j<nW; j++) {
119
120 t= (int)subgrid[j]-1; /*on parcourt tous les pixels de la sous-grille dans la grille d'origine*/
121 if ( (t<0) || (t>np-1)) {printf("badddddd!");}
122 /* printf("t = %d\n",t);
123 printf("j = %d\n",j); */
124 jc[j] = total;
125 jx = t / nr; /* col */
126 jy = t % nr; /* row */
127 /* printf("pj[j+1] = %d\n",pj[j+1]); */
128
129 for (k=pj[j]; k<pj[j+1]; k++) {
130 /* printf("k = %d\n",k); */
131 i = pi[k]-1;
132 ix = i / nr;
133 iy = i % nr;
134 squareDistance = (ix-jx)*(ix-jx)+(iy-jy)*(iy-jy);/*abs(ix-jx)+abs(iy-jy);*/
135 if (squareDistance <= rMin) { wij = 1;}
136 else {
137 temp = image[i]-image[t];
138 wij = exp(- squareDistance * a1 - temp*temp * a2 );
139 /*if(wij < valeurMinW)
140 wij = 0;*/
141 /*wij = exp( - temp*temp * a2 );*/
142 }
143
144 ir[total] = (int)subpi[k];
145
146 /* if (ir[total] >5000*5000 ) {printf("trouble! [%d,%d]\n",k,(int)subpi[k]);} */
147
148 w[total] = wij;
149
150 total = total + 1;
151
152 } /* i */
153
154
155 } /* j */
156
157 jc[nW] = total;
158}