summaryrefslogtreecommitdiffstats
path: root/SD-VBS/benchmarks/stitch/src
diff options
context:
space:
mode:
authorleochanj105 <leochanj@live.unc.edu>2020-10-19 23:09:30 -0400
committerleochanj105 <leochanj@live.unc.edu>2020-10-20 02:40:39 -0400
commitf618466c25d43f3bae9e40920273bf77de1e1149 (patch)
tree460e739e2165b8a9c37a9c7ab1b60f5874903543 /SD-VBS/benchmarks/stitch/src
parent47ced4e96bbb782b9e780e8f2cfc637b2c21ff44 (diff)
initial sd-vbs
initial sd-vbs add sd-vbs sd-vbs
Diffstat (limited to 'SD-VBS/benchmarks/stitch/src')
-rw-r--r--SD-VBS/benchmarks/stitch/src/c/dist2.c76
-rw-r--r--SD-VBS/benchmarks/stitch/src/c/extractFeatures.c181
-rw-r--r--SD-VBS/benchmarks/stitch/src/c/getANMS.c145
-rw-r--r--SD-VBS/benchmarks/stitch/src/c/harris.c141
-rw-r--r--SD-VBS/benchmarks/stitch/src/c/matchFeatures.c55
-rw-r--r--SD-VBS/benchmarks/stitch/src/c/maxWindow.c51
-rw-r--r--SD-VBS/benchmarks/stitch/src/c/script_stitch.c65
-rw-r--r--SD-VBS/benchmarks/stitch/src/c/stitch.h22
-rw-r--r--SD-VBS/benchmarks/stitch/src/c/supress.c29
-rwxr-xr-xSD-VBS/benchmarks/stitch/src/matlab/calculateH.m24
-rwxr-xr-xSD-VBS/benchmarks/stitch/src/matlab/dist2.m31
-rwxr-xr-xSD-VBS/benchmarks/stitch/src/matlab/extractFeatures.m56
-rwxr-xr-xSD-VBS/benchmarks/stitch/src/matlab/getANMS.m25
-rwxr-xr-xSD-VBS/benchmarks/stitch/src/matlab/getDirParamLocal.m4
-rwxr-xr-xSD-VBS/benchmarks/stitch/src/matlab/harris.m37
-rwxr-xr-xSD-VBS/benchmarks/stitch/src/matlab/main.m47
-rwxr-xr-xSD-VBS/benchmarks/stitch/src/matlab/matchFeatures.m13
-rw-r--r--SD-VBS/benchmarks/stitch/src/matlab/pics/matched_base_cur.jpgbin0 -> 22688 bytes
-rw-r--r--SD-VBS/benchmarks/stitch/src/matlab/pics/ransaced_feat.jpgbin0 -> 19198 bytes
-rwxr-xr-xSD-VBS/benchmarks/stitch/src/matlab/printImage.m2
-rwxr-xr-xSD-VBS/benchmarks/stitch/src/matlab/ransac.m19
-rwxr-xr-xSD-VBS/benchmarks/stitch/src/matlab/readData.m9
-rwxr-xr-xSD-VBS/benchmarks/stitch/src/matlab/script_run_profile.m38
-rwxr-xr-xSD-VBS/benchmarks/stitch/src/matlab/showInterestPoints.m7
-rwxr-xr-xSD-VBS/benchmarks/stitch/src/matlab/transformH.m13
25 files changed, 1090 insertions, 0 deletions
diff --git a/SD-VBS/benchmarks/stitch/src/c/dist2.c b/SD-VBS/benchmarks/stitch/src/c/dist2.c
new file mode 100644
index 0000000..d76fcb2
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/c/dist2.c
@@ -0,0 +1,76 @@
1/********************************
2Author: Sravanthi Kota Venkata
3********************************/
4
5#include "stitch.h"
6
7F2D* dist2(I2D* x, F2D* c)
8{
9 int ndata, dimx, ncentres, dimc, i, j, k;
10 F2D *n2, *t1, *t2;
11 float temp;
12 F2D *s1, *s2, *ctrans;
13 F2D *mult1, *mult2, *mult3;
14
15 ndata = x->height;
16 dimx = x->width;
17
18 ncentres = c->height;
19 dimc = c->width;
20
21 if(dimx != dimc)
22 return NULL;
23
24 s1 = fSetArray(ncentres, 1, 1);
25 s2 = fSetArray(ndata, 1, 1);
26 t1 = fMallocHandle(1, x->height);
27
28 for(j=0; j<t1->width; j++)
29 {
30 temp = 0;
31 for(i=0; i<t1->height; i++)
32 {
33 temp += subsref(x,j,i) * subsref(x,j,i);
34 }
35
36 asubsref(t1,j) = temp;
37 }
38
39 mult1 = fMtimes(s1, t1);
40 t2 = fMallocHandle(1, c->height);
41
42 for(j=0; j<t2->width; j++)
43 {
44 temp = 0;
45 for(i=0; i<t2->height; i++)
46 {
47 temp += subsref(c,j,i) * subsref(c,j,i);
48 }
49
50 asubsref(t2,j) = temp;
51 }
52
53 mult2 = fMtimes(s2, t2);
54 ctrans = fTranspose(c);
55 mult3 = ifMtimes(x, ctrans);
56
57 for(i=0; i<(mult3->height * mult3->width); i++)
58 asubsref(mult3,i) = asubsref(mult3,i) * 2;
59
60 free(t1);
61 free(t2);
62 free(s1);
63 free(s2);
64 free(ctrans);
65
66 n2 = fMallocHandle(ndata, ncentres);
67 for(i=0; i<(ndata*ncentres); i++)
68 asubsref(n2,i) = asubsref(mult1,i) + asubsref(mult2,i) - asubsref(mult3,i);
69
70 free(mult1);
71 free(mult2);
72 free(mult3);
73
74 return n2;
75
76}
diff --git a/SD-VBS/benchmarks/stitch/src/c/extractFeatures.c b/SD-VBS/benchmarks/stitch/src/c/extractFeatures.c
new file mode 100644
index 0000000..ea574e4
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/c/extractFeatures.c
@@ -0,0 +1,181 @@
1/********************************
2Author: Sravanthi Kota Venkata
3********************************/
4
5#include "stitch.h"
6#include <math.h>
7
8#define min(a,b) (a<b)?a:b
9
10F2D* extractFeatures(I2D* I, F2D* x, F2D* y)
11{
12 int n, i, j, k;
13 F2D* I1;
14 F2D *Iconv;
15 F2D *Isub;
16 int nr, nc;
17 F2D *w, *wt, *vecF;
18 I2D *Xsub, *Ysub;
19 float temp, mean, std;
20 int m;
21 F2D *g1, *g;
22
23 g1 = fSetArray(5,5,0);
24
25 asubsref(g1,0) = 1;
26 asubsref(g1,1) = 4;
27 asubsref(g1,2) = 6;
28 asubsref(g1,3) = 4;
29 asubsref(g1,4) = 1;
30
31 asubsref(g1,5) = 4;
32 asubsref(g1,6) = 16;
33 asubsref(g1,7) = 24;
34 asubsref(g1,8) = 16;
35 asubsref(g1,9) = 4;
36
37 asubsref(g1,10) = 6;
38 asubsref(g1,11) = 24;
39 asubsref(g1,12) = 36;
40 asubsref(g1,13) = 24;
41 asubsref(g1,14) = 6;
42
43 asubsref(g1,15) = 4;
44 asubsref(g1,16) = 16;
45 asubsref(g1,17) = 24;
46 asubsref(g1,18) = 16;
47 asubsref(g1,19) = 4;
48
49 asubsref(g1,20) = 1;
50 asubsref(g1,21) = 4;
51 asubsref(g1,22) = 6;
52 asubsref(g1,23) = 4;
53 asubsref(g1,24) = 1;
54
55 g = fDivide(g1, 256);
56 n = x->height;
57
58 vecF = fMallocHandle(n, 64);
59 I1 = fiDeepCopy(I);
60
61 Iconv = ffConv2(I1, g);
62 fFreeHandle(I1);
63 I1 = ffConv2(Iconv, g);
64 fFreeHandle(Iconv);
65 Iconv = fDeepCopy(I1);
66
67 {
68 int i = (Iconv->height/5);
69 int j = (Iconv->width/5);
70 Isub = fMallocHandle(i, j);
71 }
72
73 for(i=0, m=0; m<Isub->height; i+=5, m++)
74 {
75 for(j=0, k=0; k<Isub->width; j+=5, k++)
76 {
77 subsref(Isub,m,k) = subsref(Iconv,i,j);
78 }
79 }
80
81 fFreeHandle(Iconv);
82 fFreeHandle(g1);
83 fFreeHandle(g);
84 fFreeHandle(I1);
85
86 nr = Isub->height;
87 nc = Isub->width;
88
89 Xsub = iMallocHandle(x->height, x->width);
90 Ysub = iMallocHandle(y->height, y->width);
91
92// printf("Sizes = %d\t%d\t%d\t%d\n", Isub->height, Isub->width, x->height, x->width);
93
94 for(i=0; i<(x->height*x->width); i++)
95 {
96 asubsref(Xsub,i) = min( ( asubsref(x,i) /5), nc-4 );
97 asubsref(Ysub,i) = min( ( asubsref(y,i) /5), nr-4 );
98 }
99
100 {
101 int maxX, maxY;
102 maxX = Xsub->height>Xsub->width?Xsub->height:Xsub->width;
103 maxY = Ysub->height>Ysub->width?Ysub->height:Ysub->width;
104 if(maxX < 6 || maxY < 10)
105 {
106 fFreeHandle(vecF);
107 vecF = fSetArray(n,2,0);
108 for(i=0; i<(x->height); i++)
109 {
110 subsref(vecF, i, 0) = asubsref(Xsub,i)*1.0;
111 subsref(vecF, i, 1) = asubsref(Ysub,i)*1.0;
112 }
113
114 fFreeHandle(Isub);
115 iFreeHandle(Xsub);
116 iFreeHandle(Ysub);
117 return vecF;
118 }
119 }
120
121 {
122 int newSize = 4;
123 if(I->height > 32 && I->width >32)
124 newSize = 64;
125 fFreeHandle(vecF);
126 vecF = fMallocHandle(n, newSize);
127 }
128
129// printf("Size of Isub = %d\t%d\n", Isub->height, Isub->width);
130 for(i=0; i<n; i++)
131 {
132
133 if( asubsref(Ysub,i) < 3)
134 asubsref(Ysub,i) = 3;
135 if( asubsref(Xsub,i) < 3)
136 asubsref(Xsub,i) = 3;
137
138 if( asubsref(Ysub,i) >= (Isub->height-4))
139 asubsref(Ysub,i) = Isub->height-5;
140 if( asubsref(Xsub,i) >= (Isub->width-4))
141 asubsref(Xsub,i) = Isub->width-5;
142
143 m = 0;
144 temp = 0;
145// printf("SUBS %d\t%d\n", asubsref(Ysub,i), asubsref(Xsub,i));
146
147 for(k= asubsref(Xsub,i)-3; k<=( asubsref(Xsub,i)+4); k++)
148 {
149 for(j= asubsref(Ysub,i)-3; j<=( asubsref(Ysub,i)+4); j++)
150 {
151// printf("%d\t%d\n", j, k);
152 subsref(vecF,i,m) = subsref(Isub,j,k);
153 temp += subsref(vecF,i,m);
154 m++;
155 }
156 }
157 mean = temp/64.0;
158
159 std = 0;
160 for(j=0; j<64; j++)
161 {
162 subsref(vecF,i,j) = subsref(vecF,i,j) - mean;
163 std += subsref(vecF,i,j) * subsref(vecF,i,j);
164 }
165
166 std = std/64;
167 std = sqrt(std);
168 for(j=0; j<64; j++)
169 {
170 subsref(vecF,i,j) = subsref(vecF,i,j)/std;
171 }
172 }
173
174 iFreeHandle(Xsub);
175 fFreeHandle(Isub);
176 iFreeHandle(Ysub);
177 return vecF;
178}
179
180
181
diff --git a/SD-VBS/benchmarks/stitch/src/c/getANMS.c b/SD-VBS/benchmarks/stitch/src/c/getANMS.c
new file mode 100644
index 0000000..fa03a85
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/c/getANMS.c
@@ -0,0 +1,145 @@
1/********************************
2Author: Sravanthi Kota Venkata
3********************************/
4
5#include "stitch.h"
6
7F2D* getANMS (F2D *points, int r)
8{
9 unsigned int MAX_LIMIT = 10000000;
10 F2D *suppressR;
11 float C_ROBUST = 0.9;
12 F2D *srtdPnts;
13 int n, k;
14 I2D *srtdVIdx, *supId;
15 float r_sq, t, t1;
16 F2D *tempF, *srtdV, *interestPnts;
17 int i, j, validCount=0, cnt, end;
18 F2D *v;
19 int iter, rows, cols;
20 F2D* temp;
21 int supIdPtr = 0;
22
23 v = fMallocHandle(points->height, 1);
24 for(i=0; i<v->height; i++)
25 asubsref(v,i) = subsref(points,i,2);
26
27 r_sq = r * r * 1.0;
28 n = v->height;
29
30 srtdVIdx = fSortIndices (v, 1);
31 srtdPnts = fMallocHandle (srtdVIdx->height, points->width);
32
33 for (i = 0; i < srtdVIdx->height; i++)
34 for(j=0; j<points->width; j++)
35 subsref(srtdPnts,i,j) = subsref(points, asubsref(srtdVIdx,i), j);
36
37 temp = fSetArray (1, 3, 0);
38 suppressR = fSetArray(n, 1, MAX_LIMIT);
39
40 validCount = 0;
41 iter = 0;
42 for (i = 0; i < suppressR->height; i++)
43 {
44 if ( asubsref(suppressR,i) > r_sq)
45 {
46 validCount++;
47 }
48 }
49
50 k = 0;
51 supId = iMallocHandle(validCount, 1);
52 for (i = 0; i < (suppressR->height*suppressR->width); i++)
53 {
54 if ( asubsref(suppressR,i) > r_sq)
55 {
56 asubsref(supId,k++) = i;
57 }
58 }
59
60 while (validCount > 0)
61 {
62 F2D *tempp, *temps;
63 asubsref(temp,0) = subsref(srtdPnts, asubsref(supId,0), 0);
64 asubsref(temp,1) = subsref(srtdPnts, asubsref(supId,0), 1);
65 asubsref(temp,2) = subsref(srtdPnts, asubsref(supId,0), 2);
66
67 if(iter == 0)
68 interestPnts = fDeepCopy(temp);
69 else
70 {
71 tempp = fDeepCopy(interestPnts);
72 fFreeHandle(interestPnts);
73 interestPnts = ffVertcat(tempp, temp);
74 fFreeHandle(tempp);
75 }
76 iter++;
77
78 tempp = fDeepCopy(srtdPnts);
79 temps = fDeepCopy(suppressR);
80
81 fFreeHandle(srtdPnts);
82 fFreeHandle(suppressR);
83
84 srtdPnts = fMallocHandle(supId->height-1, 3);
85 suppressR = fMallocHandle(supId->height-1, 1);
86
87 k=0;
88 for(i=1; i<supId->height; i++)
89 {
90 subsref(srtdPnts,k,0) = subsref(tempp, asubsref(supId,i) ,0);
91 subsref(srtdPnts,k,1) = subsref(tempp, asubsref(supId,i) ,1);
92 subsref(srtdPnts,k,2) = subsref(tempp, asubsref(supId,i) ,2);
93 subsref(suppressR,k,0) = subsref(temps, asubsref(supId,i) ,0);
94 k++;
95 }
96
97 fFreeHandle(tempp);
98 fFreeHandle(temps);
99 rows = interestPnts->height-1;
100 cols = interestPnts->width;
101 for (i = 0; i < srtdPnts->height; i++)
102 {
103 t = 0;
104 t1 = 0;
105
106 if ((C_ROBUST * subsref(interestPnts,rows,2)) >= subsref(srtdPnts, i,2))
107 {
108 t = subsref(srtdPnts, i,0) - subsref(interestPnts,rows,0);
109 t1 = subsref(srtdPnts, i,1) - subsref(interestPnts,rows,1);
110 t = t * t + t1 * t1;
111 t1 = 0;
112 }
113
114 if ((C_ROBUST * subsref(interestPnts,rows,2)) < subsref(srtdPnts, i,2))
115 t1 = 1 * MAX_LIMIT;
116
117 if ( asubsref(suppressR, i) > (t + t1))
118 {
119 asubsref(suppressR, i) = t + t1;
120 }
121 }
122
123 validCount=0;
124 for (i = 0; i < suppressR->height; i++)
125 if ( asubsref(suppressR,i) > r_sq)
126 validCount++;
127
128 k = 0;
129 iFreeHandle(supId);
130 supId = iMallocHandle(validCount, 1);
131
132 for (i = 0; i < suppressR->height*suppressR->width; i++)
133 if ( asubsref(suppressR,i) > r_sq)
134 asubsref(supId,k++) = i;
135 }
136
137 iFreeHandle(supId);
138 iFreeHandle(srtdVIdx);
139 fFreeHandle(srtdPnts);
140 fFreeHandle(temp);
141 fFreeHandle(suppressR);
142 fFreeHandle(v);
143
144 return interestPnts;
145}
diff --git a/SD-VBS/benchmarks/stitch/src/c/harris.c b/SD-VBS/benchmarks/stitch/src/c/harris.c
new file mode 100644
index 0000000..a24c2b4
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/c/harris.c
@@ -0,0 +1,141 @@
1/********************************
2Author: Sravanthi Kota Venkata
3********************************/
4
5#include "stitch.h"
6
7F2D* harris(I2D* im)
8{
9 F2D *img1;
10 F2D *g1, *g2, *g;
11 F2D *Ix, *Iy;
12 F2D *Ix2, *Iy2, *IxIy;
13 F2D *v, *R, *Rmax, *Rnm;
14 float eps;
15 F2D *sobel, *sob, *temp, *temp1;
16 I2D *win, *x, *y;
17 int i;
18
19 g1 = fSetArray(5,5,0);
20 g2 = fSetArray(3,3,0);
21
22 asubsref(g1,0) = 1;
23 asubsref(g1,1) = 4;
24 asubsref(g1,2) = 6;
25 asubsref(g1,3) = 4;
26 asubsref(g1,4) = 1;
27
28 asubsref(g1,5) = 4;
29 asubsref(g1,6) = 16;
30 asubsref(g1,7) = 24;
31 asubsref(g1,8) = 16;
32 asubsref(g1,9) = 4;
33
34 asubsref(g1,10) = 6;
35 asubsref(g1,11) = 24;
36 asubsref(g1,12) = 36;
37 asubsref(g1,13) = 24;
38 asubsref(g1,14) = 6;
39
40 asubsref(g1,15) = 4;
41 asubsref(g1,16) = 16;
42 asubsref(g1,17) = 24;
43 asubsref(g1,18) = 16;
44 asubsref(g1,19) = 4;
45
46 asubsref(g1,20) = 1;
47 asubsref(g1,21) = 4;
48 asubsref(g1,22) = 6;
49 asubsref(g1,23) = 4;
50 asubsref(g1,24) = 1;
51
52 asubsref(g2,0) = 1;
53 asubsref(g2,1) = 2;
54 asubsref(g2,2) = 1;
55
56 asubsref(g2,3) = 2;
57 asubsref(g2,4) = 4;
58 asubsref(g2,5) = 2;
59
60 asubsref(g2,6) = 1;
61 asubsref(g2,7) = 2;
62 asubsref(g2,8) = 1;
63
64 g = fDivide(g1, 256);
65 sob = fMallocHandle(1,3);
66 asubsref(sob,0) = -0.5;
67 asubsref(sob,1) = 0;
68 asubsref(sob,2) = 0.5;
69
70 {
71 F2D* imf;
72 imf = fiDeepCopy(im);
73 img1 = ffConv2(imf, g);
74 fFreeHandle(imf);
75 }
76
77 Ix = ffConv2(img1, sob);
78 fFreeHandle(sob);
79 sob = fMallocHandle(3,1);
80 asubsref(sob,0) = -0.5;
81 asubsref(sob,1) = 0;
82 asubsref(sob,2) = 0.5;
83 Iy = ffConv2(img1, sob);
84
85 fFreeHandle(g);
86 g = fDivide(g2, 16);
87 eps = 2.2204e-16;
88 sobel = fTimes(Ix, Ix);
89 Ix2 = ffConv2(sobel, g);
90 fFreeHandle(sobel);
91
92 sobel = fTimes(Iy, Iy);
93 Iy2 = ffConv2(sobel, g);
94 fFreeHandle(sobel);
95
96 sobel = fTimes(Ix, Iy);
97 IxIy = ffConv2(sobel, g);
98 fFreeHandle(sobel);
99
100 temp = fTimes(Ix2, Iy2);
101 temp1 = fTimes(IxIy, IxIy);
102 sobel = fMinus(temp, temp1);
103
104 fFreeHandle(temp);
105 temp = fPlus(Ix2, Iy2);
106
107 for(i=0; i<(temp->height*temp->width); i++)
108 asubsref(temp,i) += eps;
109
110 R = ffDivide(sobel, temp);
111
112 win = iSetArray(1,2,3);
113 Rmax = maxWindow(R, win);
114 Rnm = supress(R, Rmax);
115
116 v = fFind3(Rnm);
117
118 iFreeHandle(win);
119 fFreeHandle(Rmax);
120 fFreeHandle(Rnm);
121 fFreeHandle(R);
122
123 fFreeHandle(img1);
124 fFreeHandle(g1);
125 fFreeHandle(g2);
126 fFreeHandle(g);
127 fFreeHandle(Ix);
128 fFreeHandle(Iy);
129 fFreeHandle(Ix2);
130 fFreeHandle(Iy2);
131 fFreeHandle(IxIy);
132 fFreeHandle(sobel);
133 fFreeHandle(sob);
134 fFreeHandle(temp);
135 fFreeHandle(temp1);
136// iFreeHandle(x);
137// iFreeHandle(y);
138
139 return v;
140}
141
diff --git a/SD-VBS/benchmarks/stitch/src/c/matchFeatures.c b/SD-VBS/benchmarks/stitch/src/c/matchFeatures.c
new file mode 100644
index 0000000..5450eb9
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/c/matchFeatures.c
@@ -0,0 +1,55 @@
1/********************************
2Author: Sravanthi Kota Venkata
3********************************/
4
5#include "stitch.h"
6
7I2D* matchFeatures(F2D* vecF1, F2D* vecF2)
8{
9 int m, n, n1, n2, n1c, n2c, i, j;
10 I2D *id, *retMatch, *t;
11 F2D *val, *temp;
12 int rows, cols;
13
14 n1 = vecF1->height;
15 n1c = vecF1->width;
16 n2 = vecF2->height;
17 n2c = vecF2->width;
18
19 retMatch = iMallocHandle(1, 2);
20
21 for(i=0; i<n1; i++)
22 {
23 id = iMallocHandle(1, n2);
24 t = iMallocHandle(1, n1c);
25
26 for(j=0; j<n1c; j++)
27 asubsref(t,j) = subsref(vecF1,i,j);
28
29 temp = dist2(t, vecF2);
30 val = fSort(temp,1);
31 id = fSortIndices(temp,1);
32
33 free(temp);
34 free(t);
35
36 if( asubsref(val,1) != 0 & (( asubsref(val,0) / asubsref(val,1) ) < 0.65))
37 {
38 t = retMatch;
39 rows = t->height + 1;
40 cols = t->width;
41 retMatch = iMallocHandle(rows, cols);
42 n = 0;
43
44 for(m=0; m<(t->height*t->width); m++)
45 {
46 asubsref(retMatch,n++) = asubsref(t,m);
47 }
48
49 asubsref(retMatch,n++) = i;
50 asubsref(retMatch,n) = asubsref(id,0);
51 }
52 }
53
54 return retMatch;
55}
diff --git a/SD-VBS/benchmarks/stitch/src/c/maxWindow.c b/SD-VBS/benchmarks/stitch/src/c/maxWindow.c
new file mode 100644
index 0000000..07f8dc9
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/c/maxWindow.c
@@ -0,0 +1,51 @@
1/********************************
2Author: Sravanthi Kota Venkata
3********************************/
4
5#include "stitch.h"
6
7F2D* maxWindow(F2D* im, I2D* window)
8{
9 int exR, exC, rows, cols, tr, tc, i, j, k;
10 F2D *out, *temp;
11 float t;
12 int m;
13
14 exR = asubsref(window,0)/2;
15 exC = asubsref(window,1)/2;
16
17 rows = im->height;
18 cols = im->width;
19
20 tr = rows+exR-1;
21 tc = cols+exC-1;
22 temp = fDeepCopy(im);
23 out = fMallocHandle(rows, cols);
24
25 for(i=0; i<rows; i++)
26 {
27 for(j=0; j<cols; j++)
28 {
29 t = 0;
30 for(k=-exR; k<=exR; k++)
31 {
32 for(m=-exC; m<=exC; m++)
33 {
34 if( (i+k) < 0 || (i+k) >= rows || (j+m) < 0 || (j+m) >= cols)
35 continue;
36 if( subsref(temp,(i+k),(j+m)) > t)
37 t = subsref(temp,(i+k),(j+m));
38 }
39 }
40 subsref(out,i,j) = t;
41 }
42 }
43
44 fFreeHandle(temp);
45 return out;
46}
47
48
49
50
51
diff --git a/SD-VBS/benchmarks/stitch/src/c/script_stitch.c b/SD-VBS/benchmarks/stitch/src/c/script_stitch.c
new file mode 100644
index 0000000..00c9a93
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/c/script_stitch.c
@@ -0,0 +1,65 @@
1/********************************
2Author: Sravanthi Kota Venkata
3********************************/
4
5#include "stitch.h"
6#include <malloc.h>
7#include "extra.h"
8#define STITCH_MEM 1<<30
9int main(int argc, char* argv[])
10{
11 SET_UP
12 mallopt(M_TOP_PAD, STITCH_MEM);
13 mallopt(M_MMAP_MAX, 0);
14 int rows, cols;
15 F2D *x, *y, *v, *interestPnts, *Fcur, *int1, *int2;
16 I2D *Icur;
17 int i, j;
18 char im1[100], im2[100];
19
20
21 printf("Input image: ");
22 scanf("%s", im1);
23 Icur = readImage(im1);
24 rows = Icur->height;
25 cols = Icur->width;
26
27 printf("start\n");
28 for_each_job{
29 v = harris(Icur);
30 interestPnts = getANMS(v, 24);
31 int1 = fMallocHandle(interestPnts->height, 1);
32 int2 = fSetArray(interestPnts->height, 1, 0);
33 for(i=0; i<int1->height; i++)
34 {
35 asubsref(int1,i) = subsref(interestPnts,i,0);
36 asubsref(int2,i) = subsref(interestPnts,i,1);
37 }
38
39 Fcur = extractFeatures(Icur, int1, int2);
40 }
41 printf("end..\n");
42
43
44#ifdef CHECK
45 /** Self checking - use expected.txt from data directory **/
46 {
47 int ret=0;
48 float tol = 0.02;
49#ifdef GENERATE_OUTPUT
50 fWriteMatrix(Fcur, argv[1]);
51#endif
52 ret = fSelfCheck(Fcur, "expected_C.txt", tol);
53 if (ret == -1)
54 printf("Error in Stitch\n");
55 }
56#endif
57 iFreeHandle(Icur);
58 fFreeHandle(v);
59 fFreeHandle(interestPnts);
60 fFreeHandle(int1);
61 fFreeHandle(int2);
62 fFreeHandle(Fcur);
63 WRITE_TO_FILE
64 return 0;
65}
diff --git a/SD-VBS/benchmarks/stitch/src/c/stitch.h b/SD-VBS/benchmarks/stitch/src/c/stitch.h
new file mode 100644
index 0000000..e2202fc
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/c/stitch.h
@@ -0,0 +1,22 @@
1/********************************
2Author: Sravanthi Kota Venkata
3********************************/
4
5#ifndef _SCRIPT_STITCH_
6#define _SCRIPT_STITCH_
7
8#include "sdvbs_common.h"
9
10F2D* dist2(I2D* x, F2D* c);
11F2D* extractFeatures(I2D* I, F2D* x, F2D* y);
12F2D* getANMS (F2D *points, int r);
13F2D* harris(I2D* im);
14I2D* matchFeatures(F2D* vecF1, F2D* vecF2);
15F2D* maxWindow(F2D* im, I2D* window);
16F2D* supress(F2D* im, F2D* im1);
17int script_stitch();
18
19#endif
20
21
22
diff --git a/SD-VBS/benchmarks/stitch/src/c/supress.c b/SD-VBS/benchmarks/stitch/src/c/supress.c
new file mode 100644
index 0000000..6fbdb6c
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/c/supress.c
@@ -0,0 +1,29 @@
1/********************************
2Author: Sravanthi Kota Venkata
3********************************/
4
5#include "stitch.h"
6
7F2D* supress(F2D* im, F2D* im1)
8{
9 int rows, cols, i, j;
10 F2D *out;
11
12 rows = im->height;
13 cols = im->width;
14
15 out = fSetArray(rows, cols, 0);
16
17 for(i=0; i<rows; i++)
18 {
19 for(j=0; j<cols; j++)
20 {
21 if( subsref(im,i,j) == subsref(im1,i,j))
22 subsref(out,i,j) = subsref(im,i,j);
23 }
24 }
25 return out;
26}
27
28
29
diff --git a/SD-VBS/benchmarks/stitch/src/matlab/calculateH.m b/SD-VBS/benchmarks/stitch/src/matlab/calculateH.m
new file mode 100755
index 0000000..caefd74
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/matlab/calculateH.m
@@ -0,0 +1,24 @@
1function retH=calculateH(pnt1, pnt2)
2
3[n temp]=size(pnt1);
4
5X=zeros(0,8);
6b=zeros(0,1);
7
8for i=1:n
9 X=[X; pnt1(i,1) pnt1(i,2) 1 0 0 0 -pnt2(i,1)*pnt1(i,1) -pnt2(i,1)*pnt1(i,2);0, 0, 0, pnt1(i,1), pnt1(i,2), 1, -pnt2(i,2)*pnt1(i,1), -pnt2(i,2)*pnt1(i,2)];
10 b=[b; pnt2(i,1); pnt2(i,2)];
11end
12
13if n==4
14 %if abs(det(X)~=0
15 H=X^(-1)*b;
16 %else
17 % H=[0 0 0; 0 0 0; 0 0 1];
18 %end
19else
20 Xt = X';
21 H=(Xt*X)^(-1)*Xt*b;
22end
23
24retH=[H(1) H(2) H(3);H(4) H(5) H(6);H(7) H(8) 1];
diff --git a/SD-VBS/benchmarks/stitch/src/matlab/dist2.m b/SD-VBS/benchmarks/stitch/src/matlab/dist2.m
new file mode 100755
index 0000000..89116ac
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/matlab/dist2.m
@@ -0,0 +1,31 @@
1function n2 = dist2(x, c)
2%DIST2 Calculates squared distance between two sets of points.
3%
4% Description
5% D = DIST2(X, C) takes two matrices of vectors and calculates the
6% squared Euclidean distance between them. Both matrices must be of
7% the same column dimension. If X has M rows and N columns, and C has
8% L rows and N columns, then the result has M rows and L columns. The
9% I, Jth entry is the squared distance from the Ith row of X to the
10% Jth row of C.
11%
12% See also
13% GMMACTIV, KMEANS, RBFFWD
14%
15
16% Copyright (c) Christopher M Bishop, Ian T Nabney (1996, 1997)
17
18[ndata, dimx] = size(x);
19[ncentres, dimc] = size(c);
20if dimx ~= dimc
21 error('Data dimension does not match dimension of centres')
22end
23
24ct = c';
25opt = (x.^2)';
26op2t = (x.^2)';
27tempT = (ones(ncentres, 1) * sum(opt, 1))';
28n2 = tempT + ones(ndata, 1) * sum(op2t,1) - 2.*(x*ct);
29
30
31
diff --git a/SD-VBS/benchmarks/stitch/src/matlab/extractFeatures.m b/SD-VBS/benchmarks/stitch/src/matlab/extractFeatures.m
new file mode 100755
index 0000000..38d2f7c
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/matlab/extractFeatures.m
@@ -0,0 +1,56 @@
1function vecF=extractFeatures(I, x, y, dataDir)
2
3Igray = I;
4w = (1/16)*[1 4 6 4 1];
5[n temp]=size(x);
6
7%SUB sample rate s=5
8wt = w';
9Iconv=conv2(w, wt, Igray, 'same');
10Iconv=conv2(w, wt, Iconv, 'same');
11Isub=Iconv(1:5:end,1:5:end);
12[nr nc]=size(Isub);
13
14Xsub=min(floor(x/5)+1, nc-4);
15Ysub=min(floor(y/5)+1, nr-4);
16
17if(length(Xsub) < 6 || length(Ysub) < 10)
18 vecF = [Xsub Ysub];
19 return;
20end
21
22newSize = 4;
23[rows, cols] = size(I);
24if(rows > 32 & cols >32)
25 newSize = 64;
26end
27
28for i=1:n
29
30 minValy = 3;
31 minValx = 3;
32 if( Ysub(i) < 4)
33 Ysub(i) = 4;
34 end
35 if( Xsub(i) < 4)
36 Xsub(i) = 4;
37 end
38
39 if( Ysub(i) > size(Isub,1)-4)
40 Ysub(i) = size(Isub,1)-4;
41 end
42 if( Xsub(i) > size(Isub,2)-4)
43 Xsub(i) = size(Isub,2)-4;
44 end
45
46 vecF(i,:)=reshape(Isub(Ysub(i)-minValy:Ysub(i)+4,Xsub(i)-minValx:Xsub(i)+4),1,newSize);
47
48 %normalization
49 vecF(i,:)=vecF(i,:)-mean(vecF(i,:));
50 vecF(i,:)=vecF(i,:)/std(vecF(i,:));
51 %imagesc(reshape(vecF(i,:),8,8)); colormap gray
52 %drawnow
53 %pause
54end
55
56
diff --git a/SD-VBS/benchmarks/stitch/src/matlab/getANMS.m b/SD-VBS/benchmarks/stitch/src/matlab/getANMS.m
new file mode 100755
index 0000000..caece31
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/matlab/getANMS.m
@@ -0,0 +1,25 @@
1function [interestPnts]=getANMS(x, y, v, r, dataDir)
2%interestPnts=[x y v]
3MAX_LIMIT=100000000;
4C_ROBUST=0.9;
5r_sq=r^2;
6points=[x y v];
7[n temp]=size(v);
8[srtdV srtdVIdx]=sort(v,'descend');
9srtdPnts=points(srtdVIdx,:);
10
11interestPnts=zeros(0,3);
12
13suppressR=ones(n,1)*MAX_LIMIT;
14supId=find(suppressR>r_sq);
15
16iter = 0;
17while length(supId)>0
18 interestPnts=[interestPnts; srtdPnts(supId(1),:)];
19 srtdPnts=srtdPnts(supId(2:end),:);
20 suppressR=suppressR(supId(2:end),:);
21
22 suppressR=min(suppressR,(C_ROBUST*interestPnts(end,3)>srtdPnts(:,3)).*((srtdPnts(:,1)-interestPnts(end,1)).^2 + (srtdPnts(:,2)-interestPnts(end,2)).^2)+(C_ROBUST*interestPnts(end,3)<=srtdPnts(:,3))*MAX_LIMIT);
23 supId=find(suppressR>r_sq);
24 iter = iter + 1;
25end
diff --git a/SD-VBS/benchmarks/stitch/src/matlab/getDirParamLocal.m b/SD-VBS/benchmarks/stitch/src/matlab/getDirParamLocal.m
new file mode 100755
index 0000000..7b36886
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/matlab/getDirParamLocal.m
@@ -0,0 +1,4 @@
1function DIR_PARAM=getDirParam
2DIR_PARAM.main_dir=pwd;
3DIR_PARAM.data_dir=fullfile(DIR_PARAM.main_dir,'data');
4DIR_PARAM.report_dir=fullfile(DIR_PARAM.main_dir,'report');
diff --git a/SD-VBS/benchmarks/stitch/src/matlab/harris.m b/SD-VBS/benchmarks/stitch/src/matlab/harris.m
new file mode 100755
index 0000000..423330e
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/matlab/harris.m
@@ -0,0 +1,37 @@
1
2% Sample code for detecting Harris corners, following
3% Brown et al, CVPR 2005
4% by Alyosha Efros, so probably buggy...
5
6function [x,y,v] = harris(im, dataDir);
7
8g1 = [1,4,6,4,1; 4,16,24,16,4;6,24,36,24,6;4,16,24,16,4;1,4,6,4,1]/256;
9g2 = [1,2,1;2,4,2;1,2,1]/16;
10
11img1 = conv2(im,g1,'same'); % blur image with sigma_d
12
13Ix = conv2(img1,[-0.5 0 0.5],'same'); % take x derivative
14Iy = conv2(img1,[-0.5;0;0.5],'same'); % take y derivative
15
16% Compute elements of the Harris matrix H
17%%% we can use blur instead of the summing window
18Ix2 = conv2(Ix.*Ix,g2,'same');
19Iy2 = conv2(Iy.*Iy,g2,'same');
20IxIy = conv2(Ix.*Iy,g2,'same');
21
22R = (Ix2.*Iy2 - IxIy.*IxIy) ... % det(H)
23 ./ (Ix2 + Iy2 + eps); % trace(H) + epsilon
24
25% don't want corners close to image border
26[rows, cols] = size(im);
27
28% non-maxima supression within 3x3 windows
29nonmax = inline('max(x)');
30Rmax = colfilt(R,[3 3],'sliding',nonmax); % find neighbrhood max
31Rnm = R.*(R == Rmax); % supress non-max
32
33% extract all interest points
34[y,x,v] = find(Rnm);
35
36
37
diff --git a/SD-VBS/benchmarks/stitch/src/matlab/main.m b/SD-VBS/benchmarks/stitch/src/matlab/main.m
new file mode 100755
index 0000000..9be8504
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/matlab/main.m
@@ -0,0 +1,47 @@
1Icur_list=readData('capitol');
2Icur=Icur_list{1};
3%Icur=Icur(1:150,:,:);
4[x y v]=harris(Icur);
5interestPntsCur=getANMS(x, y, v, 24);
6Fcur=extractFeatures(Icur, interestPntsCur(:,1), interestPntsCur(:,2));
7
8for id=2:length(Icur_list)
9 Iprev=Icur;
10 Fprev=Fcur;
11 interestPntsPrev=interestPntsCur;
12 Icur=Icur_list{id};
13 %Icur=Icur(1:150,:,:);
14 [x y v]=harris(Icur);
15 %showInterestPoints(I, x, y)
16 interestPntsCur=getANMS(x, y, v, 16);
17 %showInterestPoints(I, interestPnts(:,1), interestPnts(:,2))
18 Fcur=extractFeatures(Icur, interestPntsCur(:,1), interestPntsCur(:,2));
19 matchedPntsIdx=matchFeatures(Fprev, Fcur);
20 matchedPntsPrev=interestPntsPrev(matchedPntsIdx(:,1),:);
21 matchedPntsCur=interestPntsCur(matchedPntsIdx(:,2),:);
22
23 %subplot(1,2,1);showInterestPoints(Iprev, matchedPntsPrev(:,1), matchedPntsPrev(:,2));axis image
24 %subplot(1,2,2);showInterestPoints(Icur, matchedPntsCur(:,1), matchedPntsCur(:,2));axis image
25 %drawnow
26 %pause;
27 %printImage(['featureMatching' int2str(id-1) '_' int2str(id)]);
28 [retH retPntsIdx]=ransac(matchedPntsPrev, matchedPntsCur, 10000, 100);
29 subplot(2,2,1);showInterestPoints(Iprev, matchedPntsPrev(retPntsIdx,1), matchedPntsPrev(retPntsIdx,2));axis image
30 subplot(2,2,2);showInterestPoints(Icur, matchedPntsCur(retPntsIdx,1), matchedPntsCur(retPntsIdx,2));axis image
31 T=maketform('projective', retH');
32 Tfn_Mat=T;
33 [nr nc nd]=size(Iprev);
34 Itrans=imtransform(Iprev,T,'XData', [1 nc], 'YData', [1 nr],'FillValues',[0;0;0]);
35 subplot(2,2,3);imshow(Itrans)
36 subplot(2,2,4);imagesc(rgb2gray(abs(Icur-Itrans)))
37 drawnow
38 pause;
39 printImage(['ransac' int2str(id-1) '_' int2str(id)]);
40end
41
42 %[Itrans2 XData YData]=imtransform(Iprev,T,'FillValues',[0;0;0]);
43 %for the fast iteration
44 %[Itrans2 XData2 YData2]=imtransform(Iprev,T,'XData', [-2*nc 2*nc], 'YData', [-2*nr 2*nr],'FillValues',[0;0;0]);
45
46 %h=imshow(Itrans);
47
diff --git a/SD-VBS/benchmarks/stitch/src/matlab/matchFeatures.m b/SD-VBS/benchmarks/stitch/src/matlab/matchFeatures.m
new file mode 100755
index 0000000..7af77e0
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/matlab/matchFeatures.m
@@ -0,0 +1,13 @@
1function retMatch=matchFeatures(vecF1, vecF2)
2[n1 temp]=size(vecF1);
3[n2 temp]=size(vecF2);
4
5retMatch=zeros(0,2);
6
7for i=1:n1
8 [val id]=sort(dist2(vecF1(i,:),vecF2));
9 if val(2)~=0 & val(1)/val(2)<0.65
10 retMatch=[retMatch; i id(1)];
11 end
12end
13
diff --git a/SD-VBS/benchmarks/stitch/src/matlab/pics/matched_base_cur.jpg b/SD-VBS/benchmarks/stitch/src/matlab/pics/matched_base_cur.jpg
new file mode 100644
index 0000000..a4bd68b
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/matlab/pics/matched_base_cur.jpg
Binary files differ
diff --git a/SD-VBS/benchmarks/stitch/src/matlab/pics/ransaced_feat.jpg b/SD-VBS/benchmarks/stitch/src/matlab/pics/ransaced_feat.jpg
new file mode 100644
index 0000000..821ca11
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/matlab/pics/ransaced_feat.jpg
Binary files differ
diff --git a/SD-VBS/benchmarks/stitch/src/matlab/printImage.m b/SD-VBS/benchmarks/stitch/src/matlab/printImage.m
new file mode 100755
index 0000000..82e74f0
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/matlab/printImage.m
@@ -0,0 +1,2 @@
1function printImage(fname, DIR_PARAM)
2print('-djpeg', fullfile(DIR_PARAM, [fname '.jpg']));
diff --git a/SD-VBS/benchmarks/stitch/src/matlab/ransac.m b/SD-VBS/benchmarks/stitch/src/matlab/ransac.m
new file mode 100755
index 0000000..4a3c364
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/matlab/ransac.m
@@ -0,0 +1,19 @@
1function [retH retPntsIdx]=ransac(pntsPrev, pntsCur, k, epsilon)
2[n temp]=size(pntsPrev);
3pntsPrev=[pntsPrev(:,1:2) ones(n,1)];
4pntsCur=[pntsCur(:,1:2) ones(n,1)];
5
6inlierIdx=cell(k,1);
7inlierNum=zeros(k,1);
8for i=1:k
9 seed=randperm(n);
10 H=calculateH(pntsPrev(seed(1:4),:), pntsCur(seed(1:4),:));
11 err=(pntsCur-transformH(H,pntsPrev));
12 inlierIdx{i}=find(sum(err(:,1:2).^2,2) < epsilon);
13 inlierNum=length(inlierIdx{i});
14end
15
16[v maxIdx]=max(inlierNum);
17retPntsIdx=inlierIdx{maxIdx};
18retH=calculateH(pntsPrev(retPntsIdx,:), pntsCur(retPntsIdx,:));
19
diff --git a/SD-VBS/benchmarks/stitch/src/matlab/readData.m b/SD-VBS/benchmarks/stitch/src/matlab/readData.m
new file mode 100755
index 0000000..19643bb
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/matlab/readData.m
@@ -0,0 +1,9 @@
1function retImgs=readData(imgName, dataDir)
2fn=fullfile(dataDir, imgName, '*.jpg');
3filelist=dir(fn);
4
5retImgs=cell(length(filelist),1);
6for i=1:length(filelist)
7 retImgs{i}=imread(fullfile(dataDir, imgName, filelist(i).name));
8end
9
diff --git a/SD-VBS/benchmarks/stitch/src/matlab/script_run_profile.m b/SD-VBS/benchmarks/stitch/src/matlab/script_run_profile.m
new file mode 100755
index 0000000..f2ca68b
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/matlab/script_run_profile.m
@@ -0,0 +1,38 @@
1function script_run_profile(dataDir, resultDir, type, common, toolDir)
2
3path(path, common);
4image_list = 1;
5
6elapsed = zeros(1,2);
7for i=1:image_list
8 Icur = readImage([dataDir, '/', num2str(i) ,'.bmp']);
9 rows = size(Icur,1);
10 cols = size(Icur,2);
11 fprintf(1,'Input size\t\t- (%dx%d)\n', rows, cols);
12
13 %% Self check params
14 tol = 1;
15
16 %% Timing
17 start = photonStartTiming;
18
19 [x y v]=harris(Icur,dataDir);
20 interestPntsCur=getANMS(x, y, v, 24, dataDir);
21 Fcur=extractFeatures(Icur, interestPntsCur(:,1), interestPntsCur(:,2), dataDir);
22
23 %% Timing
24 stop = photonEndTiming;
25
26 temp = photonReportTiming(start, stop);
27 elapsed(1) = elapsed(1) + temp(1);
28 elapsed(2) = elapsed(2) + temp(2);
29
30
31end
32
33%% Self checking
34fWriteMatrix(Fcur, dataDir);
35
36%% Timing
37photonPrintTiming(elapsed);
38
diff --git a/SD-VBS/benchmarks/stitch/src/matlab/showInterestPoints.m b/SD-VBS/benchmarks/stitch/src/matlab/showInterestPoints.m
new file mode 100755
index 0000000..487cae4
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/matlab/showInterestPoints.m
@@ -0,0 +1,7 @@
1function showInterestPoints(im, x, y)
2% show 'em
3imagesc(im);
4colormap(gray);
5hold on;
6plot(x,y,'r.');
7hold off; \ No newline at end of file
diff --git a/SD-VBS/benchmarks/stitch/src/matlab/transformH.m b/SD-VBS/benchmarks/stitch/src/matlab/transformH.m
new file mode 100755
index 0000000..7a22eb8
--- /dev/null
+++ b/SD-VBS/benchmarks/stitch/src/matlab/transformH.m
@@ -0,0 +1,13 @@
1function retPnts=transformH(H, pnts)
2MAX_LIMIT=10000000;
3[n temp]=size(pnts);
4
5pntsT = pnts';
6retPnts=(H*pntsT)';
7for i=1:n
8 if retPnts(i,3)~=0
9 retPnts(i,:)=retPnts(i,:)./retPnts(i,3);
10 else
11 retPnts(i,:)=[MAX_LIMIT MAX_LIMIT 1];
12 end
13end