summaryrefslogtreecommitdiffstats
path: root/dis/Neighborhood/utili.h
diff options
context:
space:
mode:
authorJoshua Bakita <jbakita@cs.unc.edu>2020-10-16 16:55:14 -0400
committerJoshua Bakita <jbakita@cs.unc.edu>2020-10-16 16:55:14 -0400
commit6ea9939e0610a809f6f47d13ec68df00d1ca0afc (patch)
treefe4a2eee3ddcf77e2367309dcd75a232b76dcd62 /dis/Neighborhood/utili.h
parente9285d0cdea756a2830f0ace378e4197b36869aa (diff)
Move the DIS benchmarks up a directory and update hardcoded paths
Note that this repo does not attempt to keep a copy of the original DIS benchmark distributions. UNC real-time has another repo for that.
Diffstat (limited to 'dis/Neighborhood/utili.h')
-rw-r--r--dis/Neighborhood/utili.h363
1 files changed, 363 insertions, 0 deletions
diff --git a/dis/Neighborhood/utili.h b/dis/Neighborhood/utili.h
new file mode 100644
index 0000000..2a8e2a0
--- /dev/null
+++ b/dis/Neighborhood/utili.h
@@ -0,0 +1,363 @@
1/*
2 * Sample code for the DIS Pointer Stressmark
3 *
4 * This source code is the completely correct source code based on
5 * the example codes provided by Atlantic Aerospace Division, Titan
6 * Systems Corporation, 2000.
7 *
8 * If you just compile and generate the executables from this source
9 * code, this code would be enough. However, if you wish to get a complete
10 * understanding of this stressmark, it is strongly suggested that you
11 * read the Benchmark Analysis and Specifications Document Version 1.0
12 * before going on since the detailed comments are given in this documents.
13 * the comments are not repeated here.
14 */
15
16#include <math.h>
17
18#define TRUE 1
19#define FALSE !TRUE
20#define SUCCESS TRUE
21#define ERROR FLASE
22
23#define MIN_PIXEL 0
24#define MAX_DIMENSION 32768
25#define MIN_SEED -2147483647
26#define MAX_SEED -1
27#define MAX_NUMBER_LINES 65536
28#define MIN_BIT_DEPTH 7
29#define MAX_BIT_DEPTH 15
30
31typedef struct {
32 int column;
33 int row;
34}Coord;
35
36/*
37 * Neighborhood structure consists of the GLCM descriptors entropy and
38 * energy for each of 2 distance and 4 angels
39 */
40typedef struct {
41 float entropy;
42 float energy;
43}Descriptors;
44
45typedef struct {
46 Descriptors deg0;
47 Descriptors deg45;
48 Descriptors deg90;
49 Descriptors deg135;
50}Angeles;
51
52typedef struct {
53 Angeles distShort;
54 Angeles distLong;
55}Neighborhood;
56
57typedef short int Pixel; /* short int;*/
58
59
60void drawLineSegment(Pixel *image,
61 Coord startPoint,
62 Coord endPoint,
63 int startValue,
64 int endValue,
65 int thickness,
66 int dimension)
67 {
68 int changeColumn, changeRow;
69 int delta;
70 int column, row;
71 float value, valueDelta;
72 int t;
73
74 changeColumn = endPoint.column - startPoint.column;
75 changeRow = endPoint.row - startPoint.row;
76
77 assert((changeRow != 0) || (changeColumn != 0));
78
79 column = startPoint.column;
80 row = startPoint.row;
81 value = startValue;
82
83 if (ABS(changeColumn) > ABS(changeRow)){
84 valueDelta = ((float) endValue - startValue)/
85 ((float) ABS(changeColumn));
86 delta = 2*ABS(row) - ABS(column);
87 for (column = startPoint.column;
88 column == endPoint.column+sign(changeColumn);
89 column += sign(changeColumn)){
90 for (t = MAX(0, row-thickness/2);
91 t < MIN(dimension, row+thickness - thickness/2);
92 t++)
93 image[t*dimension + column] = (int)value;
94 value += valueDelta;
95 if (delta >= 0){
96 row += sign(changeRow);
97 delta -= 2*ABS(changeColumn);
98 }
99 column += sign(changeColumn);
100 delta += 2*ABS(changeRow);
101 }
102 }
103 else {
104 valueDelta = ((float) endValue - startValue)/
105 ((float) ABS(changeRow));
106 delta = 2* ABS(column) - ABS(row);
107 for (row = startPoint.row;
108 row == endPoint.row + sign(changeRow);
109 row += sign(changeRow)){
110 for (t = MAX(0, column-thickness/2);
111 t < MIN(dimension, row + thickness - thickness/2);
112 t++)
113 image[row*dimension + t] = (int)value;
114 if (delta >= 0){
115 column += sign(changeColumn);
116 delta -= 2*ABS(changeRow);
117 }
118 row += sign(changeRow);
119 delta += 2*ABS(changeColumn);
120 }
121 }
122 return;
123 }
124
125
126
127Pixel *createImage (int dimension,
128 Pixel maxPixel,
129 int numberLines,
130 int minThickness,
131 int maxThickness)
132 {
133 Pixel *image;
134 int i;
135
136 Coord startPoint;
137 Coord endPoint;
138 int thickness;
139 int startValue;
140 int endValue;
141
142 image = (Pixel *)malloc(sizeof(Pixel) * dimension * dimension);
143 assert (image != NULL);
144 for (i=0; i<dimension*dimension; i++){
145 image[i] = 0;
146 }
147
148 for (i=0; i<numberLines; i++){
149 float temp;
150 float prev;
151
152 temp = randomUInt(0, dimension*dimension - 1);
153 startPoint.row = (int) temp/dimension;
154 startPoint.column = (int) temp % dimension;
155 prev = temp;
156
157 while((temp = randomUInt(0, dimension*dimension -1)) == prev);
158
159 endPoint.row = (int) temp/dimension;
160 endPoint.column = (int) temp% dimension;
161
162 thickness = randomUInt(minThickness, maxThickness);
163 startValue = randomUInt(MIN_PIXEL, maxPixel);
164 endValue = randomUInt(MIN_PIXEL, maxPixel);
165
166 drawLineSegment(image, startPoint, endPoint,
167 startValue, endValue, thickness, dimension);
168 }
169 return(image);
170 }
171
172
173void calcEntropyEnergy(
174 int *sumHist,
175 int *diffHist,
176 Pixel *image,
177 int numBins,
178 int dx,
179 int dy,
180 float *entropy,
181 float *energy,
182 int dimension,
183 Pixel maxPixel)
184 {
185 int index;
186 int totalNumPixels;
187 int rowIndex;
188 int rowLow, rowHigh;
189 int columnIndex;
190 int columnLow, columnHigh;
191 int columnForPixelAtDistance;
192 int rowForPixelAtDistance;
193 int value0RowOffset;
194 int value1RowOffset;
195
196 *entropy = 0.0;
197 *energy = 0.0;
198
199 for (index = 0; index < numBins; index++){
200 sumHist[index] = 0;
201 diffHist[index] = 0;
202 }
203
204 if (dy < 0){
205 rowLow = -dy;
206 rowHigh = dimension;
207 }
208 else {
209 rowLow = 0;
210 rowHigh = dimension - dy;
211 }
212 if (dx < 0){
213 columnLow = -dx;
214 columnHigh = dimension;
215 }
216 else
217 {
218 columnLow = 0;
219 columnHigh = dimension - dx;
220 }
221
222 totalNumPixels = 0;
223 value0RowOffset = rowLow * dimension;
224 value1RowOffset = (rowLow + dy) * dimension;
225
226 for (rowIndex = rowLow; rowIndex<rowHigh; rowIndex++){
227 for (columnIndex= columnLow; columnIndex<columnHigh;
228 columnIndex++){
229 int value0;
230 int value1;
231 int binIndex;
232
233 rowForPixelAtDistance = rowIndex + dy;
234 columnForPixelAtDistance = columnIndex + dx;
235
236 value0 = *(image + value0RowOffset + columnIndex);
237 value1 = *(image + value1RowOffset +
238 columnForPixelAtDistance);
239
240 binIndex = value0 + value1 - 2*MIN_PIXEL;
241 assert((binIndex >= 0) && (binIndex < numBins));
242 sumHist[binIndex] += 1;
243 binIndex = value0 - value1 + maxPixel - MIN_PIXEL;
244
245 assert((binIndex >= 0) && (binIndex < numBins));
246
247 diffHist[binIndex] += 1;
248 totalNumPixels += 1;
249
250 }
251
252 value0RowOffset += dimension;
253 value1RowOffset += dimension;
254
255 }
256
257
258 if (totalNumPixels > 0){
259 int index;
260 double energySum;
261 double energyDifference;
262 double entropyValue;
263 double sumNormalized;
264 double diffNormalized;
265 double scale;
266
267 energySum = (double) 0;
268 energyDifference = (double) 0;
269 entropyValue = (double) 0;
270 scale = 1.e0/totalNumPixels;
271 for (index = 0; index<numBins; index++){
272 if (sumHist[index] > 0){
273 sumNormalized = (double) sumHist[index]*scale;
274 entropyValue = entropyValue - sumNormalized *
275 log((double)sumNormalized);
276 energySum = energySum + sumNormalized * sumNormalized ;
277 }
278 if (diffHist[index] > 0){
279 diffNormalized = (double)diffHist[index]*scale;
280 entropyValue = entropyValue - diffNormalized * log(diffNormalized);
281 energyDifference = energyDifference +
282 diffNormalized * diffNormalized;
283 }
284 }
285 *energy = energySum * energyDifference;
286 *entropy = entropyValue;
287 }
288 return;
289 }
290
291
292void neighborhoodCalculation
293 (Pixel *image,
294 int dimension,
295 int distanceShort,
296 int distanceLong,
297 Neighborhood *neighborhood,
298 Pixel maxPixel)
299 {
300 int *sumHist, *diffHist;
301 int numBins;
302
303 numBins = (2 * (maxPixel - MIN_PIXEL + 1) -1);
304 sumHist = (int *) malloc(numBins * sizeof(int));
305 assert (sumHist != NULL);
306 diffHist = (int *)malloc(numBins * sizeof(int));
307 assert(diffHist != NULL);
308
309 printf(" before short calc deg0\n");
310 calcEntropyEnergy(sumHist, diffHist, image, numBins,
311 distanceShort, 0,
312 &(neighborhood->distShort.deg0.entropy),
313 &(neighborhood->distShort.deg0.energy), dimension,
314 maxPixel);
315
316 calcEntropyEnergy(sumHist, diffHist, image, numBins,
317 distanceShort, distanceShort,
318 &(neighborhood->distShort.deg45.entropy),
319 &(neighborhood->distShort.deg45.energy), dimension,
320 maxPixel);
321
322 calcEntropyEnergy(sumHist, diffHist, image, numBins,
323 0, distanceShort,
324 &(neighborhood->distShort.deg90.entropy),
325 &(neighborhood->distShort.deg90.energy), dimension,
326 maxPixel);
327
328 calcEntropyEnergy(sumHist, diffHist, image, numBins,
329 -distanceShort, distanceShort,
330 &(neighborhood->distShort.deg135.entropy),
331 &(neighborhood->distShort.deg135.energy), dimension,
332 maxPixel);
333
334 calcEntropyEnergy(sumHist, diffHist, image, numBins,
335 distanceLong, 0,
336 &(neighborhood->distLong.deg0.entropy),
337 &(neighborhood->distLong.deg0.energy), dimension,
338 maxPixel);
339
340 calcEntropyEnergy(sumHist, diffHist, image, numBins,
341 distanceLong, distanceLong,
342 &(neighborhood->distLong.deg45.entropy),
343 &(neighborhood->distLong.deg45.energy), dimension,
344 maxPixel);
345
346 calcEntropyEnergy(sumHist, diffHist, image, numBins,
347 0, distanceLong,
348 &(neighborhood->distLong.deg90.entropy),
349 &(neighborhood->distLong.deg90.energy), dimension,
350 maxPixel);
351
352 calcEntropyEnergy(sumHist, diffHist, image, numBins,
353 -distanceLong, distanceLong,
354 &(neighborhood->distLong.deg135.entropy),
355 &(neighborhood->distLong.deg135.energy), dimension,
356 maxPixel);
357
358 free(sumHist);
359 free(diffHist);
360
361 return;
362 }
363