Changeset 2670 for trunk/stac/src/stacRejection.c
- Timestamp:
- Dec 8, 2004, 3:12:31 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/stac/src/stacRejection.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/stac/src/stacRejection.c
r2661 r2670 11 11 ) 12 12 { 13 float sum = 0.0; // The sum of surrounding pixels14 13 int num = 0; 15 psVector *pixels = psVectorAlloc( 9, PS_TYPE_F32); // Array of pixels16 psVector *mask = psVectorAlloc( 9, PS_TYPE_U8); // Corresponding mask14 psVector *pixels = psVectorAlloc(8, PS_TYPE_F32); // Array of pixels 15 psVector *mask = psVectorAlloc(8, PS_TYPE_U8); // Corresponding mask 17 16 18 17 // Get limits … … 23 22 for (int j = yMin; j <= yMax; j++) { 24 23 for (int i = xMin; i <= xMax; i++) { 25 sum += image->data.F32[j][i]; 26 pixels->data.F32[num] = image->data.F32[j][i]; 27 mask->data.U8[num] = 1; 28 num++; 29 } 30 } 31 #if 0 32 sum -= image->data.F32[y][x]; 33 sum /= (float)(num-1); 34 // sum -= image->data.F32[y][x]; 35 return sum / image->data.F32[y][x]; 36 #endif 37 38 // Fill out the array 39 for (int i = num; i < 9; i++) { 40 pixels->data.F32[i] = 0; 41 mask->data.U8[i] = 0; 42 } 24 if ((i != x) && (j != y)) { 25 pixels->data.F32[num] = image->data.F32[j][i]; 26 mask->data.U8[num] = 0; 27 num++; 28 } 29 } 30 } 31 pixels->n = num; 32 mask->n = num; 33 34 // Get the median 43 35 psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN); 44 (void)psVectorStats(stats, pixels, mask, 0);36 (void)psVectorStats(stats, pixels, mask, 1); 45 37 float median = stats->sampleMedian; 46 38 psFree(stats); … … 85 77 psImage *combined, // Combined image 86 78 psArray *maps, // Maps from input to transformed image 79 psArray *inverseMaps, // Maps from transformed to input image 87 80 psArray *rejected, // Rejected images 88 81 stacConfig *config // Configuration … … 167 160 #ifdef TESTING 168 161 rejmap->data.F32[y][x] = maskVal; 169 grad->data.F32[y][x] = stacGradient(inputs->data[i], x, y); 170 #endif 171 // Check threshold, then check gradient 172 if ((maskVal > config->frac) && (stacGradient(inputs->data[i], x, y) < config->grad)) { 173 mask->data.U8[y][x] = 1; 174 nBad++; 162 #endif 163 164 // Check gradient 165 float meanGrads = 0.0; 166 int numGrads = 0; 167 for (int j = 0; j < nImages; j++) { 168 if (i != j) { 169 // Get coordinates for that image 170 (void)psPlaneTransformApply(inCoords, inverseMaps->data[j], outCoords); 171 int xPix = (int)(inCoords->x + 0.5); 172 int yPix = (int)(inCoords->y + 0.5); 173 if ((xPix >= 0) && (xPix <= ((psImage*)(inputs->data[j]))->numCols - 1) && 174 (yPix >= 0) && (yPix <= ((psImage*)(inputs->data[j]))->numRows - 1)) { 175 // Calculate the gradient 176 meanGrads += stacGradient(inputs->data[j], xPix, yPix); 177 numGrads++; 178 } 179 } 180 } 181 if (numGrads > 0) { 182 meanGrads /= (float)numGrads; 183 } else { 184 meanGrads = 0; 185 } 186 187 #ifdef TESTING 188 grad->data.F32[y][x] = stacGradient(inputs->data[i], x, y) / meanGrads; 189 #endif 190 if (maskVal > config->frac) { 191 192 if ((maskVal > config->frac) && 193 (stacGradient(inputs->data[i], x, y)) < config->grad * meanGrads) { 194 mask->data.U8[y][x] = 1; 195 nBad++; 175 196 #ifdef CRFLUX 176 fprintf(crs, "%d %d --> %f %f %f\n", x, y, ((psImage*)(inputs->data[i]))->data.F32[y][x], 177 maskVal, stacGradient(inputs->data[i], x, y)); 197 fprintf(crs, "%d %d --> %f %f %f\n", x, y, ((psImage*)(inputs->data[i]))->data.F32[y][x], 198 maskVal, stacGradient(inputs->data[i], x, y)); 199 } 178 200 #endif 179 201 } else { … … 189 211 #endif 190 212 191 psTrace("stac.rejection", 1, "%d pixels masked in image %d .\n", nBad, i);213 psTrace("stac.rejection", 1, "%d pixels masked in image %d\n", nBad, i); 192 214 // Clip the image, and convert to suitable mask format 193 215
Note:
See TracChangeset
for help on using the changeset viewer.
