summaryrefslogtreecommitdiffstats
path: root/dis/Neighborhood
diff options
context:
space:
mode:
authorJoshua Bakita <jbakita@cs.unc.edu>2020-10-17 14:43:46 -0400
committerJoshua Bakita <jbakita@cs.unc.edu>2020-10-17 14:43:46 -0400
commita3886552003d031acb9039e920b7c9ddce946ad6 (patch)
treec3b6a400a9ba31e744e6218365d63bdfbbc45a83 /dis/Neighborhood
parent917499f6257ac51c05e8302af877d56a22f28cb5 (diff)
DIS fixes used for (rejected) RTSS'20 submission
- All: Output times to stderr and nothing to stdout - Field, Update, Pointer: change definition of a job to match other stressmark execution times more closely - Matrix: move all allocations into main() - Update: Use volatile to prevent computations from being optimized out - Transitive: Use volatile to prevent computations from being optimized out - Neighborhood: Use working version of drawLineSegment from original DIS sample code
Diffstat (limited to 'dis/Neighborhood')
-rw-r--r--dis/Neighborhood/initializeImage.c371
-rw-r--r--dis/Neighborhood/neighborhood.c14
-rw-r--r--dis/Neighborhood/utili.h161
3 files changed, 434 insertions, 112 deletions
diff --git a/dis/Neighborhood/initializeImage.c b/dis/Neighborhood/initializeImage.c
new file mode 100644
index 0000000..a030a1a
--- /dev/null
+++ b/dis/Neighborhood/initializeImage.c
@@ -0,0 +1,371 @@
1/* Copyright 2000, Atlantic Aerospace Electronics Corp */
2/*
3 * Name: initializeImage
4 * Input: dimension dimension of image
5 * maxImageValue max legal image value
6 * numberLines number line segments for image
7 * minThickness min thickness for line segment
8 * maxThickness max thickness for line segment
9 * Output: image image initialized
10 * Comment: This routine allocates memory to store an image and fills
11 * in the image structure except for the image data. The
12 * pixels of the image are of type ShortInt. If there
13 * is an error allocating memory, than a NULL pointer is
14 * returned. Assumptions: the image dimensions given are
15 * positive.
16 * Calls: errorMessage()
17 * (system) malloc()
18 * free()
19 * Return: image structure pointer (partially filled in - no data -
20 * and allocated)
21 * NULL (error allocating memory for image/image structure)
22 *
23 * Revision History:
24 * Date Name Revision
25 * --------- ----------- -----------------------------
26 * 25May2000 May Leung Created
27 * 05Jun2000 May Leung Add maxImageValue as input to initializeImage()
28 * XXMay2020 Joshua Bakita Commented out significant portions to allow this to
29 * be #include(d) elsewhere.
30 */
31typedef int Int;
32typedef short int ShortInt;
33typedef float Float;
34void drawRowPoint (Int value,
35 Int pointThickness,
36 Int row,
37 Int column,
38 Image *image);
39void drawColumnPoint (Int value,
40 Int pointThickness,
41 Int row,
42 Int column,
43 Image *image);
44#define MIN_RANDOM_VALUE 0
45#if 0
46#ifndef NDEBUG
47#include <stdio.h>
48#endif /* NDEBUG */
49#include <assert.h> /* define assert() */
50#include <stdlib.h> /* define NULL, malloc(), free() */
51#include "stressmark.h" /* system include file */
52#include "neighborhood.h" /* define types, structures, etc */
53#include "errorMessage.h" /* define errorMessage() */
54#include "random.h" /* define randomUInt() */
55#include "initializeImage.h" /* define initializeImage() */
56
57Image *initializeImage (Int dimension, /* dimension of image */
58 Int maxImageValue, /* max legal image value */
59 Int numberLines, /* number line segments for image */
60 Int minThickness, /* min thickness for line segment */
61 Int maxThickness) /* max thickness for line segment */
62{ /* beginning of initializeImage() */
63
64 Image *image; /* pointer to image structure to allocate */
65 ShortInt *data; /* pointer to the data for the image structure*/
66 Int lineIndex; /* loop index variable for line segments */
67 Int pixelIndex; /* loop index variable for pixels */
68 Int limit; /* limit for loop using pixelIndex */
69
70 Coord startPoint; /* starting point for a line segment */
71 Coord endPoint; /* ending point for a line segment */
72 Int lineThickness; /* thickness for a line segment */
73 Int startValue; /* starting value for a line segment */
74 Int endValue; /* ending value for a line segment */
75
76 /*
77 * Assert the assumptions that the number of columns and number of rows
78 * are positive values. No test on the maximum possible value is done since
79 * numColumns and numRows are of type Int and the maximum value of an Int
80 * type is possible.
81 */
82 assert(dimension > 0);
83 assert(numberLines > 0);
84 assert((minThickness > 0) && (minThickness < dimension));
85 assert((maxThickness > 0) && (maxThickness < dimension));
86 assert(minThickness <= maxThickness);
87
88 /* create image */
89 image = createImage(dimension,dimension,maxImageValue);
90 if (image == NULL) {
91 return(NULL);
92 } /* end error check from createImage */
93
94 /* zero out the image */
95 limit = dimension * dimension;
96 data = image->data;
97 for (pixelIndex = 0; pixelIndex < limit; pixelIndex++) {
98 *data++ = 0;
99 } /* end for loop */
100
101 /*
102 * Populate the image with line segments where the endpoints, values, and
103 * thickness of each line segment are randomly generated.
104 */
105 for (lineIndex = 0; lineIndex < numberLines; lineIndex++) {
106 randomImageLocation(image, &startPoint);
107 randomImageLocation(image, &endPoint);
108 lineThickness = randomUInt(minThickness,maxThickness);
109 startValue = randomUInt(MIN_RANDOM_VALUE, maxImageValue);
110 endValue = randomUInt(MIN_RANDOM_VALUE, maxImageValue);
111
112 /* add line segment to the image */
113 drawLineSegment(&startPoint, &endPoint, startValue, endValue, lineThickness,
114 image);
115
116 } /* end for loop */
117
118 return(image);
119} /* end initializeImage() */
120#endif
121
122/*
123 * drawLineSegment() This routine draws a line segment into the given image
124 * starting at the coordinate startPoint and ending at the
125 * coordinate endPoint. The values along this line segment
126 * vary linearly from the given starting value startValue to
127 * the end value endValue and have a lineThickness associated
128 * to it.
129 *
130 * This routine is modeled after the routine draw_line() from
131 * "Practical Computer Vision using C", by J.R. Parker, Wiley, 1994, pp 114-116.
132 * It has been enhanced to have values on the line segment vary and to have
133 * a thickness to the line segment.
134 */
135void drawLineSegment (Coord *startPoint, /* starting point for line segment */
136 Coord *endPoint, /* ending point for line segment */
137 Int startValue, /* starting value for line segment */
138 Int endValue, /* ending value for line segment */
139 Int lineThickness, /* thickness for line segment */
140 Image *image) /* image to add line segment to */
141{ /* beginning of drawLineSegment() */
142
143 /*
144 * Modeled after draw_line() from "Practical Computer Vision using C",
145 * by J.R. Parker, Wiley, 1994, pp 114-116. Enhanced to have values
146 * on the line segment vary and to have a thickness to the line segment.
147 * The value along the line segment is kept in a float variable so that
148 * fractional increments along the line segment can accumulate to integer
149 * values.
150 */
151 Int changeColumn, changeRow; /* change along line segment in col/row */
152 Int absColumn, absRow; /* absolute value of change in col/row */
153 Int signColumn, signRow; /* sign of change along line segment col/row */
154 Int delta; /* increment alone line segment */
155 Int column, row; /* column & row of coordinate along line seg */
156 Float value, valueDelta; /* value & value change along line segment */
157
158// assert(validImage(image));
159 assert(startPoint != NULL);
160 assert(endPoint != NULL);
161
162#ifdef DEBUG0
163 fprintf(stderr,
164 "drawLineSegment: start row %6ld col %6ld\tend row %6ld col %6ld\n",
165 startPoint->row,startPoint->column,endPoint->row,endPoint->column);
166 fprintf(stderr," startVal %6ld endVal %6ld thickness %6ld\n",
167 startValue, endValue, lineThickness);
168#endif /* DEBUG0 */
169
170 changeColumn = endPoint->column - startPoint->column;
171 if (changeColumn < 0) {
172 absColumn = - changeColumn;
173 signColumn = - 1;
174 } /* end changeColumn < 0 */
175 else { /* changeColumn >= 0 */
176 absColumn = changeColumn;
177 signColumn = 1;
178 } /* end changeColumn >= 0 */
179 absColumn *= 2;
180
181 changeRow = endPoint->row - startPoint->row;
182 if (changeRow < 0) {
183 absRow = - changeRow;
184 signRow = - 1;
185 } /* end changeRow < 0 */
186 else { /* changeRow >= 0 */
187 absRow = changeRow;
188 signRow = 1;
189 } /* end changeRow >= 0 */
190 absRow *= 2;
191
192 column = startPoint->column;
193 row = startPoint->row;
194 value = startValue; /* add changing value to algorithm */
195
196 if (signColumn * changeColumn > signRow * changeRow) { /* column dominant */
197 /* determine the change in value for each step (added to algorithm) */
198 valueDelta = ((Float) endValue - startValue) /
199 ((Float) changeColumn * signColumn);
200
201 delta = absRow - (absColumn / 2);
202 while (TRUE) { /* inifinite loop */
203 /*
204 * Line is column dominant, so line thickness will be along rows. Make
205 * sure the ending value doesn't go beyond endValue. (Added to algorithm)
206 */
207 drawRowPoint((Int) value, lineThickness, row, column, image);
208 if (valueDelta >=0) {
209 value = MIN(endValue, value+valueDelta);
210 } /* values are incrementing */
211 else { /* valueDelta < 0 */
212 value = MAX(endValue, value+valueDelta);
213 } /* values are decreasing */
214
215 if (column == endPoint->column) {
216 return; /* done with line segment exit routine */
217 } /* end exit criteria */
218 if (delta >= 0) {
219 row += signRow;
220 delta -= absColumn;
221 } /* end if delta >= 0 */
222 column += signColumn;
223 delta += absRow;
224 } /* end while infinite loop */
225 } /* end row dominant case */
226 else { /* row dominant case */
227 /* determine the change in value for each step (added to algorithm) */
228 if (changeRow == 0) {
229 valueDelta = 0;
230 assert(changeColumn == 0);
231 } /* end if changeRow == 0 */
232 else {
233 valueDelta = ((Float) endValue - startValue) /
234 ((Float) changeRow * signRow);
235 } /* end else */
236
237 delta = absColumn - (absRow / 2);
238 while (TRUE) { /* inifinite loop */
239 /*
240 * Line is row dominant, so line thickness will be along columns. Make
241 * sure the ending value doesn't go beyond endValue. (Added to algorithm)
242 */
243 drawColumnPoint((Int) value, lineThickness, row, column, image);
244 if (valueDelta >=0) {
245 value = MIN(endValue, value+valueDelta);
246 } /* values are incrementing */
247 else { /* valueDelta < 0 */
248 value = MAX(endValue, value+valueDelta);
249 } /* values are decreasing */
250
251 if (row == endPoint->row) {
252 return; /* done with line segment exit routine */
253 } /* end exit criteria */
254 if (delta >= 0) {
255 column += signColumn;
256 delta -= absRow;
257 } /* end if delta >= 0 */
258 row += signRow;
259 delta += absColumn;
260 } /* end while infinite loop */
261 } /* end column dominant case */
262
263 return;
264} /* end of drawLineSegment() */
265
266/*
267 * drawRowPoint() This routine draws a point with a row thickness onto the
268 * given image for the coordinate and value provided.
269 */
270void drawRowPoint (Int value, /* value for point */
271 Int pointThickness, /* thickness for point */
272 Int row, /* row coordinate of point */
273 Int column, /* column coordinate of point */
274 Image *image) /* image to draw point onto */
275{ /* beginning of drawRowPoint() */
276 Int halfThickness; /* half the point thickness */
277 Int lowerRow, upperRow, rowIndex; /* loop boundaries and index for row */
278 ShortInt *data; /* image data pointer */
279
280// assert(validImage(image));
281 assert(value >= MIN_RANDOM_VALUE);
282 assert(value <= image->maxImageValue);
283 assert(pointThickness > 0);
284
285#ifdef DEBUG0
286 fprintf(stderr,
287 "drawRowPoint: value %5ld, thickness %6ld, row %6ld, column %6ld\n",
288 value,pointThickness,row,column);
289#endif /* DEBUG0 */
290
291 halfThickness = (Int) pointThickness / 2; /* use integer division */
292 lowerRow = MAX(0, row - halfThickness);
293 upperRow = MIN(image->numRows, row + pointThickness - halfThickness);
294
295 data = image->data + (lowerRow * image->numColumns) + column;
296 for (rowIndex = lowerRow; rowIndex < upperRow; rowIndex++) {
297 *data = (ShortInt) value;
298 data += image->numColumns; /* increment pointer to next row */
299 } /* end for loop */
300
301 return;
302} /* end of drawRowPoint() */
303
304/*
305 * drawColumnPoint() This routine draws a point with a column thickness onto the
306 * given image for the coordinate and value provided.
307 */
308void drawColumnPoint (Int value, /* value for point */
309 Int pointThickness, /* thickness for point */
310 Int row, /* row coordinate of point */
311 Int column, /* column coordinate of point */
312 Image *image) /* image to draw point onto */
313{ /* beginning of drawColumnPoint() */
314 Int halfThickness; /* half the point thickness */
315 Int leftColumn, rightColumn, columnIndex; /* col loop boundaries&index*/
316 ShortInt *data; /* image data pointer */
317
318// assert(validImage(image));
319 assert(value >= MIN_RANDOM_VALUE);
320 assert(value <= image->maxImageValue);
321 assert(pointThickness > 0);
322
323#ifdef DEBUG0
324 fprintf(stderr,
325 "drawColumnPoint: value %5ld, thickness %6ld, row %6ld, column %6ld\n",
326 value,pointThickness,row,column);
327#endif /* DEBUG0 */
328
329 halfThickness = (Int) pointThickness / 2; /* use integer division */
330 leftColumn = MAX(0, column - halfThickness);
331 rightColumn = MIN(image->numColumns, column + pointThickness - halfThickness);
332
333 data = image->data + (row * image->numColumns) + leftColumn;
334 for (columnIndex = leftColumn; columnIndex < rightColumn; columnIndex++) {
335 *data = (ShortInt) value;
336 data++; /* increment pointer to next column */
337 } /* end for loop */
338
339 return;
340} /* end of drawColumnPoint() */
341
342/*
343 * randomImageLocation() This routine generates a random coordinate yielding a
344 * coordinate in the given image using randomUInt().
345 */
346#if 0
347#include "random.h"
348
349void randomImageLocation (Image *image, /* image in question */
350 Coord *location) /* random location generated */
351{ /* beginning of randomImageLocation() */
352 Int index; /* random location in image */
353 Int maxIndex; /* maximum index in image */
354
355 assert(validImage(image));
356 assert(location != NULL);
357
358 maxIndex = image->numColumns * image->numRows - 1;
359 index = randomUInt(0, maxIndex);
360
361 /* use integer division to clip to closest integer value */
362 location->row = (Int) index / image->numColumns;
363 location->column = index - (location->row * image->numColumns);
364
365 assert((location->row >= 0) && (location->row < image->numRows));
366 assert((location->column >= 0) && (location->column < image->numColumns));
367 assert(index = location->column + (location->row * image->numColumns));
368
369 return;
370} /* end of randomImageLocation() */
371#endif
diff --git a/dis/Neighborhood/neighborhood.c b/dis/Neighborhood/neighborhood.c
index 1736d38..23f3a8e 100644
--- a/dis/Neighborhood/neighborhood.c
+++ b/dis/Neighborhood/neighborhood.c
@@ -11,6 +11,10 @@
11 * read the Benchmark Analysis and Specifications Document Version 1.0 11 * read the Benchmark Analysis and Specifications Document Version 1.0
12 * before going on since the detailed comments are given in this documents. 12 * before going on since the detailed comments are given in this documents.
13 * the comments are not repeated here. 13 * the comments are not repeated here.
14 *
15 * Change log:
16 * ------- ---------------- ---------------------------------------------------
17 * 06/2020 Joshua Bakita Include image creation time in timing
14 */ 18 */
15 19
16#include <stdio.h> 20#include <stdio.h>
@@ -58,12 +62,14 @@ int main(int argc, char** argv)
58 62
59 randInit(seed); 63 randInit(seed);
60 maxPixel = (1 << bitDepth) - 1; 64 maxPixel = (1 << bitDepth) - 1;
61 image = createImage(dimension, maxPixel, numberLines, 65 image = malloc(sizeof(Pixel) * dimension * dimension);
62 minThickness, maxThickness); 66 assert(image != NULL);
63 assert (image != NULL);
64 67
65 beginTime = time(NULL); 68 beginTime = time(NULL);
66 START_LOOP 69 START_LOOP
70 createImage(image, dimension, maxPixel, numberLines,
71 minThickness, maxThickness);
72
67 neighborhoodCalculation(image, dimension, 73 neighborhoodCalculation(image, dimension,
68 distanceShort, distanceLong, &values, maxPixel); 74 distanceShort, distanceLong, &values, maxPixel);
69 STOP_LOOP 75 STOP_LOOP
@@ -91,7 +97,7 @@ int main(int argc, char** argv)
91 values.distLong.deg135.entropy, 97 values.distLong.deg135.entropy,
92 values.distLong.deg135.energy); 98 values.distLong.deg135.energy);
93 99
94 fprintf(stderr, "time for neghborhood stressmark = %f\n", 100 fprintf(stderr, "time for neghborhood stressmark = %f seconds.\n",
95 difftime(endTime, beginTime)); 101 difftime(endTime, beginTime));
96 102
97 free((Pixel *)image); 103 free((Pixel *)image);
diff --git a/dis/Neighborhood/utili.h b/dis/Neighborhood/utili.h
index 2a8e2a0..5b54d9b 100644
--- a/dis/Neighborhood/utili.h
+++ b/dis/Neighborhood/utili.h
@@ -56,81 +56,23 @@ typedef struct {
56 56
57typedef short int Pixel; /* short int;*/ 57typedef short int Pixel; /* short int;*/
58 58
59typedef struct {
60 int numColumns; /* number of columns in image */
61 int numRows; /* number of rows in image */
62 Pixel maxImageValue; /* max legal image value */
63 Pixel *data; /* data pointer */
64} Image;
59 65
60void drawLineSegment(Pixel *image, 66// For correct implementation of drawLineSegment
61 Coord startPoint, 67#include "initializeImage.c"
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 68
127Pixel *createImage (int dimension, 69Pixel *createImage (Pixel *image,
70 int dimension,
128 Pixel maxPixel, 71 Pixel maxPixel,
129 int numberLines, 72 int numberLines,
130 int minThickness, 73 int minThickness,
131 int maxThickness) 74 int maxThickness)
132 { 75 {
133 Pixel *image;
134 int i; 76 int i;
135 77
136 Coord startPoint; 78 Coord startPoint;
@@ -138,9 +80,12 @@ Pixel *createImage (int dimension,
138 int thickness; 80 int thickness;
139 int startValue; 81 int startValue;
140 int endValue; 82 int endValue;
83 Image img;
84 img.numColumns = dimension;
85 img.numRows = dimension;
86 img.maxImageValue = maxPixel;
87 img.data = image;
141 88
142 image = (Pixel *)malloc(sizeof(Pixel) * dimension * dimension);
143 assert (image != NULL);
144 for (i=0; i<dimension*dimension; i++){ 89 for (i=0; i<dimension*dimension; i++){
145 image[i] = 0; 90 image[i] = 0;
146 } 91 }
@@ -154,6 +99,7 @@ Pixel *createImage (int dimension,
154 startPoint.column = (int) temp % dimension; 99 startPoint.column = (int) temp % dimension;
155 prev = temp; 100 prev = temp;
156 101
102 // Make sure that the end is different than the start
157 while((temp = randomUInt(0, dimension*dimension -1)) == prev); 103 while((temp = randomUInt(0, dimension*dimension -1)) == prev);
158 104
159 endPoint.row = (int) temp/dimension; 105 endPoint.row = (int) temp/dimension;
@@ -163,11 +109,11 @@ Pixel *createImage (int dimension,
163 startValue = randomUInt(MIN_PIXEL, maxPixel); 109 startValue = randomUInt(MIN_PIXEL, maxPixel);
164 endValue = randomUInt(MIN_PIXEL, maxPixel); 110 endValue = randomUInt(MIN_PIXEL, maxPixel);
165 111
166 drawLineSegment(image, startPoint, endPoint, 112 drawLineSegment(&startPoint, &endPoint,
167 startValue, endValue, thickness, dimension); 113 startValue, endValue, thickness, &img);
168 } 114 }
169 return(image); 115 return(image);
170 } 116}
171 117
172 118
173void calcEntropyEnergy( 119void calcEntropyEnergy(
@@ -214,10 +160,10 @@ void calcEntropyEnergy(
214 columnHigh = dimension; 160 columnHigh = dimension;
215 } 161 }
216 else 162 else
217 { 163 {
218 columnLow = 0; 164 columnLow = 0;
219 columnHigh = dimension - dx; 165 columnHigh = dimension - dx;
220 } 166 }
221 167
222 totalNumPixels = 0; 168 totalNumPixels = 0;
223 value0RowOffset = rowLow * dimension; 169 value0RowOffset = rowLow * dimension;
@@ -225,27 +171,27 @@ void calcEntropyEnergy(
225 171
226 for (rowIndex = rowLow; rowIndex<rowHigh; rowIndex++){ 172 for (rowIndex = rowLow; rowIndex<rowHigh; rowIndex++){
227 for (columnIndex= columnLow; columnIndex<columnHigh; 173 for (columnIndex= columnLow; columnIndex<columnHigh;
228 columnIndex++){ 174 columnIndex++){
229 int value0; 175 int value0;
230 int value1; 176 int value1;
231 int binIndex; 177 int binIndex;
232 178
233 rowForPixelAtDistance = rowIndex + dy; 179 rowForPixelAtDistance = rowIndex + dy;
234 columnForPixelAtDistance = columnIndex + dx; 180 columnForPixelAtDistance = columnIndex + dx;
235 181
236 value0 = *(image + value0RowOffset + columnIndex); 182 value0 = *(image + value0RowOffset + columnIndex);
237 value1 = *(image + value1RowOffset + 183 value1 = *(image + value1RowOffset +
238 columnForPixelAtDistance); 184 columnForPixelAtDistance);
239 185
240 binIndex = value0 + value1 - 2*MIN_PIXEL; 186 binIndex = value0 + value1 - 2*MIN_PIXEL;
241 assert((binIndex >= 0) && (binIndex < numBins)); 187 assert((binIndex >= 0) && (binIndex < numBins));
242 sumHist[binIndex] += 1; 188 sumHist[binIndex] += 1;
243 binIndex = value0 - value1 + maxPixel - MIN_PIXEL; 189 binIndex = value0 - value1 + maxPixel - MIN_PIXEL;
244 190
245 assert((binIndex >= 0) && (binIndex < numBins)); 191 assert((binIndex >= 0) && (binIndex < numBins));
246 192
247 diffHist[binIndex] += 1; 193 diffHist[binIndex] += 1;
248 totalNumPixels += 1; 194 totalNumPixels += 1;
249 195
250 } 196 }
251 197
@@ -269,26 +215,26 @@ void calcEntropyEnergy(
269 entropyValue = (double) 0; 215 entropyValue = (double) 0;
270 scale = 1.e0/totalNumPixels; 216 scale = 1.e0/totalNumPixels;
271 for (index = 0; index<numBins; index++){ 217 for (index = 0; index<numBins; index++){
272 if (sumHist[index] > 0){ 218 if (sumHist[index] > 0){
273 sumNormalized = (double) sumHist[index]*scale; 219 sumNormalized = (double) sumHist[index]*scale;
274 entropyValue = entropyValue - sumNormalized * 220 entropyValue = entropyValue - sumNormalized *
275 log((double)sumNormalized); 221 log((double)sumNormalized);
276 energySum = energySum + sumNormalized * sumNormalized ; 222 energySum = energySum + sumNormalized * sumNormalized ;
277 } 223 }
278 if (diffHist[index] > 0){ 224 if (diffHist[index] > 0){
279 diffNormalized = (double)diffHist[index]*scale; 225 diffNormalized = (double)diffHist[index]*scale;
280 entropyValue = entropyValue - diffNormalized * log(diffNormalized); 226 entropyValue = entropyValue - diffNormalized * log(diffNormalized);
281 energyDifference = energyDifference + 227 energyDifference = energyDifference +
282 diffNormalized * diffNormalized; 228 diffNormalized * diffNormalized;
283 } 229 }
284 } 230 }
285 *energy = energySum * energyDifference; 231 *energy = energySum * energyDifference;
286 *entropy = entropyValue; 232 *entropy = entropyValue;
287 } 233 }
288 return; 234 return;
289 } 235}
236
290 237
291
292void neighborhoodCalculation 238void neighborhoodCalculation
293 (Pixel *image, 239 (Pixel *image,
294 int dimension, 240 int dimension,
@@ -306,7 +252,6 @@ void neighborhoodCalculation
306 diffHist = (int *)malloc(numBins * sizeof(int)); 252 diffHist = (int *)malloc(numBins * sizeof(int));
307 assert(diffHist != NULL); 253 assert(diffHist != NULL);
308 254
309 printf(" before short calc deg0\n");
310 calcEntropyEnergy(sumHist, diffHist, image, numBins, 255 calcEntropyEnergy(sumHist, diffHist, image, numBins,
311 distanceShort, 0, 256 distanceShort, 0,
312 &(neighborhood->distShort.deg0.entropy), 257 &(neighborhood->distShort.deg0.entropy),