IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 5, 2009, 4:31:25 PM (17 years ago)
Author:
Paul Price
Message:

Merging pap_branch_20090128. Resolved a small number of conflicts. Compiles, but not tested in detail.

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

Legend:

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

    r21183 r21363  
    3636#define PEAK_FLUX 1.0e4                 // Peak flux for each source
    3737#define SKY_VALUE 0.0e0                 // Sky value for fake image
    38 #define WEIGHT_VAL 3.0                  // Weighting for image
    39 #define WEIGHT_FACTOR 10.0              // Factor to multiply image by to get weighting
     38#define VARIANCE_VAL 3.0                // Variance for image
     39#define VARIANCE_FACTOR 10.0            // Factor to multiply image by to get variance
    4040#define PSF_STATS PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV // Statistics options for measuring PSF
    4141#define SOURCE_FIT_ITERATIONS 100       // Number of iterations for source fitting
     
    149149            pmModel *model = pmModelFromPSFforXY(psf, x, y, PEAK_FLUX); // Model for source
    150150            psAssert (model, "failed to generate model: should this be an error or not?");
    151             float srcRadius = model->modelRadius(model->params, PS_SQR(WEIGHT_VAL)); // Radius for source
     151            float srcRadius = model->modelRadius(model->params, PS_SQR(VARIANCE_VAL)); // Radius for source
    152152            if (srcRadius > maxRadius) {
    153153                maxRadius = srcRadius;
     
    216216    psFree(envelope);
    217217
    218     // XXX Setting the weight seems to be an art
     218    // XXX Setting the variance seems to be an art
    219219    // Can't set it too high so that pixels are rejected as insignificant
    220220    // Can't set it too low so that it's hard to get to the minimum
    221221    // Have also tried:
    222     // *** readout->weight = (psImage*)psBinaryOp(NULL, readout->image, "*", readout->image);
    223     // *** readout->weight = (psImage*)psBinaryOp(NULL, readout->image, "*", psScalarAlloc(WEIGHT_FACTOR, PS_TYPE_F32));
    224     readout->weight = (psImage*)psBinaryOp(NULL, readout->image, "+", psScalarAlloc(WEIGHT_VAL, PS_TYPE_F32));
     222    // *** readout->variance = (psImage*)psBinaryOp(NULL, readout->image, "*", readout->image);
     223    // *** readout->variance = (psImage*)psBinaryOp(NULL, readout->image, "*", psScalarAlloc(VARIANCE_FACTOR, PS_TYPE_F32));
     224    readout->variance = (psImage*)psBinaryOp(NULL, readout->image, "+",
     225                                             psScalarAlloc(VARIANCE_VAL, PS_TYPE_F32));
    225226    readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);
    226227    psImageInit(readout->mask, 0);
     
    242243
    243244        psFree(source->pixels);
    244         psFree(source->weight);
     245        psFree(source->variance);
    245246        psFree(source->maskView);
    246247        psFree(source->maskObj);
    247248        source->pixels = NULL;
    248         source->weight = NULL;
     249        source->variance = NULL;
    249250        source->maskView = NULL;
    250251        source->maskObj = NULL;
     
    280281    options->psfFieldYo = 0;
    281282
    282     pmSourceFitModelInit(SOURCE_FIT_ITERATIONS, 0.01, WEIGHT_VAL, true);
     283    pmSourceFitModelInit(SOURCE_FIT_ITERATIONS, 0.01, VARIANCE_VAL, true);
    283284
    284285    pmPSFtry *try = pmPSFtryModel(fakes, modelName, options, 0, 0xff);
  • trunk/psModules/src/imcombine/pmReadoutCombine.c

    r21183 r21363  
    3737    params->iter = 1;
    3838    params->rej = INFINITY;
    39     params->weights = false;
     39    params->variances = false;
    4040
    4141    return params;
     
    7575    psStringAppend(&comment, "Combining using statistic: %x", params->combine);
    7676    if (!hdu->header) {
    77         hdu->header = psMetadataAlloc();
     77        hdu->header = psMetadataAlloc();
    7878    }
    7979    psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, "");
     
    8282    // note the clipping parameters, if used
    8383    if (params->combine == PS_STAT_CLIPPED_MEAN) {
    84         psString comment = NULL;    // Comment to add to header
    85         psStringAppend(&comment, "Combination clipping: %d iterations, rejection at %f sigma", params->iter, params->rej);
    86         psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, "");
    87         psFree(comment);
    88     }
    89 
    90     // note the use of weights
    91     if (params->weights) {
     84        psString comment = NULL;    // Comment to add to header
     85        psStringAppend(&comment, "Combination clipping: %d iterations, rejection at %f sigma", params->iter, params->rej);
     86        psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, "");
     87        psFree(comment);
     88    }
     89
     90    // note the use of variances
     91    if (params->variances) {
    9292        psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK,
    93                          "Using input weights to combine images", "");
     93                         "Using input variances to combine images", "");
    9494    }
    9595
     
    121121
    122122    // generate the required output images based on the specified sizes
    123     pmReadoutStackDefineOutput(output, col0, row0, numCols, numRows, true, params->weights, params->blank);
     123    pmReadoutStackDefineOutput(output, col0, row0, numCols, numRows, true, params->variances, params->blank);
    124124    psTrace("psModules.imcombine", 7, "Output minimum: %d,%d\n", output->col0, output->row0);
    125125
     
    177177            return false;
    178178        }
    179         if (params->weights && !readout->weight) {
     179        if (params->variances && !readout->variance) {
    180180            psError(PS_ERR_UNEXPECTED_NULL, true,
    181                     "Rejection based on weights requested, but no weights supplied for image %d.\n", i);
     181                    "Rejection based on variances requested, but no variances supplied for image %d.\n", i);
    182182            return false;
    183183        }
     
    190190    }
    191191
    192     // pthread_t id = pthread_self();
    193     // char name[64];
    194     // sprintf (name, "%x", (unsigned int) id);
    195     // psTimerStart (name);
    196 
    197     psStatsOptions combineStdev = 0; // Statistics option for weights
     192#if 0
     193    pthread_t id = pthread_self();
     194    char name[64];
     195    sprintf(name, "%x", (unsigned int)id);
     196    psTimerStart(name);
     197#endif
     198
     199    psStatsOptions combineStdev = 0; // Statistics option for variances
    198200    switch (params->combine) {
    199201      case PS_STAT_SAMPLE_MEAN:
     
    250252    psVectorMaskType *maskData = mask->data.PS_TYPE_VECTOR_MASK_DATA;     // Dereference mask
    251253
    252     psVector *weights = NULL;           // Stack of weights
    253     psVector *errors = NULL;            // Stack of errors (sqrt of variance/weights), for psVectorStats
    254     psF32 *weightsData = NULL;          // Dereference weights
    255     if (params->weights) {
    256         weights = psVectorAlloc(inputs->n, PS_TYPE_F32); // Stack of weights
    257         weightsData = weights->data.F32;
     254    psVector *variances = NULL;           // Stack of variances
     255    psVector *errors = NULL;            // Stack of errors (sqrt of variance), for psVectorStats
     256    psF32 *variancesData = NULL;          // Dereference variances
     257    if (params->variances) {
     258        variances = psVectorAlloc(inputs->n, PS_TYPE_F32); // Stack of variances
     259        variancesData = variances->data.F32;
    258260    }
    259261    psVector *index = NULL;             // The indices to sort the pixels
     
    279281    psF32 **outputImage  = output->image->data.F32; // Output image
    280282    psImageMaskType **outputMask   = output->mask->data.PS_TYPE_IMAGE_MASK_DATA; // Output mask
    281     psF32 **outputWeight = NULL; // Output weight map
    282     if (output->weight) {
    283         outputWeight = output->weight->data.F32;
     283    psF32 **outputVariance = NULL; // Output variance map
     284    if (output->variance) {
     285        outputVariance = output->variance->data.F32;
    284286    }
    285287
     
    323325                }
    324326
    325                 if (params->weights) {
    326                     weightsData[r] = readout->weight->data.F32[yIn][xIn];
     327                if (params->variances) {
     328                    variancesData[r] = readout->variance->data.F32[yIn][xIn];
    327329                }
    328330
     
    332334                if (scale) {
    333335                    pixelsData[r] *= invScale->data.F32[r];
    334                     if (params->weights) {
    335                         weightsData[r] *= invScale->data.F32[r] * invScale->data.F32[r];
     336                    if (params->variances) {
     337                        variancesData[r] *= invScale->data.F32[r] * invScale->data.F32[r];
    336338                    }
    337339                }
     
    376378
    377379            // XXXXX this step probably is very expensive : convert errors to variance everywhere?
    378             if (params->weights) {
    379                 errors = (psVector*)psUnaryOp(errors, weights, "sqrt");
     380            if (params->variances) {
     381                errors = (psVector*)psUnaryOp(errors, variances, "sqrt");
    380382            }
    381383
     
    386388                outputImage[yOut][xOut] = NAN;
    387389                outputMask[yOut][xOut] = params->blank;
    388                 if (params->weights) {
    389                     outputWeight[yOut][xOut] = NAN;
     390                if (params->variances) {
     391                    outputVariance[yOut][xOut] = NAN;
    390392                }
    391393                sigma->data.F32[yOut][xOut] = NAN;
     
    393395                outputImage[yOut][xOut] = psStatsGetValue(stats, params->combine);
    394396                outputMask[yOut][xOut] = isfinite(outputImage[yOut][xOut]) ? 0 : params->blank;
    395                 if (params->weights) {
     397                if (params->variances) {
    396398                    float stdev = psStatsGetValue(stats, combineStdev);
    397                     outputWeight[yOut][xOut] = PS_SQR(stdev); // Variance
     399                    outputVariance[yOut][xOut] = PS_SQR(stdev); // Variance
    398400                    // XXXX this is not the correct formal error.
    399401                    // also, the weighted mean is not obviously the correct thing here
     
    412414    psFree(pixels);
    413415    psFree(mask);
    414     psFree(weights);
     416    psFree(variances);
    415417    psFree(errors);
    416418    psFree(stats);
  • trunk/psModules/src/imcombine/pmReadoutCombine.h

    r21183 r21363  
    55 * @author Paul Price, IfA
    66 *
    7  * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
    8  * @date $Date: 2009-01-27 06:39:38 $
     7 * @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
     8 * @date $Date: 2009-02-06 02:31:25 $
    99 * Copyright 2004-2006 Institute for Astronomy, University of Hawaii
    1010 */
     
    2222typedef struct {
    2323    psStatsOptions combine;             ///< Statistic to use when performing the combination
    24     psImageMaskType maskVal;            ///< Mask value
    25     psImageMaskType blank;            ///< Mask value to give blank (i.e., no data) pixels
     24    psImageMaskType maskVal;            ///< Mask value
     25    psImageMaskType blank;            ///< Mask value to give blank (i.e., no data) pixels
    2626    int nKeep;                          ///< Mimimum number of pixels to keep
    2727    float fracHigh;                     ///< Fraction of high pixels to immediately throw
     
    2929    int iter;                           ///< Number of iterations for clipping (for CLIPPED_MEAN only)
    3030    float rej;                          ///< Rejection threshould for clipping (for CLIPPED_MEAN only)
    31     bool weights;                       ///< Use the supplied weights (instead of calculated stdev)?
     31    bool variances;                     ///< Use the supplied variances (instead of calculated stdev)?
    3232} pmCombineParams;
    3333
     
    4141/// Combine multiple readouts, applying zero and scale, with optional minmax clipping
    4242bool pmReadoutCombine(pmReadout *output,///< Output readout; altered and returned
    43                       const psArray *inputs,  ///< Array of input readouts (F32 image and weight, U8 mask)
     43                      const psArray *inputs,  ///< Array of input readouts
    4444                      const psVector *zero, ///< Zero corrections to subtract from input, or NULL
    4545                      const psVector *scale, ///< Scale corrections to divide into input, or NULL
  • trunk/psModules/src/imcombine/pmStack.c

    r21183 r21363  
    88 *  @author GLG, MHPCC
    99 *
    10  *  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2009-01-27 06:39:38 $
     10 *  @version $Revision: 1.47 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2009-02-06 02:31:25 $
    1212 *  Copyright 2004-2007 Institute for Astronomy, University of Hawaii
    1313 *
     
    3030#define PIXEL_LIST_BUFFER 100           // Number of entries to add to pixel list at a time
    3131#define PIXEL_MAP_BUFFER 2              // Number of entries to add to pixel map at a time
    32 //#define VARIANCE_FACTORS                // Use variance factors when calculating the variances?
     32#define VARIANCE_FACTORS                // Use variance factors when calculating the variances?
     33//#define ADD_VARIANCE                  // Allow additional variance (besides variance factor)?
    3334#define NUM_DIRECT_STDEV 5              // For less than this number of values, measure stdev directly
    3435
     
    263264
    264265        psImage *image = data->readout->image; // Image of interest
    265         psImage *variance = data->readout->weight; // Variance ("weight") map of interest
     266        psImage *variance = data->readout->variance; // Variance map of interest
    266267        pixelData->data.F32[num] = image->data.F32[yIn][xIn];
    267268        if (variance) {
     
    442443    *numCols = data->readout->image->numCols;
    443444    *numRows = data->readout->image->numRows;
    444     if (data->readout->weight) {
     445    if (data->readout->variance) {
    445446        *haveVariances = true;
    446         PS_ASSERT_IMAGE_NON_NULL(data->readout->weight, false);
    447         PS_ASSERT_IMAGES_SIZE_EQUAL(data->readout->image, data->readout->weight, false);
    448         PS_ASSERT_IMAGE_TYPE(data->readout->weight, PS_TYPE_F32, false);
     447        PS_ASSERT_IMAGE_NON_NULL(data->readout->variance, false);
     448        PS_ASSERT_IMAGES_SIZE_EQUAL(data->readout->image, data->readout->variance, false);
     449        PS_ASSERT_IMAGE_TYPE(data->readout->variance, PS_TYPE_F32, false);
    449450    }
    450451    *haveRejects = (data->reject != NULL);
     
    473474        PS_ASSERT_IMAGES_SIZE_EQUAL(data->readout->image, data->readout->mask, false);
    474475        if (*haveVariances) {
    475             PS_ASSERT_IMAGE_NON_NULL(data->readout->weight, false);
    476             PS_ASSERT_IMAGES_SIZE_EQUAL(data->readout->image, data->readout->weight, false);
    477             PS_ASSERT_IMAGE_TYPE(data->readout->weight, PS_TYPE_F32, false);
     476            PS_ASSERT_IMAGE_NON_NULL(data->readout->variance, false);
     477            PS_ASSERT_IMAGES_SIZE_EQUAL(data->readout->image, data->readout->variance, false);
     478            PS_ASSERT_IMAGE_TYPE(data->readout->variance, PS_TYPE_F32, false);
    478479        }
    479480    }
     
    606607        weights->data.F32[i] = data->weight;
    607608        stack->data[i] = psMemIncrRefCounter(data->readout);
    608         // Variance factor
    609         float vf = psMetadataLookupF32(NULL, data->readout->parent->concepts, "CELL.VARFACTOR"); // Var factor
    610         if (!isfinite(vf)) {
    611             psWarning("Non-finite CELL.VARFACTOR for image %d --- setting to unity.", i);
    612             vf = 1.0;
    613         }
    614         varFactors->data.F32[i] = vf;
     609        varFactors->data.F32[i] = data->readout->covariance ?
     610            psImageCovarianceFactor(data->readout->covariance) : 1.0;
     611#if 0
    615612        if (isfinite(data->addVariance)) {
    616613            varFactors->data.F32[i] *= data->addVariance;
    617614        }
     615#endif
    618616        if (!haveRejects && !data->inspect) {
    619617            data->inspect = psPixelsAllocEmpty(PIXEL_LIST_BUFFER);
     
    649647        psImage *combinedImage = combined->image; // Combined image
    650648        psImage *combinedMask = combined->mask; // Combined mask
    651         psImage *combinedVariance = combined->weight; // Combined variance map
     649        psImage *combinedVariance = combined->variance; // Combined variance map
    652650
    653651        psArray *pixelMap = pixelMapGenerate(input, minInputCols, maxInputCols,
     
    702700        }
    703701
    704         psImage *combinedVariance = combined->weight; // Combined variance map
     702        psImage *combinedVariance = combined->variance; // Combined variance map
    705703        if (haveVariances && !combinedVariance) {
    706             combined->weight = psImageAlloc(numCols, numRows, PS_TYPE_F32);
    707             combinedVariance = combined->weight;
     704            combined->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     705            combinedVariance = combined->variance;
    708706        }
    709707
  • trunk/psModules/src/imcombine/pmSubtraction.c

    r21351 r21363  
    6060
    6161    // Normalise so that the sum of the variance kernel is the square of the sum of the normal kernel
    62     // This is required to keep the relative scaling between the image and the weight map
     62    // This is required to keep the relative scaling between the image and the variance map
    6363    psBinaryOp(out->image, out->image, "*", psScalarAlloc(PS_SQR(sumNormal) / sumVariance, PS_TYPE_F32));
    6464
     
    287287
    288288// Convolve an image using FFT
    289 static void convolveWeightFFT(psImage *target,// Place the result in here
    290                               psImage *weight, // Weight map to convolve
     289static void convolveVarianceFFT(psImage *target,// Place the result in here
     290                              psImage *variance, // Variance map to convolve
    291291                              psImage *sys, // Systematic error image
    292292                              psImage *mask, // Mask image
     
    302302    bool threaded = pmSubtractionThreaded(); // Are we running threaded?
    303303
    304     psImage *subWeight = convolveSubsetAlloc(weight, border, threaded); // Weight map
     304    psImage *subVariance = convolveSubsetAlloc(variance, border, threaded); // Variance map
    305305    psImage *subSys = convolveSubsetAlloc(sys, border, threaded); // Systematic error image
    306306    psImage *subMask = convolveSubsetAlloc(mask, border, threaded); // Mask
    307307
    308308    // XXX Can trim this a little by combining the convolution: only have to take the FFT of the kernel once
    309     psImage *convWeight = psImageConvolveFFT(NULL, subWeight, subMask, maskVal, kernel); // Convolved weight
     309    psImage *convVariance = psImageConvolveFFT(NULL, subVariance, subMask, maskVal, kernel); // Convolved variance
    310310    psImage *convSys = subSys ? psImageConvolveFFT(NULL, subSys, subMask, maskVal, kernel) : NULL; // Conv sys
    311311
    312     convolveSubsetFree(weight, subWeight, threaded);
     312    convolveSubsetFree(variance, subVariance, threaded);
    313313    convolveSubsetFree(sys, subSys, threaded);
    314314    convolveSubsetFree(mask, subMask, threaded);
     
    319319        for (int yTarget = yMin, ySource = size; yTarget < yMax; yTarget++, ySource++) {
    320320            for (int xTarget = xMin, xSource = size; xTarget < xMax; xTarget++, xSource++) {
    321                 target->data.F32[yTarget][xTarget] = convWeight->data.F32[ySource][xSource] +
     321                target->data.F32[yTarget][xTarget] = convVariance->data.F32[ySource][xSource] +
    322322                    convSys->data.F32[ySource][xSource];
    323323            }
     
    326326        int numBytes = (xMax - xMin) * PSELEMTYPE_SIZEOF(PS_TYPE_F32); // Number of bytes to copy
    327327        for (int yTarget = yMin, ySource = size; yTarget < yMax; yTarget++, ySource++) {
    328             memcpy(&target->data.F32[yTarget][xMin], &convWeight->data.F32[ySource][size], numBytes);
    329         }
    330     }
    331 
    332     psFree(convWeight);
     328            memcpy(&target->data.F32[yTarget][xMin], &convVariance->data.F32[ySource][size], numBytes);
     329        }
     330    }
     331
     332    psFree(convVariance);
    333333    psFree(convSys);
    334334
     
    361361// Convolve a region of an image
    362362static inline void convolveRegion(psImage *convImage, // Convolved image (output)
    363                                   psImage *convWeight, // Convolved weight map (output), or NULL
     363                                  psImage *convVariance, // Convolved variance map (output), or NULL
    364364                                  psImage *convMask, // Convolve mask (output), or NULL
    365365                                  psKernel **kernelImage, // Convolution kernel for the image
    366                                   psKernel **kernelWeight, // Convolution kernel for the weight map, or NULL
     366                                  psKernel **kernelVariance, // Convolution kernel for the variance map, or NULL
    367367                                  psImage *image, // Image to convolve
    368                                   psImage *weight, // Weight map to convolve, or NULL
     368                                  psImage *variance, // Variance map to convolve, or NULL
    369369                                  psImage *sys, // Systematic error image, or NULL
    370370                                  psImage *subMask, // Subtraction mask
     
    381381{
    382382    *kernelImage = solvedKernel(*kernelImage, kernels, polyValues, wantDual);
    383     if (weight || subMask) {
    384         *kernelWeight = varianceKernel(*kernelWeight, *kernelImage);
     383    if (variance || subMask) {
     384        *kernelVariance = varianceKernel(*kernelVariance, *kernelImage);
    385385    }
    386386
     
    398398    }
    399399
    400     // Convolve the image and weight
     400    // Convolve the image and variance
    401401    if (useFFT) {
    402402        // Use Fast Fourier Transform to do the convolution
    403403        // This provides a big speed-up for large kernels
    404404        convolveFFT(convImage, image, subMask, subBad, *kernelImage, region, background, kernels->size);
    405         if (weight) {
    406             convolveWeightFFT(convWeight, weight, sys, subMask, subBad, *kernelWeight, region, kernels->size);
     405        if (variance) {
     406            convolveVarianceFFT(convVariance, variance, sys, subMask, subBad, *kernelVariance, region, kernels->size);
    407407        }
    408408    } else {
    409409        // XXX Direct convolution doesn't account for bad pixels yet
    410410        convolveDirect(convImage, image, *kernelImage, region, background, kernels->size);
    411         if (weight) {
    412             convolveDirect(convWeight, weight, *kernelWeight, region, 0.0, kernels->size);
     411        if (variance) {
     412            convolveDirect(convVariance, variance, *kernelVariance, region, 0.0, kernels->size);
    413413        }
    414414    }
     
    885885                psFree(stamp->image1);
    886886                psFree(stamp->image2);
    887                 psFree(stamp->weight);
    888                 stamp->image1 = stamp->image2 = stamp->weight = NULL;
     887                psFree(stamp->variance);
     888                stamp->image1 = stamp->image2 = stamp->variance = NULL;
    889889                psFree(stamp->matrix1);
    890890                psFree(stamp->matrix2);
     
    915915}
    916916
    917 psImage *pmSubtractionKernelImage(const pmSubtractionKernels *kernels, float x, float y, bool wantDual)
     917psKernel *pmSubtractionKernel(const pmSubtractionKernels *kernels, float x, float y, bool wantDual)
    918918{
    919919    PM_ASSERT_SUBTRACTION_KERNELS_NON_NULL(kernels, NULL);
     
    922922    PS_ASSERT_FLOAT_WITHIN_RANGE(y, -1.0, 1.0, NULL);
    923923
    924     // Precalulate polynomial values
    925     psImage *polyValues = p_pmSubtractionPolynomial(NULL, kernels->spatialOrder, x, y);
    926 
    927     // The appropriate kernel
    928     psKernel *kernel = solvedKernel(NULL, kernels, polyValues, wantDual);
    929 
     924    psImage *polyValues = p_pmSubtractionPolynomial(NULL, kernels->spatialOrder, x, y); // Solved polynomial
     925    psKernel *kernel = solvedKernel(NULL, kernels, polyValues, wantDual); // The appropriate kernel
    930926    psFree(polyValues);
    931927
     928    return kernel;
     929}
     930
     931psImage *pmSubtractionKernelImage(const pmSubtractionKernels *kernels, float x, float y, bool wantDual)
     932{
     933    PM_ASSERT_SUBTRACTION_KERNELS_NON_NULL(kernels, NULL);
     934    PM_ASSERT_SUBTRACTION_KERNELS_SOLUTION(kernels, NULL);
     935    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, NULL);
     936    PS_ASSERT_FLOAT_WITHIN_RANGE(y, -1.0, 1.0, NULL);
     937
     938    psKernel *kernel = pmSubtractionKernel(kernels, x, y, wantDual); // Convolution kernel
    932939    psImage *image = psMemIncrRefCounter(kernel->image); // Image of the kernel
    933940    psFree(kernel);
     
    989996
    990997
    991 // XXX Put kernelImage, kernelWeight and polyValues on thread-dependent data
     998// XXX Put kernelImage, kernelVariance and polyValues on thread-dependent data
    992999static bool subtractionConvolvePatch(int numCols, int numRows, // Size of image
    9931000                                     int x0, int y0, // Offsets for image
     
    10101017
    10111018    psKernel *kernelImage = NULL;       // Kernel for the images
    1012     psKernel *kernelWeight = NULL;      // Kernel for the weight maps
     1019    psKernel *kernelVariance = NULL;      // Kernel for the variance maps
    10131020
    10141021    // Only generate polynomial values every kernel footprint, since we have already assumed
     
    10201027
    10211028    if (kernels->mode == PM_SUBTRACTION_MODE_1 || kernels->mode == PM_SUBTRACTION_MODE_DUAL) {
    1022         convolveRegion(out1->image, out1->weight, convMask, &kernelImage, &kernelWeight,
    1023                        ro1->image, ro1->weight, sys1, subMask, kernels, polyValues, background, *region,
     1029        convolveRegion(out1->image, out1->variance, convMask, &kernelImage, &kernelVariance,
     1030                       ro1->image, ro1->variance, sys1, subMask, kernels, polyValues, background, *region,
    10241031                       maskBad, maskPoor, poorFrac, useFFT, false);
    10251032    }
    10261033    if (kernels->mode == PM_SUBTRACTION_MODE_2 || kernels->mode == PM_SUBTRACTION_MODE_DUAL) {
    1027         convolveRegion(out2->image, out2->weight, convMask, &kernelImage, &kernelWeight,
    1028                        ro2->image, ro2->weight, sys2, subMask, kernels, polyValues, background, *region,
     1034        convolveRegion(out2->image, out2->variance, convMask, &kernelImage, &kernelVariance,
     1035                       ro2->image, ro2->variance, sys2, subMask, kernels, polyValues, background, *region,
    10291036                       maskBad, maskPoor, poorFrac, useFFT, kernels->mode == PM_SUBTRACTION_MODE_DUAL);
    10301037    }
    10311038
    10321039    psFree(kernelImage);
    1033     psFree(kernelWeight);
     1040    psFree(kernelVariance);
    10341041    psFree(polyValues);
    10351042
     
    11481155            // XXX }
    11491156        }
    1150         if (ro1->weight) {
    1151             if (!out1->weight) {
    1152                 out1->weight = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     1157        if (ro1->variance) {
     1158            if (!out1->variance) {
     1159                out1->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32);
    11531160                // XXX if (threaded) {
    1154                 // XXX     psMutexInit(out1->weight);
     1161                // XXX     psMutexInit(out1->variance);
    11551162                // XXX }
    11561163            }
    1157             psImageInit(out1->weight, 0.0);
     1164            psImageInit(out1->variance, 0.0);
    11581165        }
    11591166    }
     
    11651172            // XXX }
    11661173        }
    1167         if (ro2->weight) {
    1168             if (!out2->weight) {
    1169                 out2->weight = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     1174        if (ro2->variance) {
     1175            if (!out2->variance) {
     1176                out2->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32);
    11701177                // XXX if (threaded) {
    1171                 // XXX     psMutexInit(out2->weight);
     1178                // XXX     psMutexInit(out2->variance);
    11721179                // XXX }
    11731180            }
    1174             psImageInit(out2->weight, 0.0);
     1181            psImageInit(out2->variance, 0.0);
    11751182        }
    11761183    }
     
    12321239    psImage *polyValues = NULL;         // Pre-calculated polynomial values
    12331240    psKernel *kernelImage = NULL;       // Kernel for the images
    1234     psKernel *kernelWeight = NULL;      // Kernel for the weight maps
     1241    psKernel *kernelVariance = NULL;      // Kernel for the variance maps
    12351242#endif
    12361243
     
    12991306                psFree(job);
    13001307            } else {
    1301                 subtractionConvolvePatch(numCols, numRows, x0, y0, out1, out2, convMask, ro1, ro2,
    1302                                          sys1, sys2, subMask, maskBad, maskPoor, poorFrac, subRegion,
    1303                                          kernels, doBG, useFFT);
     1308                subtractionConvolvePatch(numCols, numRows, x0, y0, out1, out2, convMask, ro1, ro2, sys1, sys2,
     1309                                         subMask, maskBad, maskPoor, poorFrac, subRegion, kernels, doBG,
     1310                                         useFFT);
    13041311            }
    13051312            psFree(subRegion);
     
    13341341        // XXX }
    13351342    }
    1336 
    13371343    psImageConvolveSetThreads(oldThreads);
    13381344
    13391345    psFree(sys1);
    13401346    psFree(sys2);
     1347
     1348    // Calculate covariances
     1349    // This can take a while, so we only do it for a single instance
     1350    // XXX psImageCovarianceCalculate could be multithreaded
     1351    if (kernels->mode == PM_SUBTRACTION_MODE_1 || kernels->mode == PM_SUBTRACTION_MODE_DUAL) {
     1352        psKernel *kernel = pmSubtractionKernel(kernels, 0.0, 0.0, false); // Convolution kernel
     1353        out1->covariance = psImageCovarianceCalculate(kernel, ro1->covariance);
     1354        psFree(kernel);
     1355    }
     1356    if (kernels->mode == PM_SUBTRACTION_MODE_2 || kernels->mode == PM_SUBTRACTION_MODE_DUAL) {
     1357        psKernel *kernel = pmSubtractionKernel(kernels, 0.0, 0.0,
     1358                                               kernels->mode == PM_SUBTRACTION_MODE_DUAL); // Conv. kernel
     1359        out2->covariance = psImageCovarianceCalculate(kernel, ro2->covariance);
     1360        psFree(kernel);
     1361    }
    13411362
    13421363    // Copy anything that wasn't convolved
     
    13451366        if (out2) {
    13461367            out2->image = psMemIncrRefCounter(ro2->image);
    1347             out2->weight = psMemIncrRefCounter(ro2->weight);
     1368            out2->variance = psMemIncrRefCounter(ro2->variance);
    13481369            out2->mask = psMemIncrRefCounter(ro2->mask);
     1370            out2->covariance = psMemIncrRefCounter(ro2->covariance);
    13491371        }
    13501372        break;
     
    13521374        if (out1) {
    13531375            out1->image = psMemIncrRefCounter(ro1->image);
    1354             out1->weight = psMemIncrRefCounter(ro1->weight);
     1376            out1->variance = psMemIncrRefCounter(ro1->variance);
    13551377            out1->mask = psMemIncrRefCounter(ro1->mask);
     1378            out1->covariance = psMemIncrRefCounter(ro1->covariance);
    13561379        }
    13571380        break;
  • trunk/psModules/src/imcombine/pmSubtraction.h

    r21183 r21363  
    66 * @author GLG, MHPCC
    77 *
    8  * @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
    9  * @date $Date: 2009-01-27 06:39:38 $
     8 * @version $Revision: 1.36 $ $Name: not supported by cvs2svn $
     9 * @date $Date: 2009-02-06 02:31:25 $
    1010 * Copyright 2004-207 Institute for Astronomy, University of Hawaii
    1111 */
     
    7070                              float sigmaRej, ///< Number of RMS deviations above zero at which to reject
    7171                              int footprint ///< Half-size of stamp
     72    );
     73
     74/// Generate the convolution kernel
     75psKernel *pmSubtractionKernel(const pmSubtractionKernels *kernels, ///< Kernel parameters
     76                              float x, float y, ///< Normalised position [-1,1] for which to generate image
     77                              bool wantDual ///< Calculate for the dual kernel?
    7278    );
    7379
  • trunk/psModules/src/imcombine/pmSubtractionEquation.c

    r20561 r21363  
    2424static inline double calculateSumProduct(const psKernel *image1, // First image in multiplication
    2525                                         const psKernel *image2, // Second image in multiplication
    26                                          const psKernel *weight, // Weight image
     26                                         const psKernel *variance, // Variance image
    2727                                         int footprint // (Half-)Size of stamp
    2828    )
     
    3131    for (int y = - footprint; y <= footprint; y++) {
    3232        for (int x = - footprint; x <= footprint; x++) {
    33             sum += image1->kernel[y][x] * image2->kernel[y][x] / 1.0; // weight->kernel[y][x];
     33            sum += image1->kernel[y][x] * image2->kernel[y][x] / 1.0; // variance->kernel[y][x];
    3434        }
    3535    }
     
    4242                                           const psKernel *image1, // First image in multiplication
    4343                                           const psKernel *image2, // Second image in multiplication
    44                                            const psKernel *weight, // Weight image
     44                                           const psKernel *variance, // Variance image
    4545                                           const psImage *polyValues, // Spatial polynomial values
    4646                                           int numKernels, // Number of kernel basis functions
     
    5050    )
    5151{
    52     double sum = calculateSumProduct(image1, image2, weight, footprint); // Sum of the image products
     52    double sum = calculateSumProduct(image1, image2, variance, footprint); // Sum of the image products
    5353    if (!isfinite(sum)) {
    5454        return false;
     
    7979                                           const psKernel *image1, // First image in multiplication
    8080                                           const psKernel *image2, // Second image in multiplication
    81                                            const psKernel *weight, // Weight image
     81                                           const psKernel *variance, // Variance image
    8282                                           const psImage *polyValues, // Spatial polynomial values
    8383                                           int numKernels, // Number of kernel basis functions
     
    8787    )
    8888{
    89     double sum = calculateSumProduct(image1, image2, weight, footprint); // Sum of the image products
     89    double sum = calculateSumProduct(image1, image2, variance, footprint); // Sum of the image products
    9090    if (!isfinite(sum)) {
    9191        return false;
     
    120120                                  const psArray *convolutions1, // Convolutions for element 1
    121121                                  const psArray *convolutions2, // Convolutions for element 2
    122                                   const psKernel *weight, // Weight image
     122                                  const psKernel *variance, // Variance image
    123123                                  const psImage *polyValues, // Polynomial values
    124124                                  int numKernels, // Number of kernel basis functions
     
    135135            psKernel *jConv = convolutions2->data[j]; // Convolution for j-th element
    136136
    137             if (!calculateMatrixElement2(matrix, i, j, iConv, jConv, weight, polyValues, numKernels,
     137            if (!calculateMatrixElement2(matrix, i, j, iConv, jConv, variance, polyValues, numKernels,
    138138                                         footprint, spatialOrder, symmetric)) {
    139139                psTrace("psModules.imcombine", 2, "Bad sumCC at %d, %d", i, j);
     
    151151                            const psArray *convolutions, // Convolutions of source with kernels
    152152                            const psKernel *input, // Input stamp, or NULL
    153                             const psKernel *weight, // Weight stamp
     153                            const psKernel *variance, // Variance stamp
    154154                            const psImage *polyValues, // Spatial polynomial values
    155155                            int footprint, // (Half-)Size of stamp
     
    171171
    172172    // Square part of the matrix (convolution-convolution products)
    173     if (!calculateMatrixSquare(matrix, convolutions, convolutions, weight, polyValues, numKernels,
     173    if (!calculateMatrixSquare(matrix, convolutions, convolutions, variance, polyValues, numKernels,
    174174                               spatialOrder, footprint)) {
    175175        return false;
     
    185185
    186186            // Normalisation-convolution terms
    187             if (!calculateMatrixElement1(matrix, i, normIndex, conv, input, weight, polyValues, numKernels,
     187            if (!calculateMatrixElement1(matrix, i, normIndex, conv, input, variance, polyValues, numKernels,
    188188                                         footprint, spatialOrder, true)) {
    189189                psTrace("psModules.imcombine", 2, "Bad sumIC at %d", i);
     
    195195            for (int y = - footprint; y <= footprint; y++) {
    196196                for (int x = - footprint; x <= footprint; x++) {
    197                     sumC += conv->kernel[y][x] / 1.0; // weight->kernel[y][x];
     197                    sumC += conv->kernel[y][x] / 1.0; // variance->kernel[y][x];
    198198                }
    199199            }
     
    218218        for (int y = - footprint; y <= footprint; y++) {
    219219            for (int x = - footprint; x <= footprint; x++) {
    220                 double invNoise2 = 1.0 / 1.0; // weight->kernel[y][x];
     220                double invNoise2 = 1.0 / 1.0; // variance->kernel[y][x];
    221221                double value = input->kernel[y][x] * invNoise2;
    222222                sumI += value;
     
    253253                            const psKernel *input, // Input stamp, or NULL if !normAndBG
    254254                            const psKernel *target, // Target stamp
    255                             const psKernel *weight, // Weight stamp
     255                            const psKernel *variance, // Variance stamp
    256256                            const psImage *polyValues, // Spatial polynomial values
    257257                            int footprint, // (Half-)Size of stamp
     
    277277        for (int y = - footprint; y <= footprint; y++) {
    278278            for (int x = - footprint; x <= footprint; x++) {
    279                 sumTC += target->kernel[y][x] * conv->kernel[y][x] / 1.0; // weight->kernel[y][x];
     279                sumTC += target->kernel[y][x] * conv->kernel[y][x] / 1.0; // variance->kernel[y][x];
    280280            }
    281281        }
     
    297297        for (int y = - footprint; y <= footprint; y++) {
    298298            for (int x = - footprint; x <= footprint; x++) {
    299                 float value = target->kernel[y][x] / 1.0; // weight->kernel[y][x];
     299                float value = target->kernel[y][x] / 1.0; // variance->kernel[y][x];
    300300                sumIT += value * input->kernel[y][x];
    301301                sumT += value;
     
    329329                                 const psArray *convolutions2, // Convolutions of image 2
    330330                                 const psKernel *image1, // Image 1 stamp
    331                                  const psKernel *weight, // Weight stamp
     331                                 const psKernel *variance, // Variance stamp
    332332                                 const psImage *polyValues, // Spatial polynomial values
    333333                                 int footprint // (Half-)Size of stamp
     
    348348    PM_SUBTRACTION_INDICES(normIndex, bgIndex, kernels);
    349349
    350     if (!calculateMatrixSquare(matrix, convolutions1, convolutions2, weight, polyValues, numKernels,
     350    if (!calculateMatrixSquare(matrix, convolutions1, convolutions2, variance, polyValues, numKernels,
    351351                               spatialOrder, footprint)) {
    352352        return false;
     
    356356        // Normalisation
    357357        psKernel *conv = convolutions2->data[i]; // Convolution
    358         if (!calculateMatrixElement1(matrix, i, normIndex, conv, image1, weight, polyValues, numKernels,
     358        if (!calculateMatrixElement1(matrix, i, normIndex, conv, image1, variance, polyValues, numKernels,
    359359                                     footprint, spatialOrder, false)) {
    360360            psTrace("psModules.imcombine", 2, "Bad sumIC at %d", i);
     
    366366        for (int y = - footprint; y <= footprint; y++) {
    367367            for (int x = - footprint; x <= footprint; x++) {
    368                 sumC += conv->kernel[y][x] / 1.0; // weight->kernel[y][x];
     368                sumC += conv->kernel[y][x] / 1.0; // variance->kernel[y][x];
    369369            }
    370370        }
     
    559559      case PM_SUBTRACTION_MODE_1:
    560560        status = calculateMatrix(stamp->matrix1, kernels, stamp->convolutions1, stamp->image1,
    561                                  stamp->weight, polyValues, footprint, true);
     561                                 stamp->variance, polyValues, footprint, true);
    562562        status &= calculateVector(stamp->vector1, kernels, stamp->convolutions1, stamp->image1,
    563                                   stamp->image2, stamp->weight, polyValues, footprint, true);
     563                                  stamp->image2, stamp->variance, polyValues, footprint, true);
    564564        break;
    565565      case PM_SUBTRACTION_MODE_2:
    566566        status = calculateMatrix(stamp->matrix1, kernels, stamp->convolutions2, stamp->image2,
    567                                  stamp->weight, polyValues, footprint, true);
     567                                 stamp->variance, polyValues, footprint, true);
    568568        status &= calculateVector(stamp->vector1, kernels, stamp->convolutions2, stamp->image2,
    569                                   stamp->image1, stamp->weight, polyValues, footprint, true);
     569                                  stamp->image1, stamp->variance, polyValues, footprint, true);
    570570        break;
    571571      case PM_SUBTRACTION_MODE_DUAL:
     
    581581#endif
    582582        status  = calculateMatrix(stamp->matrix1, kernels, stamp->convolutions1, stamp->image1,
    583                                   stamp->weight, polyValues, footprint, true);
     583                                  stamp->variance, polyValues, footprint, true);
    584584        status &= calculateMatrix(stamp->matrix2, kernels, stamp->convolutions2, NULL,
    585                                   stamp->weight, polyValues, footprint, false);
     585                                  stamp->variance, polyValues, footprint, false);
    586586        status &= calculateMatrixCross(stamp->matrixX, kernels, stamp->convolutions1,
    587                                        stamp->convolutions2, stamp->image1, stamp->weight, polyValues,
     587                                       stamp->convolutions2, stamp->image1, stamp->variance, polyValues,
    588588                                       footprint);
    589589        status &= calculateVector(stamp->vector1, kernels, stamp->convolutions1, stamp->image1,
    590                                   stamp->image2, stamp->weight, polyValues, footprint, true);
     590                                  stamp->image2, stamp->variance, polyValues, footprint, true);
    591591        status &= calculateVector(stamp->vector2, kernels, stamp->convolutions2, NULL,
    592                                   stamp->image2, stamp->weight, polyValues, footprint, false);
     592                                  stamp->image2, stamp->variance, polyValues, footprint, false);
    593593        break;
    594594      default:
     
    10331033
    10341034        // Calculate residuals
    1035         psKernel *weight = stamp->weight; // Weight postage stamp
     1035        psKernel *variance = stamp->variance; // Variance postage stamp
    10361036        psImageInit(residual->image, 0.0);
    10371037        if (kernels->mode != PM_SUBTRACTION_MODE_DUAL) {
     
    10981098        for (int y = - footprint; y <= footprint; y++) {
    10991099            for (int x = - footprint; x <= footprint; x++) {
    1100                 double dev = PS_SQR(residual->kernel[y][x]) / weight->kernel[y][x];
     1100                double dev = PS_SQR(residual->kernel[y][x]) / variance->kernel[y][x];
    11011101                deviation += dev;
    11021102#ifdef TESTING
     
    11411141            psFitsClose(fits);
    11421142        }
    1143         if (stamp->weight) {
     1143        if (stamp->variance) {
    11441144            psString filename = NULL;
    1145             psStringAppend(&filename, "stamp_weight_%03d.fits", i);
     1145            psStringAppend(&filename, "stamp_variance_%03d.fits", i);
    11461146            psFits *fits = psFitsOpen(filename, "w");
    11471147            psFree(filename);
    1148             psFitsWriteImage(fits, NULL, stamp->weight->image, 0, NULL);
     1148            psFitsWriteImage(fits, NULL, stamp->variance->image, 0, NULL);
    11491149            psFitsClose(fits);
    11501150        }
  • trunk/psModules/src/imcombine/pmSubtractionMatch.c

    r21247 r21363  
    6060                      const pmReadout *ro2, // Readout 2
    6161                      const psImage *subMask, // Mask for subtraction, or NULL
    62                       psImage *weight,  // Weight map
     62                      psImage *variance,  // Variance map
    6363                      const psRegion *region, // Region of interest, or NULL
    6464                      float threshold,  // Threshold for stamp finding
     
    8080
    8181    psTrace("psModules.imcombine", 3, "Extracting stamps...\n");
    82     if (!pmSubtractionStampsExtract(*stamps, ro1->image, ro2 ? ro2->image : NULL, weight, size)) {
     82    if (!pmSubtractionStampsExtract(*stamps, ro1->image, ro2 ? ro2->image : NULL, variance, size)) {
    8383        psError(PS_ERR_UNKNOWN, false, "Unable to extract stamps.");
    8484        return false;
     
    111111            conv1->mask = NULL;
    112112        }
    113         if (conv1->weight) {
    114             psFree(conv1->weight);
    115             conv1->weight = NULL;
     113        if (conv1->variance) {
     114            psFree(conv1->variance);
     115            conv1->variance = NULL;
    116116        }
    117117    }
     
    126126            conv2->mask = NULL;
    127127        }
    128         if (conv2->weight) {
    129             psFree(conv2->weight);
    130             conv2->weight = NULL;
     128        if (conv2->variance) {
     129            psFree(conv2->variance);
     130            conv2->variance = NULL;
    131131        }
    132132    }
     
    191191    }
    192192
    193     // Where does our weight map come from?
    194     // Getting the weight exactly right is not necessary --- it's just used for weighting.
    195     psImage *weight = NULL;             // Weight image to use
    196     if (ro1->weight && ro2->weight) {
    197         weight = (psImage*)psBinaryOp(NULL, ro1->weight, "+", ro2->weight);
    198     } else if (ro1->weight) {
    199         weight = psMemIncrRefCounter(ro1->weight);
    200     } else if (ro2->weight) {
    201         weight = psMemIncrRefCounter(ro2->weight);
     193    // Where does our variance map come from?
     194    // Getting the variance exactly right is not necessary --- it's just used for weighting.
     195    psImage *variance = NULL;             // Variance image to use
     196    if (ro1->variance && ro2->variance) {
     197        variance = (psImage*)psBinaryOp(NULL, ro1->variance, "+", ro2->variance);
     198    } else if (ro1->variance) {
     199        variance = psMemIncrRefCounter(ro1->variance);
     200    } else if (ro2->variance) {
     201        variance = psMemIncrRefCounter(ro2->variance);
    202202    } else {
    203         weight = (psImage*)psBinaryOp(NULL, ro1->image, "+", ro2->image);
     203        variance = (psImage*)psBinaryOp(NULL, ro1->image, "+", ro2->image);
    204204    }
    205205
     
    274274            // We get the stamps here; we will also attempt to get stamps at the first iteration, but it
    275275            // doesn't matter.
    276             if (!getStamps(&stamps, ro1, ro2, subMask, weight, NULL, threshold, stampSpacing,
     276            if (!getStamps(&stamps, ro1, ro2, subMask, variance, NULL, threshold, stampSpacing,
    277277                           size, footprint, subMode)) {
    278278                goto MATCH_ERROR;
     
    336336                psLogMsg("psModules.imcombine", PS_LOG_INFO, "Iteration %d.", k);
    337337
    338                 if (!getStamps(&stamps, ro1, ro2, subMask, weight, region, threshold, stampSpacing,
     338                if (!getStamps(&stamps, ro1, ro2, subMask, variance, region, threshold, stampSpacing,
    339339                               size, footprint, subMode)) {
    340340                    goto MATCH_ERROR;
     
    439439    psFree(subMask);
    440440    subMask = NULL;
    441     psFree(weight);
    442     weight = NULL;
    443 
    444     if (!pmSubtractionBorder(conv1->image, conv1->weight, conv1->mask, size, maskBad)) {
     441    psFree(variance);
     442    variance = NULL;
     443
     444    if (!pmSubtractionBorder(conv1->image, conv1->variance, conv1->mask, size, maskBad)) {
    445445        psError(PS_ERR_UNKNOWN, false, "Unable to set border of convolved image.");
    446446        goto MATCH_ERROR;
     
    482482    psFree(kernels);
    483483    psFree(stamps);
    484     psFree(weight);
     484    psFree(variance);
    485485    psFree(rng);
    486486    return false;
  • trunk/psModules/src/imcombine/pmSubtractionParams.c

    r18287 r21363  
    7171                            double *sumII, // Sum of I(x)^2/sigma(x)^2
    7272                            double *sumIC, // Sum of I(x)conv(x)/sigma(x)^2
    73                             const pmSubtractionStamp *stamp, // Stamp with weight
     73                            const pmSubtractionStamp *stamp, // Stamp with variance
    7474                            const psKernel *target, // Target stamp
    7575                            int kernelIndex, // Index for kernel component
     
    7878    )
    7979{
    80     psKernel *weight = stamp->weight;   // Weight, sigma(x)^2
     80    psKernel *variance = stamp->variance;   // Variance, sigma(x)^2
    8181    psKernel *convolution = selectConvolution(stamp, kernelIndex, mode); // Convolution of interest
    8282
    8383    for (int y = -footprint; y <= footprint; y++) {
    8484        psF32 *in = &target->kernel[y][-footprint]; // Dereference input
    85         psF32 *wt = &weight->kernel[y][-footprint]; // Dereference weight
     85        psF32 *wt = &variance->kernel[y][-footprint]; // Dereference variance
    8686        psF32 *conv = &convolution->kernel[y][-footprint]; // Dereference convolution
    8787        for (int x = -footprint; x <= footprint; x++, in++, wt++, conv++) {
     
    9898static void accumulateConvolutions(double *sumC, // Sum of conv(x)/sigma(x)^2
    9999                                   double *sumCC, // Sum of conv(x)^2/sigma(x)^2
    100                                    const pmSubtractionStamp *stamp, // Stamp with input and weight
     100                                   const pmSubtractionStamp *stamp, // Stamp with input and variance
    101101                                   int kernelIndex, // Index for kernel component
    102102                                   int footprint, // Size of region of interest
     
    104104    )
    105105{
    106     psKernel *weight = stamp->weight;   // Weight, sigma(x)^2
     106    psKernel *variance = stamp->variance;   // Variance, sigma(x)^2
    107107    psKernel *convolution = selectConvolution(stamp, kernelIndex, mode); // Convolution of interest
    108108
    109109    for (int y = -footprint; y <= footprint; y++) {
    110         psF32 *wt = &weight->kernel[y][-footprint]; // Dereference weight
     110        psF32 *wt = &variance->kernel[y][-footprint]; // Dereference variance
    111111        psF32 *conv = &convolution->kernel[y][-footprint]; // Dereference convolution
    112112        for (int x = -footprint; x <= footprint; x++, wt++, conv++) {
     
    120120
    121121static double accumulateChi2(const psKernel *target, // Target stamp
    122                              pmSubtractionStamp *stamp, // Stamp with weight
     122                             pmSubtractionStamp *stamp, // Stamp with variance
    123123                             int kernelIndex, // Index for kernel component
    124124                             double coeff, // Coefficient of convolution
     
    129129{
    130130    double chi2 = 0.0;
    131     psKernel *weight = stamp->weight;   // Weight, sigma(x)^2
     131    psKernel *variance = stamp->variance;   // Variance, sigma(x)^2
    132132    psKernel *convolution = selectConvolution(stamp, kernelIndex, mode); // Convolution of interest
    133133
    134134    for (int y = -footprint; y <= footprint; y++) {
    135135        psF32 *in = &target->kernel[y][-footprint]; // Dereference input
    136         psF32 *wt = &weight->kernel[y][-footprint]; // Dereference weight
     136        psF32 *wt = &variance->kernel[y][-footprint]; // Dereference variance
    137137        psF32 *conv = &convolution->kernel[y][-footprint]; // Dereference convolution
    138138        for (int x = -footprint; x <= footprint; x++, in++, wt++, conv++) {
     
    146146// Return the initial value of chi^2
    147147static double initialChi2(const psKernel *target, // Target stamp
    148                           const pmSubtractionStamp *stamp, // Stamp with weight
     148                          const pmSubtractionStamp *stamp, // Stamp with variance
    149149                          int footprint, // Size of convolution
    150150                          pmSubtractionMode mode // Mode of subtraction
    151151    )
    152152{
    153     psKernel *weight = stamp->weight;   // Weight map
     153    psKernel *variance = stamp->variance;   // Variance map
    154154    psKernel *source;                   // Source stamp
    155155    switch (mode) {
     
    167167    for (int y = -footprint; y <= footprint; y++) {
    168168        psF32 *in = &target->kernel[y][-footprint]; // Dereference input
    169         psF32 *wt = &weight->kernel[y][-footprint]; // Dereference weight
     169        psF32 *wt = &variance->kernel[y][-footprint]; // Dereference variance
    170170        psF32 *ref = &source->kernel[y][-footprint]; // Derference reference
    171171        for (int x = -footprint; x <= footprint; x++, in++, wt++, ref++) {
     
    180180// Subtract a convolution from the input
    181181static void subtractConvolution(psKernel *target, // Target stamp
    182                                 const pmSubtractionStamp *stamp, // Stamp with weight
     182                                const pmSubtractionStamp *stamp, // Stamp with variance
    183183                                int kernelIndex, // Index for kernel component
    184184                                float coeff, // Coefficient of subtraction
     
    288288
    289289        // This sum is invariant to the kernel
    290         psKernel *weight = stamp->weight; // Weight map for stamp
     290        psKernel *variance = stamp->variance; // Variance map for stamp
    291291        for (int v = -footprint; v <= footprint; v++) {
    292             psF32 *wt = &weight->kernel[v][-footprint]; // Dereference weight map
     292            psF32 *wt = &variance->kernel[v][-footprint]; // Dereference variance map
    293293            for (int u = -footprint; u <= footprint; u++, wt++) {
    294294                sum1 += 1.0 / *wt;
  • trunk/psModules/src/imcombine/pmSubtractionStamps.c

    r21183 r21363  
    5454    psFree(stamp->image1);
    5555    psFree(stamp->image2);
    56     psFree(stamp->weight);
     56    psFree(stamp->variance);
    5757    psFree(stamp->convolutions1);
    5858    psFree(stamp->convolutions2);
     
    211211    stamp->image1 = NULL;
    212212    stamp->image2 = NULL;
    213     stamp->weight = NULL;
     213    stamp->variance = NULL;
    214214    stamp->convolutions1 = NULL;
    215215    stamp->convolutions2 = NULL;
     
    333333                psFree(stamp->image1);
    334334                psFree(stamp->image2);
    335                 psFree(stamp->weight);
     335                psFree(stamp->variance);
    336336                psFree(stamp->convolutions1);
    337337                psFree(stamp->convolutions2);
    338                 stamp->image1 = stamp->image2 = stamp->weight = NULL;
     338                stamp->image1 = stamp->image2 = stamp->variance = NULL;
    339339                stamp->convolutions1 = stamp->convolutions2 = NULL;
    340340
     
    480480
    481481bool pmSubtractionStampsExtract(pmSubtractionStampList *stamps, psImage *image1, psImage *image2,
    482                                 psImage *weight, int kernelSize)
     482                                psImage *variance, int kernelSize)
    483483{
    484484    PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, false);
     
    490490        PS_ASSERT_IMAGE_TYPE(image2, PS_TYPE_F32, false);
    491491    }
    492     PS_ASSERT_IMAGE_NON_NULL(weight, false);
    493     PS_ASSERT_IMAGES_SIZE_EQUAL(weight, image1, false);
    494     PS_ASSERT_IMAGE_TYPE(weight, PS_TYPE_F32, false);
     492    PS_ASSERT_IMAGE_NON_NULL(variance, false);
     493    PS_ASSERT_IMAGES_SIZE_EQUAL(variance, image1, false);
     494    PS_ASSERT_IMAGE_TYPE(variance, PS_TYPE_F32, false);
    495495    PS_ASSERT_INT_NONNEGATIVE(kernelSize, false);
    496496
     
    520520        assert(stamp->image1 == NULL);
    521521        assert(stamp->image2 == NULL);
    522         assert(stamp->weight == NULL);
     522        assert(stamp->variance == NULL);
    523523
    524524        psRegion region = psRegionSet(x - size, x + size + 1, y - size, y + size + 1); // Region of interest
     
    534534        }
    535535
    536         psImage *wtSub = psImageSubset(weight, region); // Subimage with stamp
    537         stamp->weight = psKernelAllocFromImage(wtSub, size, size);
     536        psImage *wtSub = psImageSubset(variance, region); // Subimage with stamp
     537        stamp->variance = psKernelAllocFromImage(wtSub, size, size);
    538538        psFree(wtSub);                  // Drop reference
    539539
  • trunk/psModules/src/imcombine/pmSubtractionStamps.h

    r20465 r21363  
    6060    psKernel *image1;                   ///< Reference image postage stamp
    6161    psKernel *image2;                   ///< Input image postage stamp
    62     psKernel *weight;                   ///< Weight image postage stamp, or NULL
     62    psKernel *variance;                 ///< Variance image postage stamp, or NULL
    6363    psArray *convolutions1;             ///< Convolutions of image 1 for each kernel component, or NULL
    6464    psArray *convolutions2;             ///< Convolutions of image 2 for each kernel component, or NULL
     
    120120                                psImage *image1, ///< Reference image
    121121                                psImage *image2, ///< Input image (or NULL)
    122                                 psImage *weight, ///< Weight (variance) map
     122                                psImage *variance, ///< Variance map
    123123                                int kernelSize ///< Kernel half-size
    124124    );
  • trunk/psModules/src/imcombine/pmSubtractionThreads.c

    r21351 r21363  
    2727    // XXX     psMutexInit(ro->image);
    2828    // XXX }
    29     // XXX if (ro->weight) {
    30     // XXX     psMutexInit(ro->weight);
     29    // XXX if (ro->variance) {
     30    // XXX     psMutexInit(ro->variance);
    3131    // XXX }
    3232
     
    4343    // XXX     psMutexDestroy(ro->image);
    4444    // XXX }
    45     // XXX if (ro->weight) {
    46     // XXX     psMutexDestroy(ro->weight);
     45    // XXX if (ro->variance) {
     46    // XXX     psMutexDestroy(ro->variance);
    4747    // XXX }
    4848
Note: See TracChangeset for help on using the changeset viewer.