IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 28, 2009, 2:33:51 PM (17 years ago)
Author:
Paul Price
Message:

Changing pmReadout.weight to variance. Adding pmReadout.covariance which will carry around a covariance pseudo-matrix, allowing us to calculate the pixel-to-pixel variance. pmReadout.covariance now exists and is set, but no mechanism yet to read/write, or use it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/pap_branch_20090128/psModules/src/imcombine/pmSubtraction.c

    r21183 r21211  
    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);
     
    989989
    990990
    991 // XXX Put kernelImage, kernelWeight and polyValues on thread-dependent data
     991// XXX Put kernelImage, kernelVariance and polyValues on thread-dependent data
    992992static bool subtractionConvolvePatch(int numCols, int numRows, // Size of image
    993993                                     int x0, int y0, // Offsets for image
     
    10101010
    10111011    psKernel *kernelImage = NULL;       // Kernel for the images
    1012     psKernel *kernelWeight = NULL;      // Kernel for the weight maps
     1012    psKernel *kernelVariance = NULL;      // Kernel for the variance maps
    10131013
    10141014    // Only generate polynomial values every kernel footprint, since we have already assumed
     
    10201020
    10211021    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,
     1022        convolveRegion(out1->image, out1->variance, convMask, &kernelImage, &kernelVariance,
     1023                       ro1->image, ro1->variance, sys1, subMask, kernels, polyValues, background, *region,
    10241024                       maskBad, maskPoor, poorFrac, useFFT, false);
    10251025    }
    10261026    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,
     1027        convolveRegion(out2->image, out2->variance, convMask, &kernelImage, &kernelVariance,
     1028                       ro2->image, ro2->variance, sys2, subMask, kernels, polyValues, background, *region,
    10291029                       maskBad, maskPoor, poorFrac, useFFT, kernels->mode == PM_SUBTRACTION_MODE_DUAL);
    10301030    }
    10311031
    10321032    psFree(kernelImage);
    1033     psFree(kernelWeight);
     1033    psFree(kernelVariance);
    10341034    psFree(polyValues);
    10351035
     
    11481148            }
    11491149        }
    1150         if (ro1->weight) {
    1151             if (!out1->weight) {
    1152                 out1->weight = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     1150        if (ro1->variance) {
     1151            if (!out1->variance) {
     1152                out1->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32);
    11531153                if (threaded) {
    1154                     psMutexInit(out1->weight);
     1154                    psMutexInit(out1->variance);
    11551155                }
    11561156            }
    1157             psImageInit(out1->weight, 0.0);
     1157            psImageInit(out1->variance, 0.0);
    11581158        }
    11591159    }
     
    11651165            }
    11661166        }
    1167         if (ro2->weight) {
    1168             if (!out2->weight) {
    1169                 out2->weight = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     1167        if (ro2->variance) {
     1168            if (!out2->variance) {
     1169                out2->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32);
    11701170                if (threaded) {
    1171                     psMutexInit(out2->weight);
     1171                    psMutexInit(out2->variance);
    11721172                }
    11731173            }
    1174             psImageInit(out2->weight, 0.0);
     1174            psImageInit(out2->variance, 0.0);
    11751175        }
    11761176    }
     
    12321232    psImage *polyValues = NULL;         // Pre-calculated polynomial values
    12331233    psKernel *kernelImage = NULL;       // Kernel for the images
    1234     psKernel *kernelWeight = NULL;      // Kernel for the weight maps
     1234    psKernel *kernelVariance = NULL;      // Kernel for the variance maps
    12351235#endif
    12361236
     
    13451345        if (out2) {
    13461346            out2->image = psMemIncrRefCounter(ro2->image);
    1347             out2->weight = psMemIncrRefCounter(ro2->weight);
     1347            out2->variance = psMemIncrRefCounter(ro2->variance);
    13481348            out2->mask = psMemIncrRefCounter(ro2->mask);
    13491349        }
     
    13521352        if (out1) {
    13531353            out1->image = psMemIncrRefCounter(ro1->image);
    1354             out1->weight = psMemIncrRefCounter(ro1->weight);
     1354            out1->variance = psMemIncrRefCounter(ro1->variance);
    13551355            out1->mask = psMemIncrRefCounter(ro1->mask);
    13561356        }
Note: See TracChangeset for help on using the changeset viewer.