Changeset 2764 for trunk/stac/src/stacRejection.c
- Timestamp:
- Dec 20, 2004, 6:15:28 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/stac/src/stacRejection.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/stac/src/stacRejection.c
r2751 r2764 42 42 } 43 43 44 #if 045 float stacGradient(psImage *image, // Input for which to measure the gradient46 int x, int y // Coordinates at which to measure the gradient47 )48 {49 float sum = 0.0; // The sum of surrounding pixels50 float maxDiff = 0.0;51 int num = 0;52 // Get limits53 int xMin = MAX(x - 1, 0);54 int xMax = MIN(x + 1, image->numCols - 1);55 int yMin = MAX(y - 1, 0);56 int yMax = MIN(y + 1, image->numRows - 1);57 for (int j = yMin; j <= yMax; j++) {58 for (int i = xMin; i <= xMax; i++) {59 if (image->data.F32[j][i] - image->data.F32[y][x] < maxDiff) {60 maxDiff = image->data.F32[j][i] - image->data.F32[y][x];61 }62 sum += image->data.F32[j][i];63 num++;64 }65 }66 sum -= image->data.F32[y][x];67 sum /= (float)(num-1);68 sum -= image->data.F32[y][x];69 // return sum / image->data.F32[y][x];70 return maxDiff / image->data.F32[y][x];71 }72 #endif73 74 75 44 psArray *stacRejection(psArray *inputs, // Input images 76 psArray * transformed, // Transformed images77 ps Image *combined, // Combined image45 psArray *rejected, // Rejected images 46 psArray *regions, // Regions of interest 78 47 psArray *maps, // Maps from input to transformed image 79 48 psArray *inverseMaps, // Maps from transformed to input image 80 psArray *rejected, // Rejected images81 49 stacConfig *config // Configuration 82 50 ) … … 85 53 86 54 // Check inputs 87 if (inputs->n != transformed->n) { 88 psError("stac.rejection", "Number of input (%d) and transformed (%d) images does not match.\n", 89 inputs->n, transformed->n); 55 if (inputs->n != rejected->n) { 56 psError("stac.rejection", "Number of input images (%d) and rejection masks (%d) does not match.\n", 57 inputs->n, rejected->n); 58 return NULL; 59 } 60 if (inputs->n != regions->n) { 61 psError("stac.rejection", "Number of input images (%d) and region masks (%d) does not match.\n", 62 inputs->n, regions->n); 63 return NULL; 64 } 65 if (inputs->n != maps->n) { 66 psError("stac.rejection", "Number of input images (%d) and transformation maps (%d) does " 67 "not match.\n", inputs->n, maps->n); 68 return NULL; 69 } 70 if (inputs->n != inverseMaps->n) { 71 psError("stac.rejection", "Number of input images (%d) and inverse transformation maps (%d) does " 72 "not match.\n", inputs->n, inverseMaps->n); 90 73 return NULL; 91 74 } 92 75 for (int i = 0; i < nImages; i++) { 93 if ((((psImage*)( transformed->data[i]))->numRows != combined->numRows) ||94 (((psImage*)( transformed->data[i]))->numCols != combined->numCols)) {76 if ((((psImage*)(inputs->data[i]))->numRows != ((psImage*)(regions->data[i]))->numRows) || 77 (((psImage*)(inputs->data[i]))->numCols != ((psImage*)(regions->data[i]))->numCols)) { 95 78 psError("stac.rejection", 96 "Sizes of transformed (%dx%d) and combined (%dx%d) imagesdo not match.\n",97 ((psImage*)( transformed->data[i]))->numCols, ((psImage*)(transformed->data[i]))->numRows,98 combined->numCols, combined->numRows);79 "Sizes of input image (%dx%d) and region mask (%dx%d) for input %d do not match.\n", 80 ((psImage*)(inputs->data[i]))->numCols, ((psImage*)(inputs->data[i]))->numRows, 81 ((psImage*)(regions->data[i]))->numCols, ((psImage*)(regions->data[i]))->numRows, i); 99 82 return NULL; 100 83 } 101 if ((((psImage*)(transformed->data[i]))->numRows != ((psImage*)(rejected->data[i]))->numRows) || 102 (((psImage*)(transformed->data[i]))->numCols != ((psImage*)(rejected->data[i]))->numCols)) { 103 psError("stac.rejection", 104 "Sizes of transformed (%dx%d) and rejected (%dx%d) images do not match.\n", 105 ((psImage*)(transformed->data[i]))->numCols, ((psImage*)(transformed->data[i]))->numRows, 106 ((psImage*)(rejected->data[i]))->numCols, ((psImage*)(rejected->data[i]))->numRows); 107 return NULL; 108 } 109 } 110 111 // Size of output images 112 int nxOutput = combined->numCols; 113 int nyOutput = combined->numRows; 84 } 114 85 115 86 // Stuff for the transformations … … 132 103 psImage *reject = rejected->data[i]; // Pull out the mask in the output frame 133 104 psPlaneTransform *map = maps->data[i]; // The map from input to output 105 psImage *region = regions->data[i]; // The region of interest for this image 134 106 135 107 psTrace("stac.rejection", 3, "Transforming rejection mask %d....\n", i); … … 153 125 for (int y = 0; y < nyInput; y++) { 154 126 for (int x = 0; x < nxInput; x++) { 155 inCoords->x = (double)x; 156 inCoords->y = (double)y; 157 (void)psPlaneTransformApply(outCoords, map, inCoords); 158 float maskVal = (float)psImagePixelInterpolate(reject, outCoords->x, outCoords->y, 159 NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR); 127 128 // Only transform pixels of interest 129 if (region->data.U8[y][x]) { 130 131 inCoords->x = (double)x; 132 inCoords->y = (double)y; 133 (void)psPlaneTransformApply(outCoords, map, inCoords); 134 float maskVal = (float)psImagePixelInterpolate(reject, outCoords->x, outCoords->y, 135 NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR); 160 136 #ifdef TESTING 161 rejmap->data.F32[y][x] = maskVal; 162 #endif 163 164 #ifdef TESTING 165 // Check gradient 166 float meanGrads = 0.0; 167 int numGrads = 0; 168 for (int j = 0; j < nImages; j++) { 169 if (i != j) { 170 // Get coordinates for that image 171 (void)psPlaneTransformApply(inCoords, inverseMaps->data[j], outCoords); 172 int xPix = (int)(inCoords->x + 0.5); 173 int yPix = (int)(inCoords->y + 0.5); 174 if ((xPix >= 0) && (xPix <= ((psImage*)(inputs->data[j]))->numCols - 1) && 175 (yPix >= 0) && (yPix <= ((psImage*)(inputs->data[j]))->numRows - 1)) { 176 // Calculate the gradient 177 meanGrads += stacGradient(inputs->data[j], xPix, yPix); 178 numGrads++; 137 rejmap->data.F32[y][x] = maskVal; 138 139 // Calculate gradient 140 float meanGrads = 0.0; 141 int numGrads = 0; 142 for (int j = 0; j < nImages; j++) { 143 if (i != j) { 144 // Get coordinates for that image 145 (void)psPlaneTransformApply(inCoords, inverseMaps->data[j], outCoords); 146 int xPix = (int)(inCoords->x + 0.5); 147 int yPix = (int)(inCoords->y + 0.5); 148 if ((xPix >= 0) && (xPix <= ((psImage*)(inputs->data[j]))->numCols - 1) && 149 (yPix >= 0) && (yPix <= ((psImage*)(inputs->data[j]))->numRows - 1)) { 150 // Calculate the gradient 151 meanGrads += stacGradient(inputs->data[j], xPix, yPix); 152 numGrads++; 153 } 179 154 } 180 155 } 181 } 182 if (numGrads > 0) { 183 meanGrads /= (float)numGrads; 184 } else { 185 meanGrads = 0; 186 } 187 #else 188 float meanGrads = 10000.0; 189 #endif 190 191 192 #ifdef TESTING 193 grad->data.F32[y][x] = stacGradient(inputs->data[i], x, y) / meanGrads; 194 #endif 195 if (maskVal > config->frac) { 156 if (numGrads > 0) { 157 meanGrads /= (float)numGrads; 158 } else { 159 meanGrads = 0; 160 } 161 grad->data.F32[y][x] = stacGradient(inputs->data[i], x, y) / meanGrads; 162 #endif 196 163 197 164 if ((maskVal > config->frac) && … … 200 167 nBad++; 201 168 #ifdef CRFLUX 202 fprintf(crs, "%d %d --> %f %f %f\n", x, y, ((psImage*)(inputs->data[i]))->data.F32[y][x], 203 maskVal, stacGradient(inputs->data[i], x, y)); 204 #endif 169 fprintf(crs, "%d %d --> %f %f %f\n", x, y, 170 ((psImage*)(inputs->data[i]))->data.F32[y][x], maskVal, 171 stacGradient(inputs->data[i], x, y)); 172 #endif 173 } else { 174 mask->data.U8[y][x] = 0; 205 175 } 206 } else { 207 mask->data.U8[y][x] = 0; 208 } 176 177 } // Only touching pixels of interest 209 178 210 179 }
Note:
See TracChangeset
for help on using the changeset viewer.
