Changeset 16626
- Timestamp:
- Feb 22, 2008, 5:00:30 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/imcombine/pmStack.c (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmStack.c
r16624 r16626 8 8 * @author GLG, MHPCC 9 9 * 10 * @version $Revision: 1.2 1$ $Name: not supported by cvs2svn $11 * @date $Date: 2008-02-23 0 2:33:59$10 * @version $Revision: 1.22 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2008-02-23 03:00:30 $ 12 12 * Copyright 2004-2007 Institute for Astronomy, University of Hawaii 13 13 * … … 43 43 psVector *pixels; // Pixel values 44 44 psVector *masks; // Pixel masks 45 psVector *weights; // Pixel weights 45 psVector *variances; // Pixel variances 46 psVector *weights; // Pixel weightings 46 47 psVector *sources; // Pixel sources (which image did they come from?) 47 48 psVector *sort; // Buffer for sorting (to get a robust estimator of the standard dev) … … 52 53 psFree(buffer->pixels); 53 54 psFree(buffer->masks); 55 psFree(buffer->variances); 54 56 psFree(buffer->weights); 55 57 psFree(buffer->sources); … … 67 69 buffer->pixels = psVectorAlloc(numImages, PS_TYPE_F32); 68 70 buffer->masks = psVectorAlloc(numImages, PS_TYPE_MASK); 71 buffer->variances = psVectorAlloc(numImages, PS_TYPE_F32); 69 72 buffer->weights = psVectorAlloc(numImages, PS_TYPE_F32); 70 73 buffer->sources = psVectorAlloc(numImages, PS_TYPE_U16); … … 84 87 85 88 // Generate a mean value for the combination 86 // Not using psVectorStats because it assumes that the weightsare errors, and weights by 1/error^289 // Not using psVectorStats because it assumes that the "weights" are errors, and weights by 1/error^2 87 90 static bool combinationMean(float *mean, // Mean value, to return 88 91 const psVector *values, // Values to combine … … 216 219 } 217 220 218 // Common path for a bad combined pixel219 static inline bool combineBad(psImage *image, // Combined image220 psImage *mask, // Combined mask221 psImage *weight, // Combined variance map222 int x, int y, // Coordinates of interest223 psMaskType bad // Value for bad pixels224 )225 {226 image->data.F32[y][x] = NAN;227 if (weight) {228 weight->data.F32[y][x] = NAN;229 }230 mask->data.PS_TYPE_MASK_DATA[y][x] = bad;231 return false;232 }233 221 234 222 // Mark a pixel for inspection … … 250 238 static void combinePixels(psImage *image, // Combined image, for output 251 239 psImage *mask, // Combined mask, for output 252 psImage * weight, // Combined variance map, for output240 psImage *variance, // Combined variance map, for output 253 241 const psArray *inputs, // Stack data 254 242 const psVector *weights, // Global (single value) weights for data, or NULL … … 271 259 assert(rej > 0); 272 260 assert(buffer); 273 assert((useVariance && weight) || !useVariance);261 assert((useVariance && variance) || !useVariance); 274 262 275 263 psVector *pixelData = buffer->pixels; // Values for the pixel of interest 276 264 psVector *pixelMasks = buffer->masks; // Masks for the pixel of interest 277 psVector *pixelWeights = buffer->weights; // Weights for the pixel of interest 265 psVector *pixelVariances = buffer->variances; // Variances for the pixel of interest 266 psVector *pixelWeights = buffer->weights; // Image weights for the pixel of interest 278 267 psVector *pixelSources = buffer->sources; // Sources for the pixel of interest 279 268 psVector *sort = buffer->sort; // Sort buffer … … 301 290 302 291 psImage *image = data->readout->image; // Image of interest 303 psImage * weight = data->readout->weight; // Weightmap of interest292 psImage *variance = data->readout->weight; // Variance ("weight") map of interest 304 293 pixelData->data.F32[num] = image->data.F32[yIn][xIn]; 305 if (weight) { 306 pixelWeights->data.F32[num] = weight->data.F32[yIn][xIn]; 307 } 294 if (variance) { 295 pixelVariances->data.F32[num] = variance->data.F32[yIn][xIn]; 296 } 297 pixelWeights->data.F32[num] = data->weight; 308 298 pixelSources->data.U16[num] = i; 309 299 num++; 310 300 } 311 301 pixelData->n = num; 312 if (weight) { 313 pixelWeights->n = num; 314 } 302 if (variance) { 303 pixelVariances->n = num; 304 } 305 pixelWeights->n = num; 315 306 pixelSources->n = num; 307 316 308 317 309 // The sensible thing to do varies according to how many good pixels there are. … … 327 319 if (!safe) { 328 320 imageValue = pixelData->data.F32[0]; 329 if ( weight) {330 varianceValue = pixel Weights->data.F32[0];321 if (variance) { 322 varianceValue = pixelVariances->data.F32[0]; 331 323 } 332 324 maskValue = 0; … … 338 330 // playing safe 339 331 if (useVariance || !safe) { 340 float mean, var iance; // Mean and variance from combination341 if (combinationMean(&mean, pixelData, weights, pixelMasks, maskVal) &&342 (! weight || combinationVariance(&variance, pixelWeights, weights, pixelMasks, maskVal))) {332 float mean, var; // Mean and variance from combination 333 if (combinationMean(&mean, pixelData, pixelWeights, NULL, maskVal) && 334 (!variance || combinationVariance(&var, pixelVariances, pixelWeights, NULL, maskVal))) { 343 335 imageValue = mean; 344 varianceValue = var iance;336 varianceValue = var; 345 337 maskValue = 0; 346 338 } … … 349 341 // Use variance to check that the two are consistent 350 342 float diff = pixelData->data.F32[0] - pixelData->data.F32[1]; 351 float sigma = sqrtf(pixel Weights->data.F32[0] + pixelWeights->data.F32[1]);343 float sigma = sqrtf(pixelVariances->data.F32[0] + pixelVariances->data.F32[1]); 352 344 if (fabs(diff) > rej * sigma) { 353 345 // Not consistent: mark both for inspection … … 361 353 // Record the value derived with no clipping, because pixels rejected using the harsh clipping 362 354 // applied in the first pass might later be accepted. 363 float mean, var iance; // Mean and variance of the combination364 if (!combinationMean(&mean, pixelData, weights, pixelMasks, maskVal) ||365 ( weight && !combinationVariance(&variance, pixelWeights, weights, pixelMasks, maskVal))) {355 float mean, var; // Mean and variance of the combination 356 if (!combinationMean(&mean, pixelData, pixelWeights, pixelMasks, maskVal) || 357 (variance && !combinationVariance(&var, pixelVariances, pixelWeights, pixelMasks, maskVal))) { 366 358 break; 367 359 } 368 360 imageValue = mean; 369 varianceValue = var iance;361 varianceValue = var; 370 362 maskValue = 0; 371 363 … … 377 369 // Convert to rejection limits 378 370 for (int i = 0; i < num; i++) { 379 pixel Weights->data.F32[i] = rej * sqrtf(pixelWeights->data.F32[i]);371 pixelVariances->data.F32[i] = rej * sqrtf(pixelVariances->data.F32[i]); 380 372 } 381 373 } … … 406 398 } 407 399 float diff = fabsf(pixelData->data.F32[j] - median); // Difference from expected 408 if (diff > (useVariance ? pixel Weights->data.F32[i] : limit)) {400 if (diff > (useVariance ? pixelVariances->data.F32[i] : limit)) { 409 401 pixelMasks->data.PS_TYPE_MASK_DATA[j] = 0xff; 410 402 combineInspect(inputs, x, y, pixelSources->data.U16[j]); … … 423 415 424 416 // Ensure the input array of pmStackData is valid, and get some details out of it 425 static bool validateInputData(bool *have Weights, // Do we have weights in the sky images?417 static bool validateInputData(bool *haveVariances, // Do we have variance maps in the sky images? 426 418 bool *havePixels, // Do we have lists of pixels? 427 419 int *num, // Number of inputs … … 439 431 PS_ASSERT_PTR_NON_NULL(data, false); 440 432 assert(psMemGetDeallocator(data) == (psFreeFunc)stackDataFree); // Ensure it's the right type 441 *have Weights = false;433 *haveVariances = false; 442 434 PS_ASSERT_IMAGE_NON_NULL(data->readout->image, false); 443 435 PS_ASSERT_IMAGE_TYPE(data->readout->image, PS_TYPE_F32, false); … … 448 440 *numRows = data->readout->image->numRows; 449 441 if (data->readout->weight) { 450 *have Weights = true;442 *haveVariances = true; 451 443 PS_ASSERT_IMAGE_NON_NULL(data->readout->weight, false); 452 444 PS_ASSERT_IMAGES_SIZE_EQUAL(data->readout->image, data->readout->weight, false); … … 476 468 PS_ASSERT_IMAGE_SIZE(data->readout->image, *numCols, *numRows, false); 477 469 PS_ASSERT_IMAGES_SIZE_EQUAL(data->readout->image, data->readout->mask, false); 478 if (*have Weights) {470 if (*haveVariances) { 479 471 PS_ASSERT_IMAGE_NON_NULL(data->readout->weight, false); 480 472 PS_ASSERT_IMAGES_SIZE_EQUAL(data->readout->image, data->readout->weight, false); … … 651 643 { 652 644 PS_ASSERT_PTR_NON_NULL(combined, false); 653 bool have Weights; // Do we have the weightmaps?645 bool haveVariances; // Do we have the variance maps? 654 646 bool havePixels; // Do we have lists of pixels? 655 647 int num; // Number of inputs 656 648 int numCols, numRows; // Size of (sky) images 657 if (!validateInputData(&have Weights, &havePixels, &num, &numCols, &numRows, input)) {649 if (!validateInputData(&haveVariances, &havePixels, &num, &numCols, &numRows, input)) { 658 650 return false; 659 651 } … … 669 661 PS_ASSERT_IMAGES_SIZE_EQUAL(combined->image, combined->mask, false); 670 662 } 671 if (useVariance && !have Weights) {663 if (useVariance && !haveVariances) { 672 664 psWarning("Unable to use variance in rejection if no variance maps supplied --- option turned off"); 673 665 useVariance = false; 674 666 } 675 667 676 // Pull out the weightings668 // Pull out the image weightings 677 669 psVector *weights = psVectorAlloc(num, PS_TYPE_F32); 678 670 for (int i = 0; i < num; i++) { … … 712 704 psImage *combinedImage = combined->image; // Combined image 713 705 psImage *combinedMask = combined->mask; // Combined mask 714 psImage *combined Weight = combined->weight; // Combined mask706 psImage *combinedVariance = combined->weight; // Combined variance map 715 707 716 708 psArray *pixelMap = pixelMapGenerate(input, maxInputCols, maxInputRows); // Map of pixels to source … … 731 723 } 732 724 psVector *reject = pixelMapQuery(pixelMap, x, y); // Inspect these images closely 733 combinePixels(combinedImage, combinedMask, combined Weight, input, weights, reject, x, y,725 combinePixels(combinedImage, combinedMask, combinedVariance, input, weights, reject, x, y, 734 726 maskVal, bad, numIter, rej, useVariance, safe, buffer); 735 727 } … … 750 742 } 751 743 752 psImage *combined Weights = combined->weight; // Combined weightmap753 if (have Weights && !combinedWeights) {744 psImage *combinedVariance = combined->weight; // Combined variance map 745 if (haveVariances && !combinedVariance) { 754 746 combined->weight = psImageAlloc(numCols, numRows, PS_TYPE_F32); 755 combined Weights= combined->weight;747 combinedVariance = combined->weight; 756 748 } 757 749 … … 769 761 for (int y = minInputRows; y < maxInputRows; y++) { 770 762 for (int x = minInputCols; x < maxInputCols; x++) { 771 combinePixels(combinedImage, combinedMask, combined Weights, input, weights, NULL, x, y,763 combinePixels(combinedImage, combinedMask, combinedVariance, input, weights, NULL, x, y, 772 764 maskVal, bad, numIter, rej, useVariance, safe, buffer); 773 765 }
Note:
See TracChangeset
for help on using the changeset viewer.
