IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 27249 for trunk/psLib


Ignore:
Timestamp:
Mar 11, 2010, 9:20:14 AM (16 years ago)
Author:
Paul Price
Message:

Wasn't being rigorous about checking for good pixels: just because
psImageBackground says there were no good pixels doesn't mean there
aren't any (because it samples the image randomly and may miss them).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/fits/psFitsScale.c

    r27097 r27249  
    122122    psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS);
    123123    psStats *stats = psStatsAlloc(MEAN_STAT | STDEV_STAT); // Statistics object
    124     psVector *sample = NULL;                               // Sample of pixels
    125124    double mean, stdev;                                    // Mean and standard deviation
    126     if (!psImageBackground(stats, &sample, image, mask, maskVal, rng)) {
     125    if (!psImageBackground(stats, NULL, image, mask, maskVal, rng)) {
    127126        // It could be because the image is entirely masked, in which case we don't want to error
    128         if (sample->n == 0) {
     127        bool good = false;              // Any good pixels?
     128
     129
     130// Find good pixels in an image, by image type
     131#define GOOD_PIXELS_CASE(TYPE) \
     132      case PS_TYPE_##TYPE: \
     133        for (int y = 0; y < image->numRows && !good; y++) { \
     134            for (int x = 0; x < image->numCols && !good; x++) { \
     135                if (mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal)) { \
     136                    continue; \
     137                } \
     138                if (!isfinite(image->data.TYPE[y][x])) { \
     139                    continue; \
     140                } \
     141                good = true; \
     142            } \
     143        } \
     144        break;
     145
     146        switch (image->type.type) {
     147            GOOD_PIXELS_CASE(F32);
     148            GOOD_PIXELS_CASE(F64);
     149          default:
     150            psAbort("Unsupported case: %x", image->type.type);
     151        }
     152
     153        if (!good) {
    129154            psLogMsg("psLib.fits", PS_LOG_DETAIL, "Image has no good pixels, setting BSCALE = 1, BZERO = 0");
    130155            psErrorClear();
     
    133158            psFree(rng);
    134159            psFree(stats);
    135             psFree(sample);
    136160            return true;
    137161        }
     162
     163        // There are some good pixels in there somewhere; psImageBackground just didn't find them
    138164        psLogMsg("psLib.fits", PS_LOG_DETAIL,
    139165                 "Couldn't measure background statistics for image quantisation; retrying.");
     
    151177                psFree(rng);
    152178                psFree(stats);
    153                 psFree(sample);
    154179                return false;
    155180            } else {
     
    168193        stdev = psStatsGetValue(stats, STDEV_STAT);
    169194    }
    170     psFree(sample);
    171195    psFree(rng);
    172196    psFree(stats);
Note: See TracChangeset for help on using the changeset viewer.