Changeset 23577 for trunk/psModules/src/imcombine/pmStack.c
- Timestamp:
- Mar 27, 2009, 3:08:33 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/imcombine/pmStack.c (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmStack.c
r23242 r23577 46 46 psVector *weights; // Pixel weightings 47 47 psVector *sources; // Pixel sources (which image did they come from?) 48 psVector *limits; // Rejection limits 48 49 psVector *sort; // Buffer for sorting (to get a robust estimator of the standard dev) 49 50 } combineBuffer; … … 56 57 psFree(buffer->weights); 57 58 psFree(buffer->sources); 59 psFree(buffer->limits); 58 60 psFree(buffer->sort); 59 61 return; … … 71 73 buffer->weights = psVectorAlloc(numImages, PS_TYPE_F32); 72 74 buffer->sources = psVectorAlloc(numImages, PS_TYPE_U16); 75 buffer->limits = psVectorAlloc(numImages, PS_TYPE_F32); 73 76 buffer->sort = psVectorAlloc(numImages, PS_TYPE_F32); 74 77 return buffer; … … 319 322 bool useVariance, // Use variance for rejection when combining? 320 323 bool safe, // Combine safely? 324 bool rejectInspect, // Reject values marked for inspection from combination? 321 325 combineBuffer *buffer // Buffer for combination; to avoid multiple allocations 322 326 ) … … 336 340 psVector *pixelWeights = buffer->weights; // Image weights for the pixel of interest 337 341 psVector *pixelSources = buffer->sources; // Sources for the pixel of interest 342 psVector *pixelLimits = buffer->limits; // Limits for the pixel of interest 338 343 psVector *sort = buffer->sort; // Sort buffer 339 344 … … 375 380 pixelWeights->n = num; 376 381 pixelSources->n = num; 382 pixelLimits->n = num; 377 383 378 384 #ifdef TESTING … … 389 395 // Default option is that the pixel is bad 390 396 float imageValue = NAN, varianceValue = NAN; // Value for combined image and variance map 391 psImageMaskType maskValue = bad; // Value for combined mask397 psImageMaskType maskValue = bad; // Value for combined mask 392 398 switch (num) { 393 399 case 0: … … 449 455 if (PS_SQR(diff) > PS_SQR(rej) * sigma2) { 450 456 // Not consistent: mark both for inspection 451 combineInspect(inputs, x, y, pixelSources->data.U16[0]); 452 combineInspect(inputs, x, y, pixelSources->data.U16[1]); 457 if (rejectInspect) { 458 imageValue = NAN; 459 varianceValue = NAN; 460 maskValue = bad; 461 } else { 462 combineInspect(inputs, x, y, pixelSources->data.U16[0]); 463 combineInspect(inputs, x, y, pixelSources->data.U16[1]); 464 } 453 465 #ifdef TESTING 454 466 if (x == TEST_X && y == TEST_Y) { … … 501 513 #endif 502 514 503 pixel Variances->data.F32[i] = rej2 * (pixelVariances->data.F32[i] + sysVar);515 pixelLimits->data.F32[i] = rej2 * (pixelVariances->data.F32[i] + sysVar); 504 516 } 505 517 } … … 541 553 #define MASK_PIXEL_FOR_INSPECTION() \ 542 554 pixelMasks->data.PS_TYPE_VECTOR_MASK_DATA[j] = 0xff; \ 543 combineInspect(inputs, x, y, pixelSources->data.U16[j]); \ 555 if (!rejectInspect) { \ 556 combineInspect(inputs, x, y, pixelSources->data.U16[j]); \ 557 } \ 544 558 numClipped++; \ 545 559 totalClipped++; … … 553 567 // Comparing squares --- cheaper than lots of sqrts 554 568 // pixelVariances includes the rejection limit, from above 555 if (PS_SQR(diff) > pixel Variances->data.F32[j]) {569 if (PS_SQR(diff) > pixelLimits->data.F32[j]) { 556 570 MASK_PIXEL_FOR_INSPECTION(); 557 571 #ifdef TESTING 558 572 if (x == TEST_X && y == TEST_Y) { 559 573 fprintf(stderr, "Rejecting input %d based on variance: %f > %f\n", 560 j, diff, sqrtf(pixel Variances->data.F32[j]));574 j, diff, sqrtf(pixelLimits->data.F32[j])); 561 575 } 562 576 #endif … … 573 587 } 574 588 } 589 590 if (rejectInspect && totalClipped > 0) { 591 // Get rid of the masked values 592 // The alternative to this is to make combinationMeanVariance() accept a mask 593 int good = 0; // Index of good value 594 for (int i = 0; i < num; i++) { 595 if (pixelMasks->data.PS_TYPE_VECTOR_MASK_DATA[i]) { 596 continue; 597 } 598 if (i != good) { 599 pixelData->data.F32[good] = pixelData->data.F32[i]; 600 pixelVariances->data.F32[good] = pixelVariances->data.F32[i]; 601 pixelWeights->data.F32[good] = pixelWeights->data.F32[i]; 602 pixelData->data.F32[good] = pixelData->data.F32[i]; 603 } 604 good++; 605 } 606 pixelData->n = good; 607 pixelVariances->n = good; 608 pixelWeights->n = good; 609 if (combinationMeanVariance(&mean, &var, pixelData, pixelVariances, pixelWeights)) { 610 imageValue = mean; 611 varianceValue = var; 612 maskValue = 0; 613 } else { 614 imageValue = NAN; 615 varianceValue = NAN; 616 maskValue = bad; 617 } 618 } 619 575 620 break; 576 621 } … … 734 779 bool pmStackCombine(pmReadout *combined, psArray *input, psImageMaskType maskVal, psImageMaskType bad, 735 780 int kernelSize, int numIter, float rej, float sys, float discard, 736 bool entire, bool useVariance, bool safe )781 bool entire, bool useVariance, bool safe, bool rejectInspect) 737 782 { 738 783 PS_ASSERT_PTR_NON_NULL(combined, false); … … 838 883 combinePixels(combinedImage, combinedMask, combinedVariance, input, weights, 839 884 addVariance, reject, x, y, maskVal, bad, numIter, rej, sys, discard, 840 useVariance, safe, buffer);885 useVariance, safe, rejectInspect, buffer); 841 886 } 842 887 } … … 853 898 combinePixels(combinedImage, combinedMask, combinedVariance, input, weights, 854 899 addVariance, reject, x, y, maskVal, bad, numIter, rej, sys, discard, 855 useVariance, safe, buffer);900 useVariance, safe, rejectInspect, buffer); 856 901 } 857 902 } … … 881 926 combinePixels(combinedImage, combinedMask, combinedVariance, input, weights, 882 927 addVariance, NULL, x, y, maskVal, bad, numIter, rej, sys, discard, 883 useVariance, safe, buffer);928 useVariance, safe, rejectInspect, buffer); 884 929 } 885 930 }
Note:
See TracChangeset
for help on using the changeset viewer.
