IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17005


Ignore:
Timestamp:
Mar 17, 2008, 11:38:43 AM (18 years ago)
Author:
Paul Price
Message:

Allow an entire image to be rejected, in which case the entire combined image needs to be recalculated. Also split the pmStackData->pixels into separate inspect and reject parts, to minimise confusion.

Location:
trunk/psModules/src/imcombine
Files:
2 edited

Legend:

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

    r16848 r17005  
    88 *  @author GLG, MHPCC
    99 *
    10  *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2008-03-06 21:38:39 $
     10 *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2008-03-17 21:38:43 $
    1212 *  Copyright 2004-2007 Institute for Astronomy, University of Hawaii
    1313 *
     
    8080{
    8181    psFree(data->readout);
    82     psFree(data->pixels);
     82    psFree(data->reject);
     83    psFree(data->inspect);
    8384    return;
    8485}
     
    172173    } else {
    173174        *median = num % 2 ? sortBuffer->data.F32[num / 2] :
    174             (sortBuffer->data.F32[num / 2] + sortBuffer->data.F32[num / 2 + 1]) / 2.0;
     175            (sortBuffer->data.F32[num / 2 - 1] + sortBuffer->data.F32[num / 2]) / 2.0;
    175176        if (stdev) {
    176177            if (num <= NUM_DIRECT_STDEV) {
     
    180181                    sum += PS_SQR(sortBuffer->data.F32[i] - *median);
    181182                }
    182                 *stdev = sqrt(sum / (float)(num - 1));
     183                *stdev = sqrt(sum / (double)(num - 1));
    183184            } else {
    184185                // Standard deviation from the interquartile range
     
    201202    pmStackData *data = inputs->data[source]; // Stack data of interest
    202203    if (!data) {
     204        psWarning("Can't find input data for source %d", source);
    203205        return;
    204206    }
    205     data->pixels = psPixelsAdd(data->pixels, PIXEL_LIST_BUFFER, x, y);
     207    data->inspect = psPixelsAdd(data->inspect, PIXEL_LIST_BUFFER, x, y);
    206208    return;
    207209}
     
    391393// Ensure the input array of pmStackData is valid, and get some details out of it
    392394static bool validateInputData(bool *haveVariances, // Do we have variance maps in the sky images?
    393                               bool *havePixels, // Do we have lists of pixels?
     395                              bool *haveRejects, // Do we have lists of rejected pixels?
    394396                              int *num,    // Number of inputs
    395397                              int *numCols, int *numRows, // Size of (sky) images
     
    420422        PS_ASSERT_IMAGE_TYPE(data->readout->weight, PS_TYPE_F32, false);
    421423    }
    422     *havePixels = (data->pixels != NULL);
     424    *haveRejects = (data->reject != NULL);
    423425
    424426    // Make sure the rest correspond with the first
     
    433435            return false;
    434436        }
    435         if ((*havePixels && !data->pixels) || (data->pixels && !*havePixels)) {
    436             psError(PS_ERR_UNEXPECTED_NULL, true, "The pixels are specified in some but not all inputs.");
     437        if ((*haveRejects && !data->reject) || (data->reject && !*haveRejects)) {
     438            psError(PS_ERR_UNEXPECTED_NULL, true,
     439                    "The rejected pixels are specified in some but not all inputs.");
    437440            return false;
    438441        }
     
    473476            continue;
    474477        }
    475         assert(data->pixels);
    476         psPixels *pixels = data->pixels;// The pixels of interest
     478        assert(data->reject);
     479        psPixels *pixels = data->reject; // The rejected pixels
    477480        for (int j = 0; j < pixels->n; j++) {
    478481            int x = pixels->data[j].x, y = pixels->data[j].y; // Coordinates of interest
     
    518521
    519522    data->readout = psMemIncrRefCounter(readout);
    520     data->pixels = NULL;
     523    data->reject = NULL;
     524    data->inspect = NULL;
    521525    data->weight = weight;
    522526
     
    526530/// Stack input images
    527531bool pmStackCombine(pmReadout *combined, psArray *input, psMaskType maskVal, psMaskType bad,
    528                     int kernelSize, int numIter, float rej, bool useVariance, bool safe)
     532                    int kernelSize, int numIter, float rej, bool entire, bool useVariance, bool safe)
    529533{
    530534    PS_ASSERT_PTR_NON_NULL(combined, false);
    531535    bool haveVariances;                 // Do we have the variance maps?
    532     bool havePixels;                    // Do we have lists of pixels?
     536    bool haveRejects;                   // Do we have lists of rejected pixels?
    533537    int num;                            // Number of inputs
    534538    int numCols, numRows;               // Size of (sky) images
    535     if (!validateInputData(&haveVariances, &havePixels, &num, &numCols, &numRows, input)) {
     539    if (!validateInputData(&haveVariances, &haveRejects, &num, &numCols, &numRows, input)) {
    536540        return false;
    537541    }
     
    544548        PS_ASSERT_FLOAT_LARGER_THAN(rej, 0.0, false);
    545549    }
    546     if (havePixels) {
     550    if (haveRejects) {
    547551        // This is a subsequent combination, so expect that the image and mask already exist
    548552        PS_ASSERT_IMAGE_NON_NULL(combined->image, false);
     
    557561    }
    558562
    559     // Pull out the image weightings
    560     psVector *weights = psVectorAlloc(num, PS_TYPE_F32);
     563    psVector *weights = psVectorAlloc(num, PS_TYPE_F32); // Relative weighting for each image
     564    psArray *stack = psArrayAlloc(num); // Stack of readouts
    561565    for (int i = 0; i < num; i++) {
    562566        pmStackData *data = input->data[i]; // Stack data for this input
    563567        if (!data) {
    564568            weights->data.F32[i] = 0.0;
     569            continue;
    565570        }
    566571        weights->data.F32[i] = data->weight;
    567     }
    568 
    569     // Get the sizes
    570     psArray *stack = psArrayAlloc(input->n);
    571     for (int i = 0; i < stack->n; i++) {
    572         pmStackData *data = input->data[i]; // Stack data
    573572        stack->data[i] = psMemIncrRefCounter(data->readout);
    574573    }
     574
    575575    int minInputCols, maxInputCols, minInputRows, maxInputRows; // Smallest and largest values to combine
    576576    int xSize, ySize;                   // Size of the output image
     
    598598    combineBuffer *buffer = combineBufferAlloc(num);
    599599
    600     if (havePixels) {
    601         // Only combine select pixels
     600    if (haveRejects) {
    602601        psImage *combinedImage = combined->image; // Combined image
    603602        psImage *combinedMask = combined->mask; // Combined mask
     
    611610                continue;
    612611            }
    613             pixels = psPixelsConcatenate(pixels, data->pixels);
    614         }
    615         for (int i = 0; i < pixels->n; i++) {
    616             // Pixel coordinates are in the frame of the original image
    617             int x = pixels->data[i].x, y = pixels->data[i].y; // Coordinates of interest
    618             if (x < minInputCols || x >= maxInputCols || y < minInputRows || y >= maxInputRows) {
    619                 continue;
    620             }
    621             psVector *reject = pixelMapQuery(pixelMap, x, y); // Inspect these images closely
    622             combinePixels(combinedImage, combinedMask, combinedVariance, input, weights, reject, x, y,
    623                           maskVal, bad, numIter, rej, useVariance, safe, buffer);
     612            pixels = psPixelsConcatenate(pixels, data->reject);
     613        }
     614
     615        if (entire) {
     616            // Combine entire image
     617            for (int y = minInputRows; y < maxInputRows; y++) {
     618                for (int x = minInputCols; x < maxInputCols; x++) {
     619                    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);
     622                }
     623            }
     624        } else {
     625            // Only combine previously rejected pixels
     626            for (int i = 0; i < pixels->n; i++) {
     627                // Pixel coordinates are in the frame of the original image
     628                int x = pixels->data[i].x, y = pixels->data[i].y; // Coordinates of interest
     629                if (x < minInputCols || x >= maxInputCols || y < minInputRows || y >= maxInputRows) {
     630                    continue;
     631                }
     632                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);
     635            }
    624636        }
    625637        psFree(pixels);
     
    644656        }
    645657
    646         // Generate the pixel lists in which to place the rejected pixels
    647         if (numIter != 0) {
    648             for (int i = 0; i < num; i++) {
    649                 pmStackData *data = input->data[i]; // Stack data for this input
    650                 if (!data) {
    651                     continue;
    652                 }
    653                 data->pixels = psPixelsAllocEmpty(PIXEL_LIST_BUFFER);
    654             }
    655         }
    656 
    657658        for (int y = minInputRows; y < maxInputRows; y++) {
    658659            for (int x = minInputCols; x < maxInputCols; x++) {
     
    669670                    continue;
    670671                }
    671                 psTrace("psModules.imcombine", 5, "Image %d: %ld pixels to inspect.\n", i, data->pixels->n);
     672                psTrace("psModules.imcombine", 5, "Image %d: %ld pixels to inspect.\n", i, data->inspect->n);
    672673            }
    673674        }
  • trunk/psModules/src/imcombine/pmStack.h

    r16685 r17005  
    88 * @author GLG, MHPCC
    99 *
    10  * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    11  * @date $Date: 2008-02-27 21:16:57 $
     10 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     11 * @date $Date: 2008-03-17 21:38:43 $
    1212 *
    1313 * Copyright 2004-2007 Institute for Astronomy, University of Hawaii
     
    2828typedef struct {
    2929    pmReadout *readout;                 ///< Warped readout (sky cell)
    30     psPixels *pixels;                   ///< Pixels to inspect or reject
    31     float weight;                       ///< Weight to apply
     30    psPixels *reject;                   ///< Pixels to reject
     31    psPixels *inspect;                  ///< Pixels to inspect
     32    float weight;                       ///< Relative weighting for image
    3233} pmStackData;
    3334
     
    4546                    int numIter,        ///< Number of iterations
    4647                    float rej,          ///< Rejection limit (standard deviations)
     48                    bool entire,        ///< Combine entire image even if rejection lists provided?
    4749                    bool useVariance,   ///< Use variance values for rejection?
    4850                    bool safe           ///< Play safe with small numbers of input pixels (mask if N <= 2)?
Note: See TracChangeset for help on using the changeset viewer.