IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 6, 2005, 6:43:52 PM (21 years ago)
Author:
Paul Price
Message:

Importing current working PAP version (many bug fixes since this branch) straight on top of this version, and tidying up a bit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pois/src/poisFindStamps.c

    r3813 r5717  
    77
    88psArray *poisFindStamps(psArray *stamps, // Existing list of stamps, or NULL
    9                         const psImage *image, // Image for which to find stamps
    10                         const psImage *mask, // Mask image
    11                         const poisConfig *config // Configuration values
     9                        const psImage *image, // Image for which to find stamps
     10                        const psImage *mask, // Mask image
     11                        const poisConfig *config // Configuration values
    1212    )
    1313{
    14     int nx = config->xImage;            // Size of image in x
    15     int ny = config->yImage;            // Size of image in y
     14    int nx = config->xImage;            // Size of image in x
     15    int ny = config->yImage;            // Size of image in y
    1616
    1717    assert(image->numCols == nx && image->numRows == ny);
     
    2121    assert(!stamps || stamps->n == config->nsx * config->nsy);
    2222
    23     float threshold = config->threshold;// Stamp threshold
    24     int footprint = config->footprint;  // Footprint for stamps
     23    int footprint = config->footprint;  // Footprint for stamps
    2524    int borderx = footprint + config->xKernel; // Border around image in x
    2625    int bordery = footprint + config->yKernel; // Border around image in y
    27     int nsx = config->nsx;              // Number of stamps in x
    28     int nsy = config->nsy;              // Number of stamps in y
     26    int nsx = config->nsx;              // Number of stamps in x
     27    int nsy = config->nsy;              // Number of stamps in y
    2928
    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
    3230
    3331    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        }
    3937    }
    4038
     
    4240    int num = 0;
    4341    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
    4944
    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
    9151
    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        }
    9578    } // Done iterating over sections
    9679
    9780    return stamps;
    98 }                                   
     81}
Note: See TracChangeset for help on using the changeset viewer.