Changeset 16197 for trunk/psLib/src/fits/psFitsScale.c
- Timestamp:
- Jan 22, 2008, 5:44:05 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/fits/psFitsScale.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/fits/psFitsScale.c
r16185 r16197 105 105 assert(options); 106 106 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); 108 124 if (!isfinite(mean) || !isfinite(stdev)) { 109 125 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); 112 127 return false; 113 128 } … … 149 164 // Public functions 150 165 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 151 152 153 154 // Measure statistics on the image for the PS_FITS_SCALE_STDEV_* scaling options155 bool psFitsScaleMeasure(psFits *fits,156 const psImage *image,157 const psImage *mask,158 psMaskType maskVal,159 psRandom *rng // Random number generator, or NULL160 )161 {162 PS_ASSERT_FITS_NON_NULL(fits, false);163 PS_ASSERT_IMAGE_NON_NULL(image, false);164 // Let psImageBackground worry about the mask165 // If we don't have a RNG, we will allocate one166 167 psFitsOptions *options = fits->options; // FITS options168 if (!options) {169 // No scaling desired170 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 anything177 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 object186 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); // Mean195 options->stdev = psStatsGetValue(stats, STDEV_STAT); // Standard deviation196 psFree(stats);197 198 return true;199 }200 201 166 202 167 bool psFitsScaleDetermine(double *bscale, // Scaling, to return
Note:
See TracChangeset
for help on using the changeset viewer.
