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/poisRejectStamps.c

    r3875 r5717  
    66#define SQUARE(x) ((x)*(x))
    77
    8 psList *restrict poisRejectStamps(psArray *stamps, // Array of stamps
    9                                   psImage *mask,        // Mask image
    10                                   const psVector *deviations, // Vector of deviations for the stamps
    11                                   const poisConfig *config // Configuration
     8bool poisRejectStamps(psArray *stamps, // Array of stamps
     9                      psImage *mask,    // Mask image
     10                      const psVector *deviations, // Vector of deviations for the stamps
     11                      const poisConfig *config // Configuration
    1212    )
    1313{
     
    2121    assert(deviations->type.type == PS_TYPE_F32);
    2222
    23     psVector *devMask = psVectorAlloc(stamps->n, PS_TYPE_U8); // Mask for statistics
     23    bool masked = false;                // Have we masked any stamps?
    2424
    2525    // Don't want the standard deviation, but rather the deviation from zero
    26     double meanDev = 0.0;
     26    double sum = 0.0;
    2727    int numDev = 0;
    2828    for (int i = 0; i < deviations->n; i++) {
    29         poisStamp *stamp = stamps->data[i];     // The stamp
    30         // Only interested in the stamps that we're actually using
    31         if (stamp != NULL && stamp->status == POIS_STAMP_USED) {
    32             meanDev += SQUARE(deviations->data.F32[i]);
    33             numDev++;
    34         }
     29        poisStamp *stamp = stamps->data[i];     // The stamp
     30        // Only interested in the stamps that we're actually using
     31        if (stamp->status == POIS_STAMP_USED) {
     32            sum += SQUARE(deviations->data.F32[i]);
     33            numDev++;
     34        }
    3535    }
    36     float rmsDev = sqrt(meanDev/numDev);
    37     float limit = rmsDev * config->sigmaRej;
    38     psTrace("pois.rejectStamps", 2, "RMS deviation: %f\n", rmsDev);
     36    float meanDev = sqrtf(sum / (float)numDev);
     37    float limit = meanDev * config->sigmaRej;
     38    psTrace("pois.rejectStamps", 2, "Mean RMS deviation: %f\n", meanDev);
    3939    psTrace("pois.rejectStamps", 2, "Rejection limit: %f\n", limit);
    4040
    4141    // Reject stamps
    42     psList *rejected = NULL;            // rejected stamps
    4342    for (int s = 0; s < deviations->n; s++) {
    44         poisStamp *stamp = stamps->data[s];
    45         if (stamp == NULL) {
    46             continue;
    47         }
    48        
    49         if (stamp->status == POIS_STAMP_USED && fabsf(deviations->data.F32[s]) > limit) {
    50             psTrace("pois.rejectStamps", 1, "Rejecting stamp %d (%d,%d): %f\n", s, stamp->x, stamp->y,
    51                     deviations->data.F32[s]);
    52            
    53             // Mask out the stamp in the image so you don't find it again
    54             for (int y = stamp->y - config->footprint; y < stamp->y + config->footprint; y++) {
    55                 for (int x = stamp->x - config->footprint; x < stamp->x + config->footprint; x++) {
    56                     mask->data.U8[y][x] |= POIS_MASK_STAMP;
    57                 }
    58             }
    59            
    60             // Mark stamp for replacement
    61             stamps->data[s] = NULL;
    62            
    63             if (rejected == NULL) {
    64                 rejected = psListAlloc(stamp);
    65             } else {
    66                 bool success = psListAdd(rejected, PS_LIST_TAIL, stamp);
    67                 assert(success);
    68             }
    69             psFree(stamp);
    70         } // Bad stamps
     43        poisStamp *stamp = stamps->data[s];
     44        if (stamp->status == POIS_STAMP_USED &&
     45            (fabsf(deviations->data.F32[s]) > limit || ! isfinite(deviations->data.F32[s]))) {
     46            masked = true;
     47            psTrace("pois.rejectStamps", 1, "Rejecting stamp %d (%d,%d): %f\n", s, stamp->x, stamp->y,
     48                    deviations->data.F32[s]);
     49
     50            // Mask out the stamp in the image so you don't find it again
     51            for (int y = stamp->y - config->footprint; y < stamp->y + config->footprint; y++) {
     52                for (int x = stamp->x - config->footprint; x < stamp->x + config->footprint; x++) {
     53                    mask->data.U8[y][x] |= POIS_MASK_STAMP;
     54                }
     55            }
     56
     57            // Set stamp for replacement
     58            stamp->x = 0;
     59            stamp->y = 0;
     60            stamp->status = POIS_STAMP_RESET;
     61
     62        } // Bad stamps
    7163    } // Iterating over stamps
    7264
    73     psFree(devMask);
    74 
    75     return rejected;
     65    return masked;
    7666}
Note: See TracChangeset for help on using the changeset viewer.