IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 24, 2010, 3:13:33 PM (16 years ago)
Author:
Paul Price
Message:

Better measurement of the background when the mask fraction is such that the number of good pixels is less than the subset size. Still not happy with the solution for when there's slightly more good pixels than the subset size, but the mask fraction is large. That probably requires a second pass.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/imageops/psImageBackground.c

    r26451 r27066  
    4646    long ny = image->numRows;
    4747
    48     const int Npixels = nx*ny;                // Total number of pixels
     48    psImage *bad = psImageAlloc(nx, ny, PS_TYPE_U8); // Image with bad pixels
     49    psImageInit(bad, 0);
     50
     51    int Npixels;                        // Total number of pixels
     52    for (int y = 0; y < ny; y++) {
     53        for (int x = 0; x < nx; x++) {
     54            if (!isfinite(image->data.F32[iy][ix]) ||
     55                (mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskValue)) {
     56                bad->data.U8[y][x] = 0xFF;
     57            }
     58            Npixels++;
     59        }
     60    }
     61
    4962    const int Nsubset = (stats->nSubsample == 0) ? Npixels : PS_MIN(stats->nSubsample, Npixels); // Number of pixels in subset
    5063
     
    6578    long n = 0;                         // Number of actual pixels in subset
    6679    if (Nsubset >= Npixels) {
    67         // if we have an image smaller than Nsubset, just loop over the image pixels
    68         for (int iy = 0; iy < ny; iy++) {
    69             for (int ix = 0; ix < nx; ix++) {
    70                 if (!isfinite(image->data.F32[iy][ix]) || (mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskValue)) {
    71                     continue;
    72                 }
     80        // if we have an image smaller than Nsubset, just loop over the (good) image pixels
     81        for (int iy = 0; iy < ny; iy++) {
     82            for (int ix = 0; ix < nx; ix++) {
     83                if (bad->data.U8[iy][ix]) {
     84                    continue;
     85                }
    7386
    74                 float value = image->data.F32[iy][ix];
    75                 min = PS_MIN(value, min);
    76                 max = PS_MAX(value, max);
    77                 values->data.F32[n] = value;
    78                 n++;
    79             }
    80         }
     87                float value = image->data.F32[iy][ix];
     88                min = PS_MIN(value, min);
     89                max = PS_MAX(value, max);
     90                values->data.F32[n] = value;
     91                n++;
     92            }
     93        }
    8194    } else {
    82         for (long i = 0; i < Nsubset; i++) {
    83             double frnd = psRandomUniform(rng);
    84             int pixel = Npixels * frnd;
    85             int ix = pixel % nx;
    86             int iy = pixel / nx;
     95        // Subsample all pixels
     96        // This is not optimal, since there may be a large masked fraction that leaves us with few good pixels.
     97        // In that case, you should have set Nsubset.......
     98        Npixels = nx * ny;
     99        for (long i = 0; i < Nsubset; i++) {
     100            double frnd = psRandomUniform(rng);
     101            int pixel = Npixels * frnd;
     102            int ix = pixel % nx;
     103            int iy = pixel / nx;
    87104
    88             if (!isfinite(image->data.F32[iy][ix]) || (mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskValue)) {
    89                 continue;
    90             }
     105            if (bad->data.U8[iy][ix]) {
     106                continue;
     107            }
    91108
    92             float value = image->data.F32[iy][ix];
    93             min = PS_MIN(value, min);
    94             max = PS_MAX(value, max);
    95             values->data.F32[n] = value;
    96             n++;
    97         }
     109            float value = image->data.F32[iy][ix];
     110            min = PS_MIN(value, min);
     111            max = PS_MAX(value, max);
     112            values->data.F32[n] = value;
     113            n++;
     114        }
    98115    }
     116
     117    psFree(bad);
     118
    99119    if (n < 0.01*Nsubset) {
    100         if ((nFailures < 3) || (nFailures % 100 == 0)) {
    101             psLogMsg("psLib.psImageBackground", PS_LOG_DETAIL, "Unable to measure image background: too few data points (%ld) (%d failures)", n, nFailures);
    102         }
    103         nFailures ++;
     120        if ((nFailures < 3) || (nFailures % 100 == 0)) {
     121            psLogMsg("psLib.psImageBackground", PS_LOG_DETAIL, "Unable to measure image background: too few data points (%ld) (%d failures)", n, nFailures);
     122        }
     123        nFailures ++;
    104124        psFree(values);
    105125        return false;
     
    117137
    118138        if (!psVectorSort(values, values)) {
    119             if ((nFailures < 3) || (nFailures % 100 == 0)) {
    120                 psError(PS_ERR_UNKNOWN, false, "Unable to sort values.(%d failures)\n", nFailures);
    121             }
    122             nFailures ++;
     139            if ((nFailures < 3) || (nFailures % 100 == 0)) {
     140                psError(PS_ERR_UNKNOWN, false, "Unable to sort values.(%d failures)\n", nFailures);
     141            }
     142            nFailures ++;
    123143            psFree(values);
    124144            return false;
     
    144164                fclose (f);
    145165            }
    146             if ((nFailures < 3) || (nFailures % 100 == 0)) {
    147                 psError(PS_ERR_UNKNOWN, false, "Unable to measure statistics for image background "
    148                         "(%dx%d, (row0,col0) = (%d,%d) (%d failures)\n",
    149                         image->numRows, image->numCols, image->row0, image->col0, nFailures);
    150             }           
    151             nFailures ++;
     166            if ((nFailures < 3) || (nFailures % 100 == 0)) {
     167                psError(PS_ERR_UNKNOWN, false, "Unable to measure statistics for image background "
     168                        "(%dx%d, (row0,col0) = (%d,%d) (%d failures)\n",
     169                        image->numRows, image->numCols, image->row0, image->col0, nFailures);
     170            }
     171            nFailures ++;
    152172            psFree(values);
    153173            return false;
Note: See TracChangeset for help on using the changeset viewer.