Changeset 5743 for trunk/stac/src/stacScales.c
- Timestamp:
- Dec 7, 2005, 2:57:14 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/stac/src/stacScales.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/stac/src/stacScales.c
r3673 r5743 14 14 assert(image->type.type == PS_TYPE_F32); 15 15 16 // Will use robust median instead of sampling --- it's supposed to be fast.17 16 #if 1 18 17 int size = image->numCols * image->numRows; // Number of pixels in image 19 18 int numSamples = size / sample; // Number of samples in image 20 19 psVector *values = psVectorAlloc(numSamples + 1, PS_TYPE_F32); // Vector containing sub-sample 20 psVector *mask = psVectorAlloc(numSamples + 1, PS_TYPE_U8); // Mask for sample 21 21 22 22 int offset = 0; // Offset from start of the row … … 27 27 while (col < image->numCols) { 28 28 values->data.F32[index] = image->data.F32[row][col]; 29 if (isnan(values->data.F32[index])) { 30 mask->data.U8[index] = 1; 31 } else { 32 mask->data.U8[index] = 0; 33 } 29 34 col += sample; 30 35 index++; … … 34 39 35 40 psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN); 36 stats = psVectorStats(stats, values, NULL, NULL, 0);41 stats = psVectorStats(stats, values, NULL, mask, 1); 37 42 float median = stats->sampleMedian; 38 43 psFree(stats); 39 44 psFree(values); 45 psFree(mask); 40 46 #else 47 // Will use robust median instead of sampling --- it's supposed to be fast. 41 48 psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN); // Using a clipped mean because median is SLOW 42 49 stats->clipSigma = 3.0; … … 162 169 } 163 170 } 164 psTrace("stac.scales", 9, "Star at %f,%f --> %f\n", coords->x, coords->y, sum);165 171 // Subtract background, renormalise to account for circular aperture 166 172 if (numPix > 0 && sum > 0) { 167 173 sum -= offsets->data.F32[i] * (float)numPix; 168 174 photometry->data.F32[j] = sum * M_PI * aper2 / (float)numPix; 175 if (photometry->data.F32[j] > 0 && finite(photometry->data.F32[j])) { 176 mask->data.U8[j] = 1; 177 psTrace("stac.scales", 8, "Star at %f,%f --> %f\n", coords->x, coords->y, sum); 178 } else { 179 mask->data.U8[j] = 0; 180 } 181 } else { 169 182 mask->data.U8[j] = 0; 170 } else {171 mask->data.U8[j] = 1;172 183 } 173 184 } … … 182 193 psVector *ref = stars->data[0]; // The reference photometry 183 194 psVector *refMask = masks->data[0]; // The reference mask 195 #if 0 184 196 psStats *stats = psStatsAlloc(PS_STAT_CLIPPED_MEAN); // Statistics 185 197 stats->clipSigma = 2.5; 186 198 stats->clipIter = 3; 199 #else 200 psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN); // Statistics 201 #endif 187 202 for (int i = 1; i < scales->n; i++) { 188 psVector *compare = stars->data[i]; // The comparison photometry 189 psVector *compareMask = masks->data[i]; // The comparison mask 190 191 compare = (psVector*)psBinaryOp(compare, compare, "/", ref); 192 compareMask = (psVector*)psBinaryOp(compareMask, compareMask, "+", refMask); 193 194 stats = psVectorStats(stats, compare, NULL, compareMask, 3); // Use maskVal of 3 to catch 1 and 2 195 203 psVector *input = stars->data[i]; // The comparison photometry 204 psVector *inputMask = masks->data[i]; // The comparison mask 205 206 psVector *compare = (psVector*)psBinaryOp(NULL, input, "/", ref); 207 psVector *compareMask = (psVector*)psBinaryOp(NULL, inputMask, "*", refMask); 208 (void)psBinaryOp(compareMask, psScalarAlloc(1, PS_TYPE_U8), "-", compareMask); 209 210 #if 0 211 psTrace("stac.scales", 9, "Getting scale for image %d...\n", i); 212 for (int j = 0; j < compare->n; j++) { 213 if (compareMask->data.U8[j] & 1) { 214 psTrace("stac.scales", 9, "Bad star %d: %f %f --> %f %d\n", j, input->data.F32[j], 215 ref->data.F32[j], compare->data.F32[j], compareMask->data.U8[j]); 216 } else { 217 psTrace("stac.scales", 9, "Good star %d: %f %f --> %f %d\n", j, input->data.F32[j], 218 ref->data.F32[j], compare->data.F32[j], compareMask->data.U8[j]); 219 } 220 } 221 #endif 222 223 psVectorStats(stats, compare, NULL, compareMask, 1); 224 225 #if 0 196 226 scales->data.F32[i] = stats->clippedMean; 227 #else 228 scales->data.F32[i] = stats->sampleMedian; 229 #endif 197 230 psTrace("stac.scales", 5, "Scale for image %d is %f\n", i, scales->data.F32[i]); 231 psFree(compare); 232 psFree(compareMask); 198 233 } 199 234 psFree(stats);
Note:
See TracChangeset
for help on using the changeset viewer.
