IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 8, 2004, 3:12:31 PM (22 years ago)
Author:
Paul Price
Message:

More robust gradient measurement

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/stac/src/stacRejection.c

    r2661 r2670  
    1111    )
    1212{
    13     float sum = 0.0;                    // The sum of surrounding pixels
    1413    int num = 0;
    15     psVector *pixels = psVectorAlloc(9, PS_TYPE_F32); // Array of pixels
    16     psVector *mask = psVectorAlloc(9, PS_TYPE_U8); // Corresponding mask
     14    psVector *pixels = psVectorAlloc(8, PS_TYPE_F32); // Array of pixels
     15    psVector *mask = psVectorAlloc(8, PS_TYPE_U8); // Corresponding mask
    1716
    1817    // Get limits
     
    2322    for (int j = yMin; j <= yMax; j++) {
    2423        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
    4335    psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN);
    44     (void)psVectorStats(stats, pixels, mask, 0);
     36    (void)psVectorStats(stats, pixels, mask, 1);
    4537    float median = stats->sampleMedian;
    4638    psFree(stats);
     
    8577                       psImage *combined, // Combined image
    8678                       psArray *maps,   // Maps from input to transformed image
     79                       psArray *inverseMaps, // Maps from transformed to input image
    8780                       psArray *rejected, // Rejected images
    8881                       stacConfig *config // Configuration
     
    167160#ifdef TESTING
    168161                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++;
    175196#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                    }
    178200#endif
    179201                } else {
     
    189211#endif
    190212
    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);
    192214        // Clip the image, and convert to suitable mask format
    193215
Note: See TracChangeset for help on using the changeset viewer.