IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 18, 2008, 3:59:59 PM (18 years ago)
Author:
Paul Price
Message:

Incorporating "variance factors" --- accounting for pixel-scale variance rather than smoothed.

File:
1 edited

Legend:

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

    r17679 r18182  
    88 *  @author GLG, MHPCC
    99 *
    10  *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2008-05-14 22:22:28 $
     10 *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2008-06-19 01:59:59 $
    1212 *  Copyright 2004-2007 Institute for Astronomy, University of Hawaii
    1313 *
     
    216216                          const psArray *inputs, // Stack data
    217217                          const psVector *weights, // Global (single value) weights for data, or NULL
     218                          const psVector *varFactors, // Variance factors for data
    218219                          const psVector *reject, // Indices of pixels to reject, or NULL
    219220                          int x, int y, // Coordinates of interest; frame of output image
     
    233234    assert(numIter >= 0);
    234235    assert(buffer);
     236    assert(varFactors);
    235237    assert((useVariance && variance) || !useVariance);
    236238
     
    339341              psVectorInit(pixelMasks, 0);
    340342              if (useVariance) {
    341                   // Convert to rejection limits
     343                  // Convert to rejection limits --- saves doing it later.
     344                  // Using squared rejection limit because it's cheaper than sqrts
     345                  rej *= rej;
    342346                  for (int i = 0; i < num; i++) {
    343                       pixelVariances->data.F32[i] = rej * sqrtf(pixelVariances->data.F32[i]);
     347                      pixelVariances->data.F32[i] = rej * pixelVariances->data.F32[i] *
     348                          varFactors->data.F32[i];
    344349                  }
    345350              }
     
    364369              }
    365370
     371// Mask a pixel for inspection
     372#define MASK_PIXEL_FOR_INSPECTION() \
     373    pixelMasks->data.PS_TYPE_MASK_DATA[j] = 0xff; \
     374    combineInspect(inputs, x, y, pixelSources->data.U16[j]); \
     375    numClipped++; \
     376    totalClipped++;
     377
    366378              for (int j = 0; j < num; j++) {
    367379                  if (pixelMasks->data.PS_TYPE_MASK_DATA[j]) {
     
    369381                  }
    370382                  float diff = fabsf(pixelData->data.F32[j] - median); // Difference from expected
    371                   if (diff > (useVariance ? pixelVariances->data.F32[i] : limit)) {
    372                       pixelMasks->data.PS_TYPE_MASK_DATA[j] = 0xff;
    373                       combineInspect(inputs, x, y, pixelSources->data.U16[j]);
    374                       numClipped++;
    375                       totalClipped++;
     383                  if (useVariance) {
     384                      // Comparing squares --- cheaper than lots of sqrts
     385                      if (PS_SQR(diff) > pixelVariances->data.F32[i]) {
     386                          MASK_PIXEL_FOR_INSPECTION();
     387                      }
     388                  } else if (diff > limit) {
     389                      MASK_PIXEL_FOR_INSPECTION();
    376390                  }
    377391              }
     
    561575    }
    562576
     577    psVector *varFactors = psVectorAlloc(num, PS_TYPE_F32); // Variance factors for each image
    563578    psVector *weights = psVectorAlloc(num, PS_TYPE_F32); // Relative weighting for each image
    564579    psArray *stack = psArrayAlloc(num); // Stack of readouts
     
    571586        weights->data.F32[i] = data->weight;
    572587        stack->data[i] = psMemIncrRefCounter(data->readout);
     588        // Variance factor
     589        float vf = psMetadataLookupF32(NULL, data->readout->parent->concepts, "CELL.VARFACTOR"); // Var factor
     590        if (!isfinite(vf)) {
     591            psWarning("Non-finite CELL.VARFACTOR for image %d --- setting to unity.", i);
     592            vf = 1.0;
     593        }
     594        varFactors->data.F32[i] = vf;
    573595    }
    574596
     
    618640                for (int x = minInputCols; x < maxInputCols; x++) {
    619641                    psVector *reject = pixelMapQuery(pixelMap, x, y); // Inspect these images closely
    620                     combinePixels(combinedImage, combinedMask, combinedVariance, input, weights, reject, x, y,
    621                                   maskVal, bad, numIter, rej, useVariance, safe, buffer);
     642                    combinePixels(combinedImage, combinedMask, combinedVariance, input, weights, varFactors,
     643                                  reject, x, y, maskVal, bad, numIter, rej, useVariance, safe, buffer);
    622644                }
    623645            }
     
    631653                }
    632654                psVector *reject = pixelMapQuery(pixelMap, x, y); // Inspect these images closely
    633                 combinePixels(combinedImage, combinedMask, combinedVariance, input, weights, reject, x, y,
    634                               maskVal, bad, numIter, rej, useVariance, safe, buffer);
     655                combinePixels(combinedImage, combinedMask, combinedVariance, input, weights, varFactors,
     656                              reject, x, y, maskVal, bad, numIter, rej, useVariance, safe, buffer);
    635657            }
    636658        }
     
    658680        for (int y = minInputRows; y < maxInputRows; y++) {
    659681            for (int x = minInputCols; x < maxInputCols; x++) {
    660                 combinePixels(combinedImage, combinedMask, combinedVariance, input, weights, NULL, x, y,
    661                               maskVal, bad, numIter, rej, useVariance, safe, buffer);
     682                combinePixels(combinedImage, combinedMask, combinedVariance, input, weights, varFactors,
     683                              NULL, x, y, maskVal, bad, numIter, rej, useVariance, safe, buffer);
    662684            }
    663685        }
Note: See TracChangeset for help on using the changeset viewer.