IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 28, 2009, 5:35:05 PM (17 years ago)
Author:
Paul Price
Message:

Reworking stack combination because there are *three* modes for pixels going into the final stack (after rejection), not just two: tested and good, tested and rejected, and not tested. The code did not recognise the third, which is a distinct state because we don't want these pixels grown, as we do for rejected pixels. This cannot be fixed merely by using the 'safe' combination because that would discard the 'tested and good' pixels that have only a single unrejected input but are good because they have survived the testing process. Needed to add a new state into the combination process. Now I add these pixels straight into the 'reject' list. This requires a little bit more fiddling around in ppStack. Not sure it's working yet.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/pap/psModules/src/imcombine/pmStack.c

    r25960 r25964  
    290290
    291291// Mark a pixel for inspection
     292// Value in pixel doesn't seem to agree with the stack, so need to look closer
    292293static inline void combineInspect(const psArray *inputs, // Stack data
    293294                                  int x, int y, // Pixel
     
    301302    }
    302303    data->inspect = psPixelsAdd(data->inspect, data->inspect->nalloc, x, y);
     304    return;
     305}
     306
     307// Mark a pixel for rejection
     308// Cannot possibly inspect this pixel and confirm that it's good.
     309// e.g., Only a single input
     310static inline void combineReject(const psArray *inputs, // Stack data
     311                                 int x, int y, // Pixel
     312                                 int source // Source image index
     313                                 )
     314{
     315    pmStackData *data = inputs->data[source]; // Stack data of interest
     316    if (!data) {
     317        psWarning("Can't find input data for source %d", source);
     318        return;
     319    }
     320    data->reject = psPixelsAdd(data->reject, data->reject->nalloc, x, y);
    303321    return;
    304322}
     
    319337                          float rej, // Number of standard deviations at which to reject
    320338                          float sys,    // Relative systematic error
    321                           float discard,// Fraction of values to discard (Olympic weighted mean)
     339                          float olympic,// Fraction of values to discard (Olympic weighted mean)
    322340                          bool useVariance, // Use variance for rejection when combining?
    323341                          bool safe,    // Combine safely?
    324                           bool rejectInspect, // Reject values marked for inspection from combination?
     342                          bool rejection, // Reject values marked for inspection from combination?
    325343                          combineBuffer *buffer // Buffer for combination; to avoid multiple allocations
    326344                         )
     
    419437              }
    420438              maskValue = 0;
    421           }
    422 #ifdef TESTING
    423           else {
     439          } else {
     440              if (!rejection) {
     441                  combineReject(inputs, x, y, pixelSources->data.U16[0]);
     442              }
     443#ifdef TESTING
    424444              numRejected = 1;
    425445              if (x == TEST_X && y == TEST_Y) {
    426446                  fprintf(stderr, "Single input to combine, safety on, pixel is bad.\n");
    427447              }
     448#endif
    428449          }
    429 #endif
    430450          break;
    431451      }
     
    459479              if (PS_SQR(diff) > PS_SQR(rej) * sigma2) {
    460480                  // Not consistent: mark both for inspection
    461                   if (rejectInspect) {
     481                  if (rejection) {
    462482                      imageValue = NAN;
    463483                      varianceValue = NAN;
     
    550570                  }
    551571#endif
    552                   median = combinationWeightedOlympic(pixelData, pixelWeights, pixelMasks, discard, sort);
     572                  median = combinationWeightedOlympic(pixelData, pixelWeights, pixelMasks, olympic, sort);
    553573              }
    554574
     
    563583#define MASK_PIXEL_FOR_INSPECTION() \
    564584    pixelMasks->data.PS_TYPE_VECTOR_MASK_DATA[j] = 0xff; \
    565     if (!rejectInspect) { \
     585    if (!rejection) { \
    566586        combineInspect(inputs, x, y, pixelSources->data.U16[j]); \
    567587    } \
     
    605625          }
    606626
    607           if (rejectInspect && totalClipped > 0) {
     627          if (rejection && totalClipped > 0) {
    608628              // Get rid of the masked values
    609629              // The alternative to this is to make combinationMeanVariance() accept a mask
     
    658678// Ensure the input array of pmStackData is valid, and get some details out of it
    659679static bool validateInputData(bool *haveVariances, // Do we have variance maps in the sky images?
    660                               bool *haveRejects, // Do we have lists of rejected pixels?
    661680                              int *num,    // Number of inputs
    662681                              int *numCols, int *numRows, // Size of (sky) images
    663                               psArray *input // Input array of pmStackData to validate
     682                              const psArray *input, // Input array of pmStackData to validate
     683                              const pmReadout *output // Output readout
    664684    )
    665685{
     
    687707        PS_ASSERT_IMAGE_TYPE(data->readout->variance, PS_TYPE_F32, false);
    688708    }
    689     *haveRejects = (data->reject != NULL);
     709    bool haveRejects = (data->reject != NULL); // Do we have rejected pixels?
    690710
    691711    // Make sure the rest correspond with the first
     
    700720            return false;
    701721        }
    702         if ((*haveRejects && !data->reject) || (data->reject && !*haveRejects)) {
     722        if ((haveRejects && !data->reject) || (data->reject && !haveRejects)) {
    703723            psError(PS_ERR_UNEXPECTED_NULL, true,
    704724                    "The rejected pixels are specified in some but not all inputs.");
     
    716736            PS_ASSERT_IMAGE_TYPE(data->readout->variance, PS_TYPE_F32, false);
    717737        }
     738    }
     739
     740    PM_ASSERT_READOUT_NON_NULL(output, false);
     741    if (output->image) {
     742        PS_ASSERT_IMAGE_NON_NULL(output->image, false);
     743        PS_ASSERT_IMAGE_TYPE(output->image, PS_TYPE_F32, false);
     744        PS_ASSERT_IMAGE_NON_NULL(output->mask, false);
     745        PS_ASSERT_IMAGE_TYPE(output->mask, PS_TYPE_IMAGE_MASK, false);
     746        PS_ASSERT_IMAGES_SIZE_EQUAL(output->image, output->mask, false);
    718747    }
    719748
     
    802831/// Stack input images
    803832bool pmStackCombine(pmReadout *combined, psArray *input, psImageMaskType maskVal, psImageMaskType bad,
    804                     int kernelSize, int numIter, float rej, float sys, float discard,
    805                     bool entire, bool useVariance, bool safe, bool rejectInspect)
    806 {
    807     PS_ASSERT_PTR_NON_NULL(combined, false);
     833                    int kernelSize, int numIter, float rej, float sys, float olympic,
     834                    bool useVariance, bool safe, bool rejection)
     835{
    808836    bool haveVariances;                 // Do we have the variance maps?
    809     bool haveRejects;                   // Do we have lists of rejected pixels?
    810837    int num;                            // Number of inputs
    811838    int numCols, numRows;               // Size of (sky) images
    812     if (!validateInputData(&haveVariances, &haveRejects, &num, &numCols, &numRows, input)) {
     839    if (!validateInputData(&haveVariances, &num, &numCols, &numRows, input, combined)) {
    813840        return false;
    814841    }
     
    821848        PS_ASSERT_FLOAT_LARGER_THAN(rej, 0.0, false);
    822849    }
    823     if (haveRejects) {
    824         // This is a subsequent combination, so expect that the image and mask already exist
    825         PS_ASSERT_IMAGE_NON_NULL(combined->image, false);
    826         PS_ASSERT_IMAGE_TYPE(combined->image, PS_TYPE_F32, false);
    827         PS_ASSERT_IMAGE_NON_NULL(combined->mask, false);
    828         PS_ASSERT_IMAGE_TYPE(combined->mask, PS_TYPE_IMAGE_MASK, false);
    829         PS_ASSERT_IMAGES_SIZE_EQUAL(combined->image, combined->mask, false);
    830     }
    831850    if (useVariance && !haveVariances) {
    832851        psWarning("Unable to use variance in rejection if no variance maps supplied --- option turned off");
     
    852871        }
    853872#endif
    854         if (!haveRejects && !data->inspect) {
    855             data->inspect = psPixelsAllocEmpty(PIXEL_LIST_BUFFER);
     873        if (!rejection) {
     874            // Ensure pixels can be put on the appropriate list
     875            if (!data->inspect) {
     876                data->inspect = psPixelsAllocEmpty(PIXEL_LIST_BUFFER);
     877            }
     878            if (!data->reject) {
     879                data->reject = psPixelsAllocEmpty(PIXEL_LIST_BUFFER);
     880            }
    856881        }
    857882    }
     
    882907    combineBuffer *buffer = combineBufferAlloc(num);
    883908
    884     if (haveRejects) {
    885         psImage *combinedImage = combined->image; // Combined image
    886         psImage *combinedMask = combined->mask; // Combined mask
    887         psImage *combinedVariance = combined->variance; // Combined variance map
    888 
    889         psArray *pixelMap = pixelMapGenerate(input, minInputCols, maxInputCols,
    890                                              minInputRows, maxInputRows); // Map of pixels to source
    891         psPixels *pixels = NULL;            // Total list of pixels, with no duplicates
     909    // Pull the products out, allocate if necessary
     910    psImage *combinedImage = combined->image; // Combined image
     911    if (!combinedImage) {
     912        combined->image = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     913        combinedImage = combined->image;
     914    }
     915    psImage *combinedMask = combined->mask; // Combined mask
     916    if (!combinedMask) {
     917        combined->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);
     918        combinedMask = combined->mask;
     919    }
     920
     921    psImage *combinedVariance = combined->variance; // Combined variance map
     922    if (haveVariances && !combinedVariance) {
     923        combined->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     924        combinedVariance = combined->variance;
     925    }
     926
     927    // Set up rejection list
     928    psArray *pixelMap = NULL;           // Map of pixels to source
     929    if (rejection) {
     930        pixelMap = pixelMapGenerate(input, minInputCols, maxInputCols, minInputRows, maxInputRows);
     931    }
     932
     933    // Combine each pixel
     934    for (int y = minInputRows; y < maxInputRows; y++) {
     935        for (int x = minInputCols; x < maxInputCols; x++) {
     936            psVector *reject = NULL; // Images to reject for this pixel
     937            if (rejection) {
     938                reject = pixelMapQuery(pixelMap, minInputCols, minInputRows, x, y);
     939            }
     940            combinePixels(combinedImage, combinedMask, combinedVariance, input, weights,
     941                          addVariance, reject, x, y, maskVal, bad, numIter, rej, sys, olympic,
     942                          useVariance, safe, rejection, buffer);
     943        }
     944    }
     945
     946    psFree(pixelMap);
     947    psFree(weights);
     948    psFree(buffer);
     949
     950#ifndef PS_NO_TRACE
     951    if (!rejection && psTraceGetLevel("psModules.imcombine") >= 5) {
    892952        for (int i = 0; i < num; i++) {
    893             pmStackData *data = input->data[i]; // Stacking data; contains the list of pixels
    894             if (!data) {
     953            pmStackData *data = input->data[i]; // Stack data for this input
     954            if (!data || !data->inspect) {
    895955                continue;
    896956            }
    897             pixels = psPixelsConcatenate(pixels, data->reject);
    898         }
    899         pixels = psPixelsDuplicates(pixels, pixels);
    900 
    901         if (entire) {
    902             // Combine entire image
    903             for (int y = minInputRows; y < maxInputRows; y++) {
    904                 for (int x = minInputCols; x < maxInputCols; x++) {
    905                     psVector *reject = pixelMapQuery(pixelMap, minInputCols, minInputRows,
    906                                                      x, y); // Reject these images
    907                     combinePixels(combinedImage, combinedMask, combinedVariance, input, weights,
    908                                   addVariance, reject, x, y, maskVal, bad, numIter, rej, sys, discard,
    909                                   useVariance, safe, rejectInspect, buffer);
    910                 }
    911             }
    912         } else {
    913             // Only combine previously rejected pixels
    914             for (int i = 0; i < pixels->n; i++) {
    915                 // Pixel coordinates are in the frame of the original image
    916                 int x = pixels->data[i].x, y = pixels->data[i].y; // Coordinates of interest
    917                 if (x < minInputCols || x >= maxInputCols || y < minInputRows || y >= maxInputRows) {
    918                     continue;
    919                 }
    920                 psVector *reject = pixelMapQuery(pixelMap, minInputCols, minInputRows,
    921                                                  x, y); // Reject these images
    922                 combinePixels(combinedImage, combinedMask, combinedVariance, input, weights,
    923                               addVariance, reject, x, y, maskVal, bad, numIter, rej, sys, discard,
    924                               useVariance, safe, rejectInspect, buffer);
    925             }
    926         }
    927         psFree(pixels);
    928         psFree(pixelMap);
    929     } else {
    930         // Pull the products out, allocate if necessary
    931         psImage *combinedImage = combined->image; // Combined image
    932         if (!combinedImage) {
    933             combined->image = psImageAlloc(numCols, numRows, PS_TYPE_F32);
    934             combinedImage = combined->image;
    935         }
    936         psImage *combinedMask = combined->mask; // Combined mask
    937         if (!combinedMask) {
    938             combined->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);
    939             combinedMask = combined->mask;
    940         }
    941 
    942         psImage *combinedVariance = combined->variance; // Combined variance map
    943         if (haveVariances && !combinedVariance) {
    944             combined->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32);
    945             combinedVariance = combined->variance;
    946         }
    947 
    948         for (int y = minInputRows; y < maxInputRows; y++) {
    949             for (int x = minInputCols; x < maxInputCols; x++) {
    950                 combinePixels(combinedImage, combinedMask, combinedVariance, input, weights,
    951                               addVariance, NULL, x, y, maskVal, bad, numIter, rej, sys, discard,
    952                               useVariance, safe, rejectInspect, buffer);
    953             }
    954         }
    955 
    956 #ifndef PS_NO_TRACE
    957         if (psTraceGetLevel("psModules.imcombine") >= 5) {
    958             for (int i = 0; i < num; i++) {
    959                 pmStackData *data = input->data[i]; // Stack data for this input
    960                 if (!data || !data->inspect) {
    961                     continue;
    962                 }
    963                 psTrace("psModules.imcombine", 5, "Image %d: %ld pixels to inspect.\n", i, data->inspect->n);
    964             }
    965         }
    966 #endif
    967     }
    968 
    969     psFree(weights);
    970     psFree(buffer);
     957            psTrace("psModules.imcombine", 5, "Image %d: %ld pixels to inspect.\n", i, data->inspect->n);
     958        }
     959    }
     960#endif
    971961
    972962    return true;
Note: See TracChangeset for help on using the changeset viewer.