summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/toolbox/MultiNcut/multiIntensityFirstLayer.c
diff options
context:
space:
mode:
Diffstat (limited to 'SD-VBS/common/toolbox/MultiNcut/multiIntensityFirstLayer.c')
-rwxr-xr-xSD-VBS/common/toolbox/MultiNcut/multiIntensityFirstLayer.c126
1 files changed, 126 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/MultiNcut/multiIntensityFirstLayer.c b/SD-VBS/common/toolbox/MultiNcut/multiIntensityFirstLayer.c
new file mode 100755
index 0000000..0cae523
--- /dev/null
+++ b/SD-VBS/common/toolbox/MultiNcut/multiIntensityFirstLayer.c
@@ -0,0 +1,126 @@
1/*================================================================
2* function w = intensityWppc(image,pi,pj,rMin,sigmaX,sigmaIntensite,valeurMinW )
3* Input:
4* [pi,pj] = index pair representation for MALTAB sparse matrices
5* Output:
6* w = affinity with IC at [pi,pj]
7*
8
9pixels i and j (corresponding to the sampling in pi,pj) are fully connected when d(i,j) <= rmin;
10
11% test sequence
12f = synimg(10);
13[i,j] = cimgnbmap(size(f),2);
14[ex,ey,egx,egy] = quadedgep(f);
15a = affinityic(ex,ey,egx,egy,i,j)
16show_dist_w(f,a);
17
18* Stella X. Yu, Nov 19, 2001.
19*=================================================================*/
20
21# include "mex.h"
22# include "math.h"
23
24void mexFunction(
25 int nargout,
26 mxArray *out[],
27 int nargin,
28 const mxArray *in[]
29)
30{
31 /* declare variables */
32 int nr, nc, np, total;
33 int i, j, k, ix, iy, jx, jy;
34 int *ir, *jc;
35 int squareDistance;
36 /* unsigned long *pi, *pj; */
37unsigned int *pi, *pj;
38 double *w;
39
40 double temp,a1,a2,wij;
41 double rMin;
42 double sigmaX, sigmaIntensite,valeurMinW;
43 double *image;
44
45 /* check argument */
46 if (nargin<7) {
47 mexErrMsgTxt("Four input arguments required");
48 }
49 if (nargout>1) {
50 mexErrMsgTxt("Too many output arguments");
51 }
52
53 /* get edgel information */
54 nr = mxGetM(in[0]);
55 nc = mxGetN(in[0]);
56 np = nr * nc;
57
58 image = mxGetPr(in[0]);
59
60
61
62 /* get new index pair */
63 if (!mxIsUint32(in[1]) | !mxIsUint32(in[2])) {
64 mexErrMsgTxt("Index pair shall be of type UINT32");
65 }
66 if (mxGetM(in[2]) * mxGetN(in[2]) != np + 1) {
67 mexErrMsgTxt("Wrong index representation");
68 }
69 pi = mxGetData(in[1]);
70 pj = mxGetData(in[2]);
71
72 /* create output */
73 out[0] = mxCreateSparse(np,np,pj[np],mxREAL);
74 if (out[0]==NULL) {
75 mexErrMsgTxt("Not enough memory for the output matrix");
76 }
77 w = mxGetPr(out[0]);
78 ir = mxGetIr(out[0]);
79 jc = mxGetJc(out[0]);
80
81 rMin = mxGetScalar(in[3]);
82 sigmaX = mxGetScalar(in[4]);
83 sigmaIntensite= mxGetScalar(in[5]);
84 valeurMinW = mxGetScalar(in[6]);
85
86 a1 = 1.0/ (sigmaX*sigmaX);
87 a2 = 1.0 / (sigmaIntensite*sigmaIntensite );
88
89 /* computation */
90 total = 0;
91 for (j=0; j<np; j++) {
92
93 jc[j] = total;
94 jx = j / nr; /* col */
95 jy = j % nr; /* row */
96
97 for (k=pj[j]; k<pj[j+1]; k++) {
98
99 i = pi[k];
100
101 if (i==j) {
102 wij= 1; /*voir*/
103
104 } else {
105 ix = i / nr;
106 iy = i % nr;
107
108 squareDistance = (ix-jx)*(ix-jx)+(iy-jy)*(iy-jy);
109
110 temp = image[i]-image[j];
111 wij = exp(- squareDistance * a1 - temp*temp * a2 );
112 /*if(wij < valeurMinW)
113 wij = -0.1;*/
114 }
115 ir[total] = i;
116
117 w[total] = wij;
118 total = total + 1;
119
120 } /* i */
121
122 } /* j */
123
124 jc[np] = total;
125}
126