IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14318


Ignore:
Timestamp:
Jul 19, 2007, 11:26:12 AM (19 years ago)
Author:
Paul Price
Message:

Fixing MAJOR bug --- the rejection step wasn't doing the convolution
correctly. It was, in effect, adding each kernel component, instead
of using the solution. Fixed to look more like the code within
pmSubtractionConvolve.

File:
1 edited

Legend:

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

    r14314 r14318  
    44 *  @author GLG, MHPCC
    55 *
    6  *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
    7  *  @date $Date: 2007-07-19 03:36:06 $
     6 *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
     7 *  @date $Date: 2007-07-19 21:26:12 $
    88 *
    99 *  Copyright 2004-2007 Institute for Astronomy, University of Hawaii
     
    2525#include "pmSubtraction.h"
    2626
    27 //#define USE_FUNCTIONS_INSTEAD_OF_MACROS          // Can I pass the address of a static inline function?
     27#define USE_FUNCTIONS_INSTEAD_OF_MACROS          // Can I pass the address of a static inline function?
    2828
    2929//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     
    851851    }
    852852
    853     int numKernels = solution->n - 1;   // Number of kernel basis functions
    854 
    855     // Measure
     853    // Measure deviations
    856854    psVector *deviations = psVectorAlloc(stamps->n, PS_TYPE_F32); // Mean deviation for stamps
    857855    double totalSquareDev = 0.0;        // Total square deviation from zero
     
    859857    {
    860858        int numCols = refImage->numCols, numRows = refImage->numRows; // Image dimensions
    861 
    862859        psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN); // Statistics
    863 
    864         // Convolved image of stamp
    865         psImage *convolvedStamp = psImageAlloc(2 * footprint + 1, 2 * footprint + 1, PS_TYPE_F32);
     860        psImage *convolvedStamp = psImageAlloc(2 * footprint + 1, 2 * footprint + 1,
     861                                               PS_TYPE_F32); // Convolved image of stamp
     862        psKernel *kernelImage = NULL;       // The kernel, with which to convolve the stamps
     863        float background = solution->data.F64[solution->n-1]; // The difference in background
     864        int size = kernels->size;       // Half-size of the kernel
    866865
    867866        for (int i = 0; i < stamps->n; i++) {
     
    871870            }
    872871            int xStamp = stamp->x, yStamp = stamp->y; // Coordinates of stamp
    873             psImageInit(convolvedStamp, 0.0);
    874872
    875873            // Precalulate polynomial values
     
    878876                                                    2.0 * (float)(stamp->y - numRows/2.0) / (float)numRows);
    879877
    880             for (int y = - footprint; y <= footprint; y++) {
    881                 for (int x = footprint; x <= footprint; x++) {
    882                     for (int k = 0; k < numKernels; k++) {
    883878#ifdef USE_FUNCTIONS_INSTEAD_OF_MACROS
    884                         convolvedStamp->data.F32[y + footprint][x + footprint] +=
    885                             convolvePixel(kernels, k, xStamp + x, yStamp + y, refImage, polyValues,
    886                                           imageWeighting);
     879            kernelImage = solvedKernel(kernelImage, solution, kernels, polyValues, imageWeighting);
    887880#else
    888                         CONVOLVE_PIXEL(convolvedStamp->data.F32[y + footprint][x + footprint], kernels,
    889                                        k, xStamp + x, yStamp + y, refImage, polyValues, imageWeighting);
     881            SOLVED_KERNEL(kernelImage, solution, kernels, polyValues, imageWeighting);
    890882#endif
     883            for (int y = yStamp - footprint, j = 0; y <= yStamp + footprint; y++, j++) {
     884                for (int x = xStamp - footprint, i = 0; x <= xStamp + footprint; x++, i++) {
     885                    convolvedStamp->data.F32[j][i] = background;
     886                    for (int v = -size; v <= size; v++) {
     887                        for (int u = -size; u <= size; u++) {
     888                            convolvedStamp->data.F32[j][i] += kernelImage->kernel[v][u] *
     889                                refImage->data.F32[y + v][x + u];
     890                        }
    891891                    }
    892892                }
    893893            }
     894
    894895            psFree(polyValues);
    895896
     
    900901                   inStamp->numRows == convolvedStamp->numRows);
    901902            (void)psBinaryOp(convolvedStamp, inStamp, "-", convolvedStamp);
     903            (void)psBinaryOp(convolvedStamp, convolvedStamp, "*", convolvedStamp);
    902904            (void)psBinaryOp(convolvedStamp, convolvedStamp, "/", inStamp);
    903905            psFree(inStamp);
    904             (void)psBinaryOp(convolvedStamp, convolvedStamp, "*", convolvedStamp);
    905906            if (!psImageStats(stats, convolvedStamp, NULL, 0)) {
    906907                psError(PS_ERR_UNKNOWN, false,
     
    911912                return -1;
    912913            }
    913             deviations->data.F32[i] = stats->sampleMean;
     914            deviations->data.F32[i] = sqrt(stats->sampleMean / 2.0);
     915            psTrace("psModules.imcombine", 1, "Deviation for stamp %d: %f\n", i, deviations->data.F32[i]);
    914916            totalSquareDev += PS_SQR(deviations->data.F32[i]);
    915917            numStamps++;
    916918        }
    917919
     920        psFree(kernelImage);
    918921        psFree(convolvedStamp);
    919922        psFree(stats);
    920923    }
    921924
    922     float limit = sigmaRej * sqrt(totalSquareDev / (numStamps - 1)); // Limit on maximum deviation
     925    float limit = sigmaRej * sqrt(totalSquareDev / numStamps); // Limit on maximum deviation
     926    psTrace("psModules.imcombine", 1, "Deviation limit: %f\n", limit);
    923927
    924928    int numRejected = 0;
Note: See TracChangeset for help on using the changeset viewer.