Changeset 5717 for trunk/pois/src/poisFindStamps.c
- Timestamp:
- Dec 6, 2005, 6:43:52 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/pois/src/poisFindStamps.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pois/src/poisFindStamps.c
r3813 r5717 7 7 8 8 psArray *poisFindStamps(psArray *stamps, // Existing list of stamps, or NULL 9 const psImage *image, // Image for which to find stamps10 const psImage *mask, // Mask image11 const poisConfig *config // Configuration values9 const psImage *image, // Image for which to find stamps 10 const psImage *mask, // Mask image 11 const poisConfig *config // Configuration values 12 12 ) 13 13 { 14 int nx = config->xImage; // Size of image in x15 int ny = config->yImage; // Size of image in y14 int nx = config->xImage; // Size of image in x 15 int ny = config->yImage; // Size of image in y 16 16 17 17 assert(image->numCols == nx && image->numRows == ny); … … 21 21 assert(!stamps || stamps->n == config->nsx * config->nsy); 22 22 23 float threshold = config->threshold;// Stamp threshold 24 int footprint = config->footprint; // Footprint for stamps 23 int footprint = config->footprint; // Footprint for stamps 25 24 int borderx = footprint + config->xKernel; // Border around image in x 26 25 int bordery = footprint + config->yKernel; // Border around image in y 27 int nsx = config->nsx; // Number of stamps in x28 int nsy = config->nsy; // Number of stamps in y26 int nsx = config->nsx; // Number of stamps in x 27 int nsy = config->nsy; // Number of stamps in y 29 28 30 psF32 **pixels = image->data.F32; // The image pixels 31 psU8 **maskpix = mask->data.U8; // The mask pixels 29 psF32 **pixels = image->data.F32; // The image pixels 32 30 33 31 if (stamps == NULL) { 34 stamps = psArrayAlloc(nsx * nsy);35 // Initialise; should be done by psArrayAlloc 36 for (int i = 0; i < nsx * nsy; i++) {37 stamps->data[i] = NULL;38 }32 stamps = psArrayAlloc(nsx * nsy); 33 // Initialise 34 for (int i = 0; i < nsx * nsy; i++) { 35 stamps->data[i] = poisStampAlloc(); 36 } 39 37 } 40 38 … … 42 40 int num = 0; 43 41 for (int i = 0; i < nsx; i++) { 44 for (int j = 0; j < nsy; j++) { 45 poisStamp *stamp = stamps->data[num]; // The stamp 46 if (stamp == NULL) { 47 stamp = stamps->data[num] = poisStampAlloc(); 48 } 42 for (int j = 0; j < nsy; j++) { 43 poisStamp *stamp = stamps->data[num]; // The stamp 49 44 50 // Only find a new stamp if we need to 51 if (stamp->status == POIS_STAMP_RESET) { 52 // Find maximum non-masked value in the image section, but don't include a footprint around 53 // the edge 54 float max = - INFINITY; // Negative infinity 55 int bestx = 0, besty = 0; // Position of maximum 56 57 for (int y = bordery + j * (ny - 2.0 * bordery) / nsy; 58 y < bordery + (j + 1) * (ny - 2.0 * bordery) / nsy; y++) { 59 for (int x = borderx + i * (nx - 2.0 * borderx) / nsx; 60 x < borderx + (i + 1) * (nx - 2.0 * borderx) / nsx; x++) { 61 if (pixels[y][x] > max && pixels[y][x] >= threshold) { 62 // Check the footprint 63 int ok = 1; 64 for (int v = y - footprint; v <= y + footprint && ok; v++) { 65 for (int u = x - footprint; u <= x + footprint && ok; u++) { 66 if (maskpix[v][u] & 67 (POIS_MASK_BAD | POIS_MASK_NEAR_BAD | POIS_MASK_STAMP)) { 68 ok = 0; 69 } 70 } 71 } 72 if (ok) { 73 max = pixels[y][x]; 74 bestx = x; 75 besty = y; 76 } 77 } // Done checking the candidate pixel 78 } 79 } // Done iterating over this image section 80 81 // Store the stamp 82 if (max != - INFINITY) { 83 stamp->x = bestx; 84 stamp->y = besty; 85 stamp->status = POIS_STAMP_RECALC; 86 } else { 87 // No stamp in this section 88 stamp->status = POIS_STAMP_BAD; 89 } 90 } // Finding a new stamp 45 // Only find a new stamp if we need to 46 if ((stamp->x == 0 && stamp->y == 0) || stamp->status == POIS_STAMP_RESET) { 47 // Find maximum non-masked value in the image section, but don't include a footprint around 48 // the edge 49 float max = - INFINITY; // Negative infinity 50 int bestx = 0, besty = 0; // Position of maximum 91 51 92 psTrace("pois.findStamps", 7, "Stamp %d: %d,%d\n", num, stamp->x, stamp->y); 93 num++; 94 } 52 for (int y = bordery + j * (ny - 2.0 * bordery) / nsy; 53 y < bordery + (j + 1) * (ny - 2.0 * bordery) / nsy; y++) { 54 for (int x = borderx + i * (nx - 2.0 * borderx) / nsx; 55 x < borderx + (i + 1) * (nx - 2.0 * borderx) / nsx; x++) { 56 if (pixels[y][x] > max && poisCheckStamp(image, mask, x, y, config)) { 57 max = pixels[y][x]; 58 bestx = x; 59 besty = y; 60 } 61 } 62 } // Done iterating over this image section 63 64 // Store the stamp 65 if (max != - INFINITY) { 66 stamp->x = bestx; 67 stamp->y = besty; 68 stamp->status = POIS_STAMP_RECALC; 69 } else { 70 // No stamp in this section 71 stamp->status = POIS_STAMP_BAD; 72 } 73 } // Finding a new stamp 74 75 psTrace("pois.findStamps", 7, "Stamp %d: %d,%d\n", num, stamp->x, stamp->y); 76 num++; 77 } 95 78 } // Done iterating over sections 96 79 97 80 return stamps; 98 } 81 }
Note:
See TracChangeset
for help on using the changeset viewer.
