summaryrefslogtreecommitdiffstats
path: root/SD-VBS/benchmarks/mser/src/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/mser/src/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/mser/src/c')
-rw-r--r--SD-VBS/benchmarks/mser/src/c/mser.c714
-rw-r--r--SD-VBS/benchmarks/mser/src/c/mser.h83
-rw-r--r--SD-VBS/benchmarks/mser/src/c/script_mser.c120
3 files changed, 917 insertions, 0 deletions
diff --git a/SD-VBS/benchmarks/mser/src/c/mser.c b/SD-VBS/benchmarks/mser/src/c/mser.c
new file mode 100644
index 0000000..d886d7a
--- /dev/null
+++ b/SD-VBS/benchmarks/mser/src/c/mser.c
@@ -0,0 +1,714 @@
1/********************************
2Author: Sravanthi Kota Venkata
3********************************/
4
5/***
6% MSER Maximally Stable Extremal Regions
7% R=MSER(I,DELTA) computes the Maximally Stable Extremal Regions
8% (MSER) of image I with stability threshold DELTA. I is any
9% array of class UINT8, while DELTA is a scalar of the same class.
10% R is an index set (of class UINT32) which enumerates the
11% representative pixels of the detected regions.
12%
13% A region R can be recovered from a representative pixel X as the
14% connected component of the level set {Y:I(Y) <= I(X)} which
15% contains X.
16***/
17
18
19#include "mser.h"
20#include <string.h>
21
22/* advance N-dimensional subscript */
23void
24adv(iArray *dims, int ndims, iArray *subs_pt)
25{
26 int d = 0 ;
27 while(d < ndims)
28 {
29 sref(subs_pt,d) = sref(subs_pt,d) + 1;
30 if( sref(subs_pt,d) < sref(dims,d) )
31 return ;
32 sref(subs_pt,d++) = 0 ;
33 }
34}
35
36/** driver **/
37I2D* mser(I2D* I, int in_delta,
38 iArray* subs_pt, iArray* nsubs_pt, iArray* strides_pt, iArray* visited_pt, iArray* dims,
39 uiArray* joins_pt,
40 region_t* regions_pt,
41 pair_t* pairs_pt,
42 node_t* forest_pt,
43 ulliArray* acc_pt, ulliArray* ell_pt,
44 I2D* out)
45{
46 idx_t i, rindex=0;
47 int k;
48 int nout = 1;
49
50 int OUT_REGIONS=0;
51 int OUT_ELL = 1;
52 int OUT_PARENTS = 2;
53 int OUT_AREA = 3;
54 int BUCKETS = 256;
55
56 //I2D* out;
57
58 int IN_I = 0;
59 int IN_DELTA = 1;
60
61 /* configuration */
62 int verbose = 1 ; /* be verbose */
63 int small_cleanup= 1 ; /* remove very small regions */
64 int big_cleanup = 1 ; /* remove very big regions */
65 int bad_cleanup = 0 ; /* remove very bad regions */
66 int dup_cleanup = 1 ; /* remove duplicates */
67 val_t delta ; /* stability delta */
68
69 /* node value denoting a void node */
70 idx_t const node_is_void = 0xffffffff ;
71
72 //iArray* subs_pt ; /* N-dimensional subscript
73 //iArray* nsubs_pt ; /* diff-subscript to point to neigh.
74// uiArray* strides_pt ; /* strides to move in image array
75// uiArray* visited_pt ; /* flag
76
77 int nel ; /* number of image elements (pixels) */
78 int ner = 0 ; /* number of extremal regions */
79 int nmer = 0 ; /* number of maximally stable */
80 int ndims ; /* number of dimensions */
81// iArray* dims ; /* dimensions
82 int njoins = 0 ; /* number of join ops */
83
84 I2D* I_pt ; /* source image */
85 //pair_t* pairs_pt ; /* scratch buffer to sort pixels
86// node_t* forest_pt ; /* the extremal regions forest
87// region_t* regions_pt ; /* list of extremal regions found
88 int regions_pt_size;
89 int pairs_pt_size;
90 int forest_pt_size;
91
92 /* ellipses fitting */
93 //ulliArray* acc_pt ; /* accumulator to integrate region moments
94 //ulliArray* ell_pt ; /* ellipses parameters
95 int gdl ; /* number of parameters of an ellipse */
96 //uiArray* joins_pt ; /* sequence of joins
97
98 delta = 0;
99 delta = in_delta;
100
101 /* get dimensions */
102
103 nel = I->height*I->width; /* number of elements of src image */
104 ndims = 2;
105 //dims = malloc(sizeof(iArray) + sizeof(int)*ndims);
106 I_pt = I;
107
108 sref(dims,0) = I->height;
109 sref(dims,1) = I->width;
110
111 /* allocate stuff */
112 //subs_pt = malloc(sizeof(iArray) + sizeof(int)*ndims);
113 //nsubs_pt = malloc(sizeof(iArray) + sizeof(int)*ndims);
114
115 //strides_pt = malloc(sizeof(uiArray)+sizeof(unsigned int)*ndims);
116 //visited_pt = malloc(sizeof(uiArray) + sizeof(unsigned int)*nel);
117 //joins_pt = malloc(sizeof(uiArray) + sizeof(unsigned int)*nel);
118
119 //regions_pt = (region_t*)malloc(sizeof(region_t)*nel);
120 regions_pt_size = nel;
121
122 //pairs_pt = (pair_t*)malloc(sizeof(pair_t)*nel);
123 pairs_pt_size = nel;
124
125 //forest_pt = (node_t*)malloc(sizeof(node_t)*nel);
126 forest_pt_size = nel;
127
128 /* compute strides to move into the N-dimensional image array */
129 sref(strides_pt,0) = 1;
130 for(k = 1 ; k < ndims ; ++k)
131 {
132 sref(strides_pt,k) = sref(strides_pt,k-1) * sref(dims,k-1) ;
133 }
134
135 /* sort pixels in increasing order of intensity: using Bucket Sort */
136 {
137 int unsigned buckets [BUCKETS] ;
138 memset(buckets, 0, sizeof(int unsigned)*BUCKETS) ;
139
140 for(i = 0 ; i < nel ; ++i)
141 {
142 val_t v = asubsref(I_pt,i) ;
143 ++buckets[v] ;
144 }
145
146 for(i = 1 ; i < BUCKETS ; ++i)
147 {
148 arrayref(buckets,i) += arrayref(buckets,i-1) ;
149 }
150
151 for(i = nel ; i >= 1 ; )
152 {
153 val_t v = asubsref(I_pt,--i) ;
154 idx_t j = --buckets[v] ;
155 pairs_pt[j].value = v ;
156 pairs_pt[j].index = i ;
157 }
158 }
159
160 /* initialize the forest with all void nodes */
161 for(i = 0 ; i < nel ; ++i)
162 {
163 forest_pt[i].parent = node_is_void ;
164 }
165
166 /* number of ellipse free parameters */
167 gdl = ndims*(ndims+1)/2 + ndims ;
168
169 /* -----------------------------------------------------------------
170 * Compute extremal regions tree
171 * -------------------------------------------------------------- */
172
173 for(i = 0 ; i < nel ; ++i)
174 {
175 /* pop next node xi */
176 idx_t index = pairs_pt [i].index ;
177 val_t value = pairs_pt [i].value ;
178
179 /* this will be needed later */
180 rindex = index ;
181
182 /* push it into the tree */
183 forest_pt [index] .parent = index ;
184 forest_pt [index] .shortcut = index ;
185 forest_pt [index] .area = 1 ;
186#ifdef USE_RANK_UNION
187 forest_pt [index] .height = 1 ;
188#endif
189
190 /* convert index into a subscript sub; also initialize nsubs
191 to (-1,-1,...,-1) */