IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 27, 2009, 3:08:33 PM (17 years ago)
Author:
Paul Price
Message:

Ensure we can reject pixels when combining images without convolution.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/imcombine/pmStack.c

    r23242 r23577  
    4646    psVector *weights;                  // Pixel weightings
    4747    psVector *sources;                  // Pixel sources (which image did they come from?)
     48    psVector *limits;                   // Rejection limits
    4849    psVector *sort;                     // Buffer for sorting (to get a robust estimator of the standard dev)
    4950} combineBuffer;
     
    5657    psFree(buffer->weights);
    5758    psFree(buffer->sources);
     59    psFree(buffer->limits);
    5860    psFree(buffer->sort);
    5961    return;
     
    7173    buffer->weights = psVectorAlloc(numImages, PS_TYPE_F32);
    7274    buffer->sources = psVectorAlloc(numImages, PS_TYPE_U16);
     75    buffer->limits = psVectorAlloc(numImages, PS_TYPE_F32);
    7376    buffer->sort = psVectorAlloc(numImages, PS_TYPE_F32);
    7477    return buffer;
     
    319322                          bool useVariance, // Use variance for rejection when combining?
    320323                          bool safe,    // Combine safely?
     324                          bool rejectInspect, // Reject values marked for inspection from combination?
    321325                          combineBuffer *buffer // Buffer for combination; to avoid multiple allocations
    322326                         )
     
    336340    psVector *pixelWeights = buffer->weights; // Image weights for the pixel of interest
    337341    psVector *pixelSources = buffer->sources; // Sources for the pixel of interest
     342    psVector *pixelLimits = buffer->limits; // Limits for the pixel of interest
    338343    psVector *sort = buffer->sort;      // Sort buffer
    339344
     
    375380    pixelWeights->n = num;
    376381    pixelSources->n = num;
     382    pixelLimits->n = num;
    377383
    378384#ifdef TESTING
     
    389395    // Default option is that the pixel is bad
    390396    float imageValue = NAN, varianceValue = NAN; // Value for combined image and variance map
    391     psImageMaskType maskValue = bad;         // Value for combined mask
     397    psImageMaskType maskValue = bad;    // Value for combined mask
    392398    switch (num) {
    393399      case 0:
     
    449455              if (PS_SQR(diff) > PS_SQR(rej) * sigma2) {
    450456                  // 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                  }
    453465#ifdef TESTING
    454466                  if (x == TEST_X && y == TEST_Y) {
     
    501513#endif
    502514
    503                       pixelVariances->data.F32[i] = rej2 * (pixelVariances->data.F32[i] + sysVar);
     515                      pixelLimits->data.F32[i] = rej2 * (pixelVariances->data.F32[i] + sysVar);
    504516                  }
    505517              }
     
    541553#define MASK_PIXEL_FOR_INSPECTION() \
    542554    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    } \
    544558    numClipped++; \
    545559    totalClipped++;
     
    553567                      // Comparing squares --- cheaper than lots of sqrts
    554568                      // pixelVariances includes the rejection limit, from above
    555                       if (PS_SQR(diff) > pixelVariances->data.F32[j]) {
     569                      if (PS_SQR(diff) > pixelLimits->data.F32[j]) {
    556570                          MASK_PIXEL_FOR_INSPECTION();
    557571#ifdef TESTING
    558572                          if (x == TEST_X && y == TEST_Y) {
    559573                              fprintf(stderr, "Rejecting input %d based on variance: %f > %f\n",
    560                                       j, diff, sqrtf(pixelVariances->data.F32[j]));
     574                                      j, diff, sqrtf(pixelLimits->data.F32[j]));
    561575                          }
    562576#endif
     
    573587              }
    574588          }
     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
    575620          break;
    576621      }
     
    734779bool pmStackCombine(pmReadout *combined, psArray *input, psImageMaskType maskVal, psImageMaskType bad,
    735780                    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)
    737782{
    738783    PS_ASSERT_PTR_NON_NULL(combined, false);
     
    838883                    combinePixels(combinedImage, combinedMask, combinedVariance, input, weights,
    839884                                  addVariance, reject, x, y, maskVal, bad, numIter, rej, sys, discard,
    840                                   useVariance, safe, buffer);
     885                                  useVariance, safe, rejectInspect, buffer);
    841886                }
    842887            }
     
    853898                combinePixels(combinedImage, combinedMask, combinedVariance, input, weights,
    854899                              addVariance, reject, x, y, maskVal, bad, numIter, rej, sys, discard,
    855                               useVariance, safe, buffer);
     900                              useVariance, safe, rejectInspect, buffer);
    856901            }
    857902        }
     
    881926                combinePixels(combinedImage, combinedMask, combinedVariance, input, weights,
    882927                              addVariance, NULL, x, y, maskVal, bad, numIter, rej, sys, discard,
    883                               useVariance, safe, buffer);
     928                              useVariance, safe, rejectInspect, buffer);
    884929            }
    885930        }
Note: See TracChangeset for help on using the changeset viewer.