Changeset 27097
- Timestamp:
- Feb 25, 2010, 5:05:40 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/fits/psFitsScale.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/fits/psFitsScale.c
r25439 r27097 15 15 #include "psImage.h" 16 16 #include "psFits.h" 17 #include "psStats.h" 18 #include "psImageStats.h" 17 19 #include "psImageBackground.h" 18 #include "psStats.h"19 20 #include "psImageStructManip.h" 20 21 … … 29 30 #define MEAN_STAT PS_STAT_ROBUST_MEDIAN // Statistic to use for mean 30 31 #define STDEV_STAT PS_STAT_ROBUST_STDEV // Statistic to use for stdev 32 33 #define DESPERATE_MEAN_STAT PS_STAT_SAMPLE_MEDIAN // Statistic to use for mean when deperate 34 #define DESPERATE_STDEV_STAT PS_STAT_SAMPLE_QUARTILE // Statistic to use for stdev when desperate 31 35 32 36 … … 118 122 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); 119 123 psStats *stats = psStatsAlloc(MEAN_STAT | STDEV_STAT); // Statistics object 120 if (!psImageBackground(stats, NULL, image, mask, maskVal, rng)) { 121 psError(PS_ERR_UNKNOWN, false, "Unable to perform statistics on image"); 122 psFree(rng); 123 psFree(stats); 124 return false; 125 } 124 psVector *sample = NULL; // Sample of pixels 125 double mean, stdev; // Mean and standard deviation 126 if (!psImageBackground(stats, &sample, image, mask, maskVal, rng)) { 127 // It could be because the image is entirely masked, in which case we don't want to error 128 if (sample->n == 0) { 129 psLogMsg("psLib.fits", PS_LOG_DETAIL, "Image has no good pixels, setting BSCALE = 1, BZERO = 0"); 130 psErrorClear(); 131 *bscale = 1.0; 132 *bzero = 0.0; 133 psFree(rng); 134 psFree(stats); 135 psFree(sample); 136 return true; 137 } 138 psLogMsg("psLib.fits", PS_LOG_DETAIL, 139 "Couldn't measure background statistics for image quantisation; retrying."); 140 psErrorClear(); 141 // Retry using all the available pixels 142 stats->nSubsample = image->numCols * image->numRows + 1; 143 if (!psImageStats(stats, image, mask, maskVal)) { 144 psLogMsg("psLib.fits", PS_LOG_DETAIL, 145 "Couldn't measure background statistics for image quantisation (attempt 2); retrying."); 146 psErrorClear(); 147 // Retry with desperate statistic 148 stats->options = DESPERATE_MEAN_STAT | DESPERATE_STDEV_STAT; 149 if (!psImageStats(stats, image, mask, maskVal)) { 150 psError(PS_ERR_UNKNOWN, false, "Unable to measure background statistics for image"); 151 psFree(rng); 152 psFree(stats); 153 psFree(sample); 154 return false; 155 } else { 156 // Desperate retry 157 mean = psStatsGetValue(stats, DESPERATE_MEAN_STAT); 158 stdev = psStatsGetValue(stats, DESPERATE_STDEV_STAT); 159 } 160 } else { 161 // Retry with all available pixels 162 mean = psStatsGetValue(stats, MEAN_STAT); 163 stdev = psStatsGetValue(stats, STDEV_STAT); 164 } 165 } else { 166 // First attempt 167 mean = psStatsGetValue(stats, MEAN_STAT); 168 stdev = psStatsGetValue(stats, STDEV_STAT); 169 } 170 psFree(sample); 126 171 psFree(rng); 127 128 double mean = psStatsGetValue(stats, MEAN_STAT); // Mean129 double stdev = psStatsGetValue(stats, STDEV_STAT); // Standard deviation130 172 psFree(stats); 131 173 if (!isfinite(mean) || !isfinite(stdev)) {
Note:
See TracChangeset
for help on using the changeset viewer.
