diff options
Diffstat (limited to 'dis/original/Neighborhood/utili.h')
| -rw-r--r-- | dis/original/Neighborhood/utili.h | 363 |
1 files changed, 363 insertions, 0 deletions
diff --git a/dis/original/Neighborhood/utili.h b/dis/original/Neighborhood/utili.h new file mode 100644 index 0000000..2a8e2a0 --- /dev/null +++ b/dis/original/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 | |||
| 31 | typedef 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 | */ | ||
| 40 | typedef struct { | ||
| 41 | float entropy; | ||
| 42 | float energy; | ||
| 43 | }Descriptors; | ||
| 44 | |||
| 45 | typedef struct { | ||
| 46 | Descriptors deg0; | ||
| 47 | Descriptors deg45; | ||
| 48 | Descriptors deg90; | ||
| 49 | Descriptors deg135; | ||
| 50 | }Angeles; | ||
| 51 | |||
| 52 | typedef struct { | ||
| 53 | Angeles distShort; | ||
| 54 | Angeles distLong; | ||
| 55 | }Neighborhood; | ||
| 56 | |||
| 57 | typedef short int Pixel; /* short int;*/ | ||
| 58 | |||
| 59 | |||
| 60 | void 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 | |||
| 127 | Pixel *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 | |||
| 173 | void 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; | ||
