IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 23, 2010, 9:12:53 AM (16 years ago)
Author:
Paul Price
Message:

Pulling r27400 out of the trunk until it can be developed further (compression, make optional). Development will continue on branches/pap_stack/

File:
1 edited

Legend:

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

    r27400 r27402  
    3535
    3636//#define TESTING                         // Enable test output
    37 //#define TEST_X 843-1                     // x coordinate to examine
    38 //#define TEST_Y 813-1                     // y coordinate to examine
     37//#define TEST_X 2148-1                     // x coordinate to examine
     38//#define TEST_Y 248-1                     // y coordinate to examine
    3939//#define TEST_RADIUS 0                    // Radius to examine
    4040
     
    4646    psVector *variances;                // Pixel variances
    4747    psVector *weights;                  // Pixel weightings
    48     psVector *exps;                     // Pixel exposures
    4948    psVector *sources;                  // Pixel sources (which image did they come from?)
    5049    psVector *limits;                   // Rejection limits
     
    5857    psFree(buffer->variances);
    5958    psFree(buffer->weights);
    60     psFree(buffer->exps);
    6159    psFree(buffer->sources);
    6260    psFree(buffer->limits);
     
    7573    buffer->variances = psVectorAlloc(numImages, PS_TYPE_F32);
    7674    buffer->weights = psVectorAlloc(numImages, PS_TYPE_F32);
    77     buffer->exps = psVectorAlloc(numImages, PS_TYPE_F32);
    7875    buffer->sources = psVectorAlloc(numImages, PS_TYPE_U16);
    7976    buffer->limits = psVectorAlloc(numImages, PS_TYPE_F32);
     
    9895static bool combinationMeanVariance(float *mean, // Mean value, to return
    9996                                    float *var, // Variance value, to return
    100                                     float *exp, // Exposure time, to return
    101                                     float *expWeight,          // Weighted exposure time, to return
    10297                                    const psVector *values, // Values to combine
    10398                                    const psVector *variances, // Pixel variances to combine
    104                                     const psVector *exps,      // Exposure times to combine
    10599                                    const psVector *weights // Weights to apply
    106100                                    )
     
    127121    float sumVarianceWeight = 0.0;     // Sum of the pixel variances multiplied by the global weights
    128122    float sumWeight = 0.0;              // Sum of the image weights
    129     float sumExp = 0.0;                 // Sum of the exposure time
    130     float sumExpWeight = 0.0;           // Sum of the exposure time multiplied by the global weights
    131123    for (int i = 0; i < values->n; i++) {
    132124        sumValueWeight += values->data.F32[i] * weights->data.F32[i];
     
    135127            sumVarianceWeight += variances->data.F32[i] * PS_SQR(weights->data.F32[i]);
    136128        }
    137         if (exps) {
    138             sumExp += exps->data.F32[i];
    139             sumExpWeight += exps->data.F32[i] * weights->data.F32[i];
    140         }
    141129    }
    142130
     
    148136    if (var) {
    149137        *var = sumVarianceWeight / PS_SQR(sumWeight);
    150     }
    151     if (exp) {
    152         *exp = sumExp;
    153     }
    154     if (expWeight) {
    155         *expWeight = sumExpWeight / sumWeight;
    156138    }
    157139    return true;
     
    294276                           const psArray *inputs, // Stack data
    295277                           const psVector *weights, // Global (single value) weights for data, or NULL
    296                            const psVector *exps,    // Exposures for data, or NULL
    297278                           const psVector *addVariance, // Additional variance for data
    298279                           const psVector *reject, // Indices of pixels to reject, or NULL
     
    311292    psVector *pixelVariances = variance ? buffer->variances : NULL; // Variances for the pixel of interest
    312293    psVector *pixelWeights = buffer->weights; // Image weights for the pixel of interest
    313     psVector *pixelExps = buffer->exps;       // Exposure times
    314294    psVector *pixelSources = buffer->sources; // Sources for the pixel of interest
    315295    psVector *pixelLimits = buffer->limits; // Limits for the pixel of interest
     
    351331        }
    352332        pixelWeights->data.F32[numGood] = data->weight;
    353         pixelExps->data.F32[numGood] = data->exp;
    354333        pixelSources->data.U16[numGood] = i;
    355334        numGood++;
     
    368347    if (PS_SQR(x - TEST_X) + PS_SQR(y - TEST_Y) <= PS_SQR(TEST_RADIUS)) {
    369348        for (int i = 0; i < numGood; i++) {
    370             fprintf(stderr, "Input %d, pixel %d,%d (%" PRIu16 "): %f %f (%f) %f %f %d\n",
     349            fprintf(stderr, "Input %d, pixel %d,%d (%" PRIu16 "): %f %f (%f) %f %d\n",
    371350                    i, x, y, pixelSources->data.U16[i], pixelData->data.F32[i], pixelVariances->data.F32[i],
    372                     addVariance->data.F32[i], pixelWeights->data.F32[i], pixelExps->data.F32[i],
    373                     pixelSuspects->data.U8[i]);
     351                    addVariance->data.F32[i], pixelWeights->data.F32[i], pixelSuspects->data.U8[i]);
    374352        }
    375353    }
     
    384362                          psImage *mask, // Combined mask, for output
    385363                          psImage *variance, // Combined variance map, for output
    386                           psImage *exp,   // Exposure map (time), for output
    387                           psImage *expnum,       // Exposure map (number) for output
    388                           psImage *expweight,    // Exposure map (weighted time) for output
    389364                          int num,      // Number of good pixels
    390365                          combineBuffer *buffer, // Buffer with vectors
     
    397372    psVector *pixelVariances = variance ? buffer->variances : NULL; // Variances for the pixel of interest
    398373    psVector *pixelWeights = buffer->weights; // Image weights for the pixel of interest
    399     psVector *pixelExps = buffer->exps;       // Exposure times
    400374
    401375    // Default option is that the pixel is bad
    402376    float imageValue = NAN, varianceValue = NAN; // Value for combined image and variance map
    403377    psImageMaskType maskValue = bad;    // Value for combined mask
    404     float expValue = 0.0, expWeightValue = NAN; // Exposure value (straight, and weighted)
    405 
    406378    switch (num) {
    407379      case 0: {
     
    421393                  varianceValue = pixelVariances->data.F32[0];
    422394              }
    423               if (exp) {
    424                   expValue = pixelExps->data.F32[0];
    425               }
    426395              maskValue = 0;
    427396#ifdef TESTING
     
    442411          // Automatically accept the mean of the pixels only if we're not playing safe
    443412          if (!safe) {
    444               if (combinationMeanVariance(&imageValue, &varianceValue, &expValue, &expWeightValue,
    445                                           pixelData, pixelVariances, pixelExps, pixelWeights)) {
     413              float mean, var;   // Mean and variance from combination
     414              if (combinationMeanVariance(&mean, &var, pixelData, pixelVariances, pixelWeights)) {
     415                  imageValue = mean;
     416                  varianceValue = var;
    446417                  maskValue = 0;
    447418#ifdef TESTING
    448419                  if (PS_SQR(x - TEST_X) + PS_SQR(y - TEST_Y) <= PS_SQR(TEST_RADIUS)) {
    449420                      fprintf(stderr, "Two inputs to combine using unsafe, pixel %d,%d --> %f %f\n",
    450                               x, y, imageValue, varianceValue);
     421                              x, y, mean, var);
    451422                  }
    452423#endif
     
    464435      default: {
    465436          // Can combine without too much worrying
    466           if (!combinationMeanVariance(&imageValue, &varianceValue, &expValue, &expWeightValue,
    467                                        pixelData, pixelVariances, pixelExps, pixelWeights)) {
     437          float mean, var;           // Mean and variance of the combination
     438          if (!combinationMeanVariance(&mean, &var, pixelData, pixelVariances, pixelWeights)) {
    468439              break;
    469440          }
     441          imageValue = mean;
     442          varianceValue = var;
    470443          maskValue = 0;
    471444#ifdef TESTING
    472445          if (PS_SQR(x - TEST_X) + PS_SQR(y - TEST_Y) <= PS_SQR(TEST_RADIUS)) {
    473               fprintf(stderr, "Combined inputs, pixel %d,%d --> %f %f\n", x, y, imageValue, varianceValue);
     446              fprintf(stderr, "Combined inputs, pixel %d,%d --> %f %f\n", x, y, mean, var);
    474447          }
    475448#endif
     
    483456        variance->data.F32[y][x] = varianceValue;
    484457    }
    485     if (exp) {
    486         exp->data.F32[y][x] = expValue;
    487     }
    488     if (expnum) {
    489         expnum->data.PS_TYPE_IMAGE_MASK_DATA[y][x] = num;
    490     }
    491     if (expweight) {
    492         expweight->data.F32[y][x] = expWeightValue;
    493     }
     458
     459#ifdef TESTING
     460    mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] = num;
     461#endif
     462
    494463
    495464    return;
     
    834803                              int *numCols, int *numRows, // Size of (sky) images
    835804                              const psArray *input, // Input array of pmStackData to validate
    836                               const pmReadout *output, // Output readout
    837                               const pmReadout *exp    // Exposure map
     805                              const pmReadout *output // Output readout
    838806    )
    839807{
     
    901869    }
    902870
    903     if (exp) {
    904         PM_ASSERT_READOUT_NON_NULL(exp, false);
    905         if (exp->image) {
    906             PS_ASSERT_IMAGES_SIZE_EQUAL(exp->image, output->image, false);
    907         }
    908         if (exp->mask) {
    909             PS_ASSERT_IMAGES_SIZE_EQUAL(exp->mask, output->image, false);
    910         }
    911     }
    912 
    913871    return true;
    914872}
     
    979937
    980938/// Constructor
    981 pmStackData *pmStackDataAlloc(pmReadout *readout, float weight, float exp, float addVariance)
     939pmStackData *pmStackDataAlloc(pmReadout *readout, float weight, float addVariance)
    982940{
    983941    pmStackData *data = psAlloc(sizeof(pmStackData)); // Stack data, to return
     
    988946    data->inspect = NULL;
    989947    data->weight = weight;
    990     data->exp = exp;
    991948    data->addVariance = addVariance;
    992949
     
    995952
    996953/// Stack input images
    997 bool pmStackCombine(pmReadout *combined, pmReadout *expmaps, psArray *input,
    998                     psImageMaskType maskVal, psImageMaskType maskSuspect,
    999                     psImageMaskType bad, int kernelSize,
    1000                     float iter, float rej, float sys, float olympic,
     954bool pmStackCombine(pmReadout *combined, psArray *input, psImageMaskType maskVal, psImageMaskType maskSuspect,
     955                    psImageMaskType bad, int kernelSize, float iter, float rej, float sys, float olympic,
    1001956                    bool useVariance, bool safe, bool rejection)
    1002957{
     
    1004959    int num;                            // Number of inputs
    1005960    int numCols, numRows;               // Size of (sky) images
    1006     if (!validateInputData(&haveVariances, &num, &numCols, &numRows, input, combined, expmaps)) {
     961    if (!validateInputData(&haveVariances, &num, &numCols, &numRows, input, combined)) {
    1007962        return false;
    1008963    }
     
    1022977    psVector *addVariance = psVectorAlloc(num, PS_TYPE_F32); // Additional variance for each image
    1023978    psVector *weights = psVectorAlloc(num, PS_TYPE_F32); // Relative weighting for each image
    1024     psVector *exps = psVectorAlloc(num, PS_TYPE_F32);    // Exposure times for each image
    1025979    psArray *stack = psArrayAlloc(num); // Stack of readouts
    1026980    for (int i = 0; i < num; i++) {
     
    1028982        if (!data) {
    1029983            weights->data.F32[i] = 0.0;
    1030             exps->data.F32[i] = NAN;
    1031984            continue;
    1032985        }
    1033986        weights->data.F32[i] = data->weight;
    1034         exps->data.F32[i] = data->exp;
    1035987        pmReadout *ro = data->readout;  // Readout of interest
    1036988        stack->data[i] = psMemIncrRefCounter(ro);
     
    10931045        combined->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32);
    10941046        combinedVariance = combined->variance;
    1095     }
    1096 
    1097     psImage *exp = NULL, *expnum = NULL; // Exposure map and exposure number
    1098     if (expmaps) {
    1099         if (!expmaps->image) {
    1100             expmaps->image = psImageAlloc(numCols, numRows, PS_TYPE_F32);
    1101         }
    1102         exp = expmaps->image;
    1103 
    1104         if (!expmaps->mask) {
    1105             expmaps->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);
    1106         }
    1107         expnum = expmaps->mask;
    11081047    }
    11091048
     
    11441083            bool suspect;               // Suspect pixels in stack?
    11451084            combineExtract(&num, &suspect, buffer, combinedImage, combinedMask, combinedVariance,
    1146                            input, weights, exps, addVariance, reject, x, y, maskVal, maskSuspect);
    1147             combinePixels(combinedImage, combinedMask, combinedVariance, exp, expnum, NULL,
    1148                           num, buffer, x, y, bad, safe);
     1085                           input, weights, addVariance, reject, x, y, maskVal, maskSuspect);
     1086            combinePixels(combinedImage, combinedMask, combinedVariance, num, buffer, x, y, bad, safe);
    11491087
    11501088            if (iter > 0) {
Note: See TracChangeset for help on using the changeset viewer.