summaryrefslogtreecommitdiffstats
path: root/SD-VBS/benchmarks/stitch/src/c/extractFeatures.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/benchmarks/stitch/src/c/extractFeatures.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/benchmarks/stitch/src/c/extractFeatures.c')
-rw-r--r--SD-VBS/benchmarks/stitch/src/c/extractFeatures.c181
1 files changed, 181 insertions, 0 deletions
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