diff options
| author | Joshua Bakita <jbakita@cs.unc.edu> | 2020-10-17 19:07:11 -0400 |
|---|---|---|
| committer | Joshua Bakita <jbakita@cs.unc.edu> | 2020-10-17 20:54:41 -0400 |
| commit | 1120161286ee5c855b630bccc9e0b37bb8a3ee65 (patch) | |
| tree | 082a47491403a624a28f8b2bf8e20bbdb3f5e0e7 /dis/Neighborhood | |
| parent | 5aad2261f7c012aa16a93c7c5bf6bda0081658fb (diff) | |
Fix DIS coding style by running them all through clang-format
Also fixes a missing header in DISstressmarkRNG.h and the "all"
make target. No functional changes.
Diffstat (limited to 'dis/Neighborhood')
| -rw-r--r-- | dis/Neighborhood/DISstressmarkRNG.h | 1 | ||||
| -rw-r--r-- | dis/Neighborhood/neighborhood.c | 77 | ||||
| -rw-r--r-- | dis/Neighborhood/utili.h | 435 |
3 files changed, 231 insertions, 282 deletions
diff --git a/dis/Neighborhood/DISstressmarkRNG.h b/dis/Neighborhood/DISstressmarkRNG.h index 4aa2620..6243606 100644 --- a/dis/Neighborhood/DISstressmarkRNG.h +++ b/dis/Neighborhood/DISstressmarkRNG.h | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | #include <assert.h> | ||
| 1 | #include <math.h> | 2 | #include <math.h> |
| 2 | 3 | ||
| 3 | #define IA 16807 | 4 | #define IA 16807 |
diff --git a/dis/Neighborhood/neighborhood.c b/dis/Neighborhood/neighborhood.c index 23f3a8e..614b8e8 100644 --- a/dis/Neighborhood/neighborhood.c +++ b/dis/Neighborhood/neighborhood.c | |||
| @@ -1,12 +1,12 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Sample code for the DIS Neighborhood Stressmark | 2 | * Sample code for the DIS Neighborhood Stressmark |
| 3 | * | 3 | * |
| 4 | * This source code is the completely correct source code based on | 4 | * This source code is the completely correct source code based on |
| 5 | * the example codes provided by Atlantic Aerospace Division, Titan | 5 | * the example codes provided by Atlantic Aerospace Division, Titan |
| 6 | * Systems Corporation, 2000. | 6 | * Systems Corporation, 2000. |
| 7 | * | 7 | * |
| 8 | * If you just compile and generate the executables from this source | 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 | 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 | 10 | * understanding of this stressmark, it is strongly suggested that you |
| 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. |
| @@ -17,19 +17,18 @@ | |||
| 17 | * 06/2020 Joshua Bakita Include image creation time in timing | 17 | * 06/2020 Joshua Bakita Include image creation time in timing |
| 18 | */ | 18 | */ |
| 19 | 19 | ||
| 20 | #include "DISstressmarkRNG.h" | ||
| 21 | #include "extra.h" | ||
| 22 | #include "utili.h" | ||
| 23 | #include <assert.h> | ||
| 20 | #include <stdio.h> | 24 | #include <stdio.h> |
| 21 | #include <stdlib.h> | 25 | #include <stdlib.h> |
| 22 | #include <time.h> | 26 | #include <time.h> |
| 23 | #include<assert.h> | ||
| 24 | #include "DISstressmarkRNG.h" | ||
| 25 | #include "utili.h" | ||
| 26 | #include "extra.h" | ||
| 27 | 27 | ||
| 28 | /* | 28 | /* |
| 29 | * main() | 29 | * main() |
| 30 | */ | 30 | */ |
| 31 | int main(int argc, char** argv) | 31 | int main(int argc, char **argv) { |
| 32 | { | ||
| 33 | long int seed; | 32 | long int seed; |
| 34 | int dimension; | 33 | int dimension; |
| 35 | int numberLines; | 34 | int numberLines; |
| @@ -46,10 +45,9 @@ int main(int argc, char** argv) | |||
| 46 | time_t endTime; | 45 | time_t endTime; |
| 47 | SET_UP | 46 | SET_UP |
| 48 | 47 | ||
| 49 | assert(fscanf(stdin, "%ld %d %d %d %d %d %d %d", | 48 | assert(fscanf(stdin, "%ld %d %d %d %d %d %d %d", &seed, &bitDepth, &dimension, |
| 50 | &seed, &bitDepth, &dimension, &numberLines, | 49 | &numberLines, &minThickness, &maxThickness, &distanceShort, |
| 51 | &minThickness, &maxThickness, | 50 | &distanceLong) == 8); |
| 52 | &distanceShort, &distanceLong) == 8); | ||
| 53 | 51 | ||
| 54 | assert((seed >= MIN_SEED) && (seed <= MAX_SEED)); | 52 | assert((seed >= MIN_SEED) && (seed <= MAX_SEED)); |
| 55 | assert((dimension > 0) && (dimension <= MAX_DIMENSION)); | 53 | assert((dimension > 0) && (dimension <= MAX_DIMENSION)); |
| @@ -67,43 +65,32 @@ int main(int argc, char** argv) | |||
| 67 | 65 | ||
| 68 | beginTime = time(NULL); | 66 | beginTime = time(NULL); |
| 69 | START_LOOP | 67 | START_LOOP |
| 70 | createImage(image, dimension, maxPixel, numberLines, | 68 | createImage(image, dimension, maxPixel, numberLines, minThickness, |
| 71 | minThickness, maxThickness); | 69 | maxThickness); |
| 72 | 70 | ||
| 73 | neighborhoodCalculation(image, dimension, | 71 | neighborhoodCalculation(image, dimension, distanceShort, distanceLong, |
| 74 | distanceShort, distanceLong, &values, maxPixel); | 72 | &values, maxPixel); |
| 75 | STOP_LOOP | 73 | STOP_LOOP |
| 76 | endTime = time(NULL); | 74 | endTime = time(NULL); |
| 77 | WRITE_TO_FILE | 75 | WRITE_TO_FILE |
| 78 | 76 | ||
| 79 | // printf(" end time is %d\n", endTime); | 77 | // printf(" end time is %d\n", endTime); |
| 80 | 78 | ||
| 81 | fprintf(stdout, "%9.4e %9.4e %9.4e %9.4e %9.4e %9.4e %9.4e %9.4e", | 79 | fprintf(stdout, "%9.4e %9.4e %9.4e %9.4e %9.4e %9.4e %9.4e %9.4e", |
| 82 | values.distShort.deg0.entropy, | 80 | values.distShort.deg0.entropy, values.distShort.deg0.energy, |
| 83 | values.distShort.deg0.energy, | 81 | values.distShort.deg45.entropy, values.distShort.deg45.energy, |
| 84 | values.distShort.deg45.entropy, | 82 | values.distShort.deg90.entropy, values.distShort.deg90.energy, |
| 85 | values.distShort.deg45.energy, | 83 | values.distShort.deg135.entropy, values.distShort.deg135.energy); |
| 86 | values.distShort.deg90.entropy, | ||
| 87 | values.distShort.deg90.energy, | ||
| 88 | values.distShort.deg135.entropy, | ||
| 89 | values.distShort.deg135.energy); | ||
| 90 | 84 | ||
| 91 | fprintf(stdout,"%9.4e %9.4e %9.4e %9.4e %9.4e %9.4e %9.4e %9.4e", | 85 | fprintf(stdout, "%9.4e %9.4e %9.4e %9.4e %9.4e %9.4e %9.4e %9.4e", |
| 92 | values.distLong.deg0.entropy, | 86 | values.distLong.deg0.entropy, values.distLong.deg0.energy, |
| 93 | values.distLong.deg0.energy,values.distShort.deg45.entropy, | 87 | values.distShort.deg45.entropy, values.distLong.deg45.energy, |
| 94 | values.distLong.deg45.energy, | 88 | values.distLong.deg90.entropy, values.distLong.deg90.energy, |
| 95 | values.distLong.deg90.entropy, | 89 | values.distLong.deg135.entropy, values.distLong.deg135.energy); |
| 96 | values.distLong.deg90.energy, | ||
| 97 | values.distLong.deg135.entropy, | ||
| 98 | values.distLong.deg135.energy); | ||
| 99 | 90 | ||
| 100 | fprintf(stderr, "time for neghborhood stressmark = %f seconds.\n", | 91 | fprintf(stderr, "time for neghborhood stressmark = %f seconds.\n", |
| 101 | difftime(endTime, beginTime)); | 92 | difftime(endTime, beginTime)); |
| 102 | 93 | ||
| 103 | free((Pixel *)image); | 94 | free((Pixel *)image); |
| 104 | return (SUCCESS); | 95 | return (SUCCESS); |
| 105 | } | 96 | } |
| 106 | |||
| 107 | |||
| 108 | |||
| 109 | |||
diff --git a/dis/Neighborhood/utili.h b/dis/Neighborhood/utili.h index 5b54d9b..b5a7498 100644 --- a/dis/Neighborhood/utili.h +++ b/dis/Neighborhood/utili.h | |||
| @@ -1,12 +1,12 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Sample code for the DIS Pointer Stressmark | 2 | * Sample code for the DIS Pointer Stressmark |
| 3 | * | 3 | * |
| 4 | * This source code is the completely correct source code based on | 4 | * This source code is the completely correct source code based on |
| 5 | * the example codes provided by Atlantic Aerospace Division, Titan | 5 | * the example codes provided by Atlantic Aerospace Division, Titan |
| 6 | * Systems Corporation, 2000. | 6 | * Systems Corporation, 2000. |
| 7 | * | 7 | * |
| 8 | * If you just compile and generate the executables from this source | 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 | 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 | 10 | * understanding of this stressmark, it is strongly suggested that you |
| 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. |
| @@ -22,287 +22,248 @@ | |||
| 22 | 22 | ||
| 23 | #define MIN_PIXEL 0 | 23 | #define MIN_PIXEL 0 |
| 24 | #define MAX_DIMENSION 32768 | 24 | #define MAX_DIMENSION 32768 |
| 25 | #define MIN_SEED -2147483647 | 25 | #define MIN_SEED -2147483647 |
| 26 | #define MAX_SEED -1 | 26 | #define MAX_SEED -1 |
| 27 | #define MAX_NUMBER_LINES 65536 | 27 | #define MAX_NUMBER_LINES 65536 |
| 28 | #define MIN_BIT_DEPTH 7 | 28 | #define MIN_BIT_DEPTH 7 |
| 29 | #define MAX_BIT_DEPTH 15 | 29 | #define MAX_BIT_DEPTH 15 |
| 30 | 30 | ||
| 31 | typedef struct { | 31 | typedef struct { |
| 32 | int column; | 32 | int column; |
| 33 | int row; | 33 | int row; |
| 34 | }Coord; | 34 | } Coord; |
| 35 | 35 | ||
| 36 | /* | 36 | /* |
| 37 | * Neighborhood structure consists of the GLCM descriptors entropy and | 37 | * Neighborhood structure consists of the GLCM descriptors entropy and |
| 38 | * energy for each of 2 distance and 4 angels | 38 | * energy for each of 2 distance and 4 angels |
| 39 | */ | 39 | */ |
| 40 | typedef struct { | 40 | typedef struct { |
| 41 | float entropy; | 41 | float entropy; |
| 42 | float energy; | 42 | float energy; |
| 43 | }Descriptors; | 43 | } Descriptors; |
| 44 | 44 | ||
| 45 | typedef struct { | 45 | typedef struct { |
| 46 | Descriptors deg0; | 46 | Descriptors deg0; |
| 47 | Descriptors deg45; | 47 | Descriptors deg45; |
| 48 | Descriptors deg90; | 48 | Descriptors deg90; |
| 49 | Descriptors deg135; | 49 | Descriptors deg135; |
| 50 | }Angeles; | 50 | } Angeles; |
| 51 | 51 | ||
| 52 | typedef struct { | 52 | typedef struct { |
| 53 | Angeles distShort; | 53 | Angeles distShort; |
| 54 | Angeles distLong; | 54 | Angeles distLong; |
| 55 | }Neighborhood; | 55 | } Neighborhood; |
| 56 | 56 | ||
| 57 | typedef short int Pixel; /* short int;*/ | 57 | typedef short int Pixel; /* short int;*/ |
| 58 | 58 | ||
| 59 | typedef struct { | 59 | typedef struct { |
| 60 | int numColumns; /* number of columns in image */ | 60 | int numColumns; /* number of columns in image */ |
| 61 | int numRows; /* number of rows in image */ | 61 | int numRows; /* number of rows in image */ |
| 62 | Pixel maxImageValue; /* max legal image value */ | 62 | Pixel maxImageValue; /* max legal image value */ |
| 63 | Pixel *data; /* data pointer */ | 63 | Pixel *data; /* data pointer */ |
| 64 | } Image; | 64 | } Image; |
| 65 | 65 | ||
| 66 | // For correct implementation of drawLineSegment | 66 | // For correct implementation of drawLineSegment |
| 67 | #include "initializeImage.c" | 67 | #include "initializeImage.c" |
| 68 | 68 | ||
| 69 | Pixel *createImage (Pixel *image, | 69 | Pixel *createImage(Pixel *image, int dimension, Pixel maxPixel, int numberLines, |
| 70 | int dimension, | 70 | int minThickness, int maxThickness) { |
| 71 | Pixel maxPixel, | 71 | int i; |
| 72 | int numberLines, | 72 | |
| 73 | int minThickness, | 73 | Coord startPoint; |
| 74 | int maxThickness) | 74 | Coord endPoint; |
| 75 | { | 75 | int thickness; |
| 76 | int i; | 76 | int startValue; |
| 77 | 77 | int endValue; | |
| 78 | Coord startPoint; | 78 | Image img; |
| 79 | Coord endPoint; | 79 | img.numColumns = dimension; |
| 80 | int thickness; | 80 | img.numRows = dimension; |
| 81 | int startValue; | 81 | img.maxImageValue = maxPixel; |
| 82 | int endValue; | 82 | img.data = image; |
| 83 | Image img; | 83 | |
| 84 | img.numColumns = dimension; | 84 | for (i = 0; i < dimension * dimension; i++) { |
| 85 | img.numRows = dimension; | 85 | image[i] = 0; |
| 86 | img.maxImageValue = maxPixel; | 86 | } |
| 87 | img.data = image; | ||
| 88 | |||
| 89 | for (i=0; i<dimension*dimension; i++){ | ||
| 90 | image[i] = 0; | ||
| 91 | } | ||
| 92 | 87 | ||
| 93 | for (i=0; i<numberLines; i++){ | 88 | for (i = 0; i < numberLines; i++) { |
| 94 | float temp; | 89 | float temp; |
| 95 | float prev; | 90 | float prev; |
| 96 | 91 | ||
| 97 | temp = randomUInt(0, dimension*dimension - 1); | 92 | temp = randomUInt(0, dimension * dimension - 1); |
| 98 | startPoint.row = (int) temp/dimension; | 93 | startPoint.row = (int)temp / dimension; |
| 99 | startPoint.column = (int) temp % dimension; | 94 | startPoint.column = (int)temp % dimension; |
| 100 | prev = temp; | 95 | prev = temp; |
| 101 | 96 | ||
| 102 | // Make sure that the end is different than the start | 97 | // Make sure that the end is different than the start |
| 103 | while((temp = randomUInt(0, dimension*dimension -1)) == prev); | 98 | while ((temp = randomUInt(0, dimension * dimension - 1)) == prev) |
| 99 | ; | ||
| 104 | 100 | ||
| 105 | endPoint.row = (int) temp/dimension; | 101 | endPoint.row = (int)temp / dimension; |
| 106 | endPoint.column = (int) temp% dimension; | 102 | endPoint.column = (int)temp % dimension; |
| 107 | 103 | ||
| 108 | thickness = randomUInt(minThickness, maxThickness); | 104 | thickness = randomUInt(minThickness, maxThickness); |
| 109 | startValue = randomUInt(MIN_PIXEL, maxPixel); | 105 | startValue = randomUInt(MIN_PIXEL, maxPixel); |
| 110 | endValue = randomUInt(MIN_PIXEL, maxPixel); | 106 | endValue = randomUInt(MIN_PIXEL, maxPixel); |
| 111 | 107 | ||
| 112 | drawLineSegment(&startPoint, &endPoint, | 108 | drawLineSegment(&startPoint, &endPoint, startValue, endValue, thickness, |
| 113 | startValue, endValue, thickness, &img); | 109 | &img); |
| 114 | } | 110 | } |
| 115 | return(image); | 111 | return (image); |
| 116 | } | 112 | } |
| 117 | 113 | ||
| 114 | void calcEntropyEnergy(int *sumHist, int *diffHist, Pixel *image, int numBins, | ||
| 115 | int dx, int dy, float *entropy, float *energy, | ||
| 116 | int dimension, Pixel maxPixel) { | ||
| 117 | int index; | ||
| 118 | int totalNumPixels; | ||
| 119 | int rowIndex; | ||
| 120 | int rowLow, rowHigh; | ||
| 121 | int columnIndex; | ||
| 122 | int columnLow, columnHigh; | ||
| 123 | int columnForPixelAtDistance; | ||
| 124 | int rowForPixelAtDistance; | ||
| 125 | int value0RowOffset; | ||
| 126 | int value1RowOffset; | ||
| 127 | |||
| 128 | *entropy = 0.0; | ||
| 129 | *energy = 0.0; | ||
| 130 | |||
| 131 | for (index = 0; index < numBins; index++) { | ||
| 132 | sumHist[index] = 0; | ||
| 133 | diffHist[index] = 0; | ||
| 134 | } | ||
| 118 | 135 | ||
| 119 | void calcEntropyEnergy( | 136 | if (dy < 0) { |
| 120 | int *sumHist, | 137 | rowLow = -dy; |
| 121 | int *diffHist, | 138 | rowHigh = dimension; |
| 122 | Pixel *image, | 139 | } else { |
| 123 | int numBins, | 140 | rowLow = 0; |
| 124 | int dx, | 141 | rowHigh = dimension - dy; |
| 125 | int dy, | 142 | } |
| 126 | float *entropy, | 143 | if (dx < 0) { |
| 127 | float *energy, | 144 | columnLow = -dx; |
| 128 | int dimension, | 145 | columnHigh = dimension; |
| 129 | Pixel maxPixel) | 146 | } else { |
| 130 | { | 147 | columnLow = 0; |
| 131 | int index; | 148 | columnHigh = dimension - dx; |
| 132 | int totalNumPixels; | 149 | } |
| 133 | int rowIndex; | ||
| 134 | int rowLow, rowHigh; | ||
| 135 | int columnIndex; | ||
| 136 | int columnLow, columnHigh; | ||
| 137 | int columnForPixelAtDistance; | ||
| 138 | int rowForPixelAtDistance; | ||
| 139 | int value0RowOffset; | ||
| 140 | int value1RowOffset; | ||
| 141 | |||
| 142 | *entropy = 0.0; | ||
| 143 | *energy = 0.0; | ||
| 144 | |||
| 145 | for (index = 0; index < numBins; index++){ | ||
| 146 | sumHist[index] = 0; | ||
| 147 | diffHist[index] = 0; | ||
| 148 | } | ||
| 149 | |||
| 150 | if (dy < 0){ | ||
| 151 | rowLow = -dy; | ||
| 152 | rowHigh = dimension; | ||
| 153 | } | ||
| 154 | else { | ||
| 155 | rowLow = 0; | ||
| 156 | rowHigh = dimension - dy; | ||
| 157 | } | ||
| 158 | if (dx < 0){ | ||
| 159 | columnLow = -dx; | ||
| 160 | columnHigh = dimension; | ||
| 161 | } | ||
| 162 | else | ||
| 163 | { | ||
| 164 | columnLow = 0; | ||
| 165 | columnHigh = dimension - dx; | ||
| 166 | } | ||
| 167 | 150 | ||
| 168 | totalNumPixels = 0; | 151 | totalNumPixels = 0; |
| 169 | value0RowOffset = rowLow * dimension; | 152 | value0RowOffset = rowLow * dimension; |
| 170 | value1RowOffset = (rowLow + dy) * dimension; | 153 | value1RowOffset = (rowLow + dy) * dimension; |
| 171 | 154 | ||
| 172 | for (rowIndex = rowLow; rowIndex<rowHigh; rowIndex++){ | 155 | for (rowIndex = rowLow; rowIndex < rowHigh; rowIndex++) { |
| 173 | for (columnIndex= columnLow; columnIndex<columnHigh; | 156 | for (columnIndex = columnLow; columnIndex < columnHigh; columnIndex++) { |
| 174 | columnIndex++){ | 157 | int value0; |
| 175 | int value0; | 158 | int value1; |
| 176 | int value1; | 159 | int binIndex; |
| 177 | int binIndex; | ||
| 178 | 160 | ||
| 179 | rowForPixelAtDistance = rowIndex + dy; | 161 | rowForPixelAtDistance = rowIndex + dy; |
| 180 | columnForPixelAtDistance = columnIndex + dx; | 162 | columnForPixelAtDistance = columnIndex + dx; |
| 181 | 163 | ||
| 182 | value0 = *(image + value0RowOffset + columnIndex); | 164 | value0 = *(image + value0RowOffset + columnIndex); |
| 183 | value1 = *(image + value1RowOffset + | 165 | value1 = *(image + value1RowOffset + columnForPixelAtDistance); |
| 184 | columnForPixelAtDistance); | ||
| 185 | 166 | ||
| 186 | binIndex = value0 + value1 - 2*MIN_PIXEL; | 167 | binIndex = value0 + value1 - 2 * MIN_PIXEL; |
| 187 | assert((binIndex >= 0) && (binIndex < numBins)); | 168 | assert((binIndex >= 0) && (binIndex < numBins)); |
| 188 | sumHist[binIndex] += 1; | 169 | sumHist[binIndex] += 1; |
| 189 | binIndex = value0 - value1 + maxPixel - MIN_PIXEL; | 170 | binIndex = value0 - value1 + maxPixel - MIN_PIXEL; |
| 190 | 171 | ||
| 191 | assert((binIndex >= 0) && (binIndex < numBins)); | 172 | assert((binIndex >= 0) && (binIndex < numBins)); |
| 192 | 173 | ||
| 193 | diffHist[binIndex] += 1; | 174 | diffHist[binIndex] += 1; |
| 194 | totalNumPixels += 1; | 175 | totalNumPixels += 1; |
| 176 | } | ||
| 195 | 177 | ||
| 196 | } | 178 | value0RowOffset += dimension; |
| 197 | 179 | value1RowOffset += dimension; | |
| 198 | value0RowOffset += dimension; | 180 | } |
| 199 | value1RowOffset += dimension; | ||
| 200 | 181 | ||
| 201 | } | 182 | if (totalNumPixels > 0) { |
| 202 | 183 | int index; | |
| 203 | 184 | double energySum; | |
| 204 | if (totalNumPixels > 0){ | 185 | double energyDifference; |
| 205 | int index; | 186 | double entropyValue; |
| 206 | double energySum; | 187 | double sumNormalized; |
| 207 | double energyDifference; | 188 | double diffNormalized; |
| 208 | double entropyValue; | 189 | double scale; |
| 209 | double sumNormalized; | 190 | |
| 210 | double diffNormalized; | 191 | energySum = (double)0; |
| 211 | double scale; | 192 | energyDifference = (double)0; |
| 212 | 193 | entropyValue = (double)0; | |
| 213 | energySum = (double) 0; | 194 | scale = 1.e0 / totalNumPixels; |
| 214 | energyDifference = (double) 0; | 195 | for (index = 0; index < numBins; index++) { |
| 215 | entropyValue = (double) 0; | 196 | if (sumHist[index] > 0) { |
| 216 | scale = 1.e0/totalNumPixels; | 197 | sumNormalized = (double)sumHist[index] * scale; |
| 217 | for (index = 0; index<numBins; index++){ | 198 | entropyValue = |
| 218 | if (sumHist[index] > 0){ | 199 | entropyValue - sumNormalized * log((double)sumNormalized); |
| 219 | sumNormalized = (double) sumHist[index]*scale; | 200 | energySum = energySum + sumNormalized * sumNormalized; |
| 220 | entropyValue = entropyValue - sumNormalized * | 201 | } |
| 221 | log((double)sumNormalized); | 202 | if (diffHist[index] > 0) { |
| 222 | energySum = energySum + sumNormalized * sumNormalized ; | 203 | diffNormalized = (double)diffHist[index] * scale; |
| 223 | } | 204 | entropyValue = entropyValue - diffNormalized * log(diffNormalized); |
| 224 | if (diffHist[index] > 0){ | 205 | energyDifference = energyDifference + diffNormalized * diffNormalized; |
| 225 | diffNormalized = (double)diffHist[index]*scale; | ||
| 226 | entropyValue = entropyValue - diffNormalized * log(diffNormalized); | ||
| 227 | energyDifference = energyDifference + | ||
| 228 | diffNormalized * diffNormalized; | ||
| 229 | } | ||
| 230 | } | 206 | } |
| 231 | *energy = energySum * energyDifference; | ||
| 232 | *entropy = entropyValue; | ||
| 233 | } | 207 | } |
| 234 | return; | 208 | *energy = energySum * energyDifference; |
| 235 | } | 209 | *entropy = entropyValue; |
| 236 | |||
| 237 | |||
| 238 | void neighborhoodCalculation | ||
| 239 | (Pixel *image, | ||
| 240 | int dimension, | ||
| 241 | int distanceShort, | ||
| 242 | int distanceLong, | ||
| 243 | Neighborhood *neighborhood, | ||
| 244 | Pixel maxPixel) | ||
| 245 | { | ||
| 246 | int *sumHist, *diffHist; | ||
| 247 | int numBins; | ||
| 248 | |||
| 249 | numBins = (2 * (maxPixel - MIN_PIXEL + 1) -1); | ||
| 250 | sumHist = (int *) malloc(numBins * sizeof(int)); | ||
| 251 | assert (sumHist != NULL); | ||
| 252 | diffHist = (int *)malloc(numBins * sizeof(int)); | ||
| 253 | assert(diffHist != NULL); | ||
| 254 | |||
| 255 | calcEntropyEnergy(sumHist, diffHist, image, numBins, | ||
| 256 | distanceShort, 0, | ||
| 257 | &(neighborhood->distShort.deg0.entropy), | ||
| 258 | &(neighborhood->distShort.deg0.energy), dimension, | ||
| 259 | maxPixel); | ||
| 260 | |||
| 261 | calcEntropyEnergy(sumHist, diffHist, image, numBins, | ||
| 262 | distanceShort, distanceShort, | ||
| 263 | &(neighborhood->distShort.deg45.entropy), | ||
| 264 | &(neighborhood->distShort.deg45.energy), dimension, | ||
| 265 | maxPixel); | ||
| 266 | |||
| 267 | calcEntropyEnergy(sumHist, diffHist, image, numBins, | ||
| 268 | 0, distanceShort, | ||
| 269 | &(neighborhood->distShort.deg90.entropy), | ||
| 270 | &(neighborhood->distShort.deg90.energy), dimension, | ||
| 271 | maxPixel); | ||
| 272 | |||
| 273 | calcEntropyEnergy(sumHist, diffHist, image, numBins, | ||
| 274 | -distanceShort, distanceShort, | ||
| 275 | &(neighborhood->distShort.deg135.entropy), | ||
| 276 | &(neighborhood->distShort.deg135.energy), dimension, | ||
| 277 | maxPixel); | ||
| 278 | |||
| 279 | calcEntropyEnergy(sumHist, diffHist, image, numBins, | ||
| 280 | distanceLong, 0, | ||
| 281 | &(neighborhood->distLong.deg0.entropy), | ||
| 282 | &(neighborhood->distLong.deg0.energy), dimension, | ||
| 283 | maxPixel); | ||
| 284 | |||
| 285 | calcEntropyEnergy(sumHist, diffHist, image, numBins, | ||
| 286 | distanceLong, distanceLong, | ||
| 287 | &(neighborhood->distLong.deg45.entropy), | ||
| 288 | &(neighborhood->distLong.deg45.energy), dimension, | ||
| 289 | maxPixel); | ||
| 290 | |||
| 291 | calcEntropyEnergy(sumHist, diffHist, image, numBins, | ||
| 292 | 0, distanceLong, | ||
| 293 | &(neighborhood->distLong.deg90.entropy), | ||
| 294 | &(neighborhood->distLong.deg90.energy), dimension, | ||
| 295 | maxPixel); | ||
| 296 | |||
| 297 | calcEntropyEnergy(sumHist, diffHist, image, numBins, | ||
| 298 | -distanceLong, distanceLong, | ||
| 299 | &(neighborhood->distLong.deg135.entropy), | ||
| 300 | &(neighborhood->distLong.deg135.energy), dimension, | ||
| 301 | maxPixel); | ||
| 302 | |||
| 303 | free(sumHist); | ||
| 304 | free(diffHist); | ||
| 305 | |||
| 306 | return; | ||
| 307 | } | 210 | } |
| 211 | return; | ||
| 212 | } | ||
| 308 | 213 | ||
| 214 | void neighborhoodCalculation(Pixel *image, int dimension, int distanceShort, | ||
| 215 | int distanceLong, Neighborhood *neighborhood, | ||
| 216 | Pixel maxPixel) { | ||
| 217 | int *sumHist, *diffHist; | ||
| 218 | int numBins; | ||
| 219 | |||
| 220 | numBins = (2 * (maxPixel - MIN_PIXEL + 1) - 1); | ||
| 221 | sumHist = (int *)malloc(numBins * sizeof(int)); | ||
| 222 | assert(sumHist != NULL); | ||
| 223 | diffHist = (int *)malloc(numBins * sizeof(int)); | ||
| 224 | assert(diffHist != NULL); | ||
| 225 | |||
| 226 | calcEntropyEnergy(sumHist, diffHist, image, numBins, distanceShort, 0, | ||
| 227 | &(neighborhood->distShort.deg0.entropy), | ||
| 228 | &(neighborhood->distShort.deg0.energy), dimension, | ||
| 229 | maxPixel); | ||
| 230 | |||
| 231 | calcEntropyEnergy(sumHist, diffHist, image, numBins, distanceShort, | ||
| 232 | distanceShort, &(neighborhood->distShort.deg45.entropy), | ||
| 233 | &(neighborhood->distShort.deg45.energy), dimension, | ||
| 234 | maxPixel); | ||
| 235 | |||
| 236 | calcEntropyEnergy(sumHist, diffHist, image, numBins, 0, distanceShort, | ||
| 237 | &(neighborhood->distShort.deg90.entropy), | ||
| 238 | &(neighborhood->distShort.deg90.energy), dimension, | ||
| 239 | maxPixel); | ||
| 240 | |||
| 241 | calcEntropyEnergy(sumHist, diffHist, image, numBins, -distanceShort, | ||
| 242 | distanceShort, &(neighborhood->distShort.deg135.entropy), | ||
| 243 | &(neighborhood->distShort.deg135.energy), dimension, | ||
| 244 | maxPixel); | ||
| 245 | |||
| 246 | calcEntropyEnergy(sumHist, diffHist, image, numBins, distanceLong, 0, | ||
| 247 | &(neighborhood->distLong.deg0.entropy), | ||
| 248 | &(neighborhood->distLong.deg0.energy), dimension, maxPixel); | ||
| 249 | |||
| 250 | calcEntropyEnergy(sumHist, diffHist, image, numBins, distanceLong, | ||
| 251 | distanceLong, &(neighborhood->distLong.deg45.entropy), | ||
| 252 | &(neighborhood->distLong.deg45.energy), dimension, | ||
| 253 | maxPixel); | ||
| 254 | |||
| 255 | calcEntropyEnergy(sumHist, diffHist, image, numBins, 0, distanceLong, | ||
| 256 | &(neighborhood->distLong.deg90.entropy), | ||
| 257 | &(neighborhood->distLong.deg90.energy), dimension, | ||
| 258 | maxPixel); | ||
| 259 | |||
| 260 | calcEntropyEnergy(sumHist, diffHist, image, numBins, -distanceLong, | ||
| 261 | distanceLong, &(neighborhood->distLong.deg135.entropy), | ||
| 262 | &(neighborhood->distLong.deg135.energy), dimension, | ||
| 263 | maxPixel); | ||
| 264 | |||
| 265 | free(sumHist); | ||
| 266 | free(diffHist); | ||
| 267 | |||
| 268 | return; | ||
| 269 | } | ||
