IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 22, 2008, 5:44:05 PM (18 years ago)
Author:
Paul Price
Message:

Removing psFitsScalingMeasure, since psImageBackground removes all non-finite pixels before doing statistics, so that a mask is unnecessary.

File:
1 edited

Legend:

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

    r16185 r16197  
    105105    assert(options);
    106106
    107     double mean = options->mean, stdev = options->stdev; // Mean and standard deviation
     107    // Measure the mean and stdev
     108    // psImageBackground automatically excludes pixels that are non-finite, so we don't need to bother about a
     109    // mask.
     110    psU64 seed = p_psRandomGetSystemSeed(false);
     111    psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, seed);
     112    psStats *stats = psStatsAlloc(MEAN_STAT | STDEV_STAT); // Statistics object
     113    if (!psImageBackground(stats, NULL, image, NULL, 0, rng)) {
     114        psError(PS_ERR_UNKNOWN, false, "Unable to perform statistics on image");
     115        psFree(rng);
     116        psFree(stats);
     117        return false;
     118    }
     119    psFree(rng);
     120
     121    double mean = psStatsGetValue(stats, MEAN_STAT); // Mean
     122    double stdev = psStatsGetValue(stats, STDEV_STAT); // Standard deviation
     123    psFree(stats);
    108124    if (!isfinite(mean) || !isfinite(stdev)) {
    109125        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    110                 "Mean (%f) or stdev (%f) is non-finite. Did you forget to call psFitsScaleMeasure()?",
    111                 mean, stdev);
     126                "Mean (%f) or stdev (%f) is non-finite.", mean, stdev);
    112127        return false;
    113128    }
     
    149164// Public functions
    150165//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    151 
    152 
    153 
    154 // Measure statistics on the image for the PS_FITS_SCALE_STDEV_* scaling options
    155 bool psFitsScaleMeasure(psFits *fits,
    156                         const psImage *image,
    157                         const psImage *mask,
    158                         psMaskType maskVal,
    159                         psRandom *rng // Random number generator, or NULL
    160     )
    161 {
    162     PS_ASSERT_FITS_NON_NULL(fits, false);
    163     PS_ASSERT_IMAGE_NON_NULL(image, false);
    164     // Let psImageBackground worry about the mask
    165     // If we don't have a RNG, we will allocate one
    166 
    167     psFitsOptions *options = fits->options; // FITS options
    168     if (!options) {
    169         // No scaling desired
    170         return true;
    171     }
    172 
    173     if (options->scaling != PS_FITS_SCALE_STDEV_POSITIVE &&
    174         options->scaling != PS_FITS_SCALE_STDEV_NEGATIVE &&
    175         options->scaling != PS_FITS_SCALE_STDEV_BOTH) {
    176         // No need to do anything
    177         return true;
    178     }
    179 
    180     if (!psMemIncrRefCounter(rng)) {
    181         psU64 seed = p_psRandomGetSystemSeed(false);
    182         rng = psRandomAlloc(PS_RANDOM_TAUS, seed);
    183     }
    184 
    185     psStats *stats = psStatsAlloc(MEAN_STAT | STDEV_STAT); // Statistics object
    186     if (!psImageBackground(stats, NULL, image, mask, maskVal, rng)) {
    187         psError(PS_ERR_UNKNOWN, false, "Unable to perform statistics on image");
    188         psFree(rng);
    189         psFree(stats);
    190         return false;
    191     }
    192     psFree(rng);
    193 
    194     options->mean = psStatsGetValue(stats, MEAN_STAT); // Mean
    195     options->stdev = psStatsGetValue(stats, STDEV_STAT); // Standard deviation
    196     psFree(stats);
    197 
    198     return true;
    199 }
    200 
    201166
    202167bool psFitsScaleDetermine(double *bscale, // Scaling, to return
Note: See TracChangeset for help on using the changeset viewer.