IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18043


Ignore:
Timestamp:
Jun 9, 2008, 4:43:01 PM (18 years ago)
Author:
Paul Price
Message:

Gene has determined that what I had before --- normalising by the sum
of kernel squares for the variance --- is the correct thing to do, so
I'm restoring what I had before. Here's Gene's explanation:

since the errors in the output image are correlated by the smoothing
kernel, the output variance image actually should not change
normalization under the smoothing. thus, you should in fact the
normalizing to have the sum(psf2) = 1.0.
Note that in the output smoothed image, the per-pixel variance [sum of
(v[i][j] - <v>)
2] will decrease as you smooth, but the variance of
apertures comparable to your smoothing scale will not be decreased.
thus, the output weight image you generate is appropriate for
measuring extended parameters, but not per-pixel stats. If you are
making the assumption that the per-pixel variance should be consistent
with the mean of the variance images, you will have an error.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/imageops/psImageInterpolate.c

    r16351 r18043  
    77 *  @author Paul Price, IfA
    88 *
    9  *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2008-02-07 04:03:22 $
     9 *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2008-06-10 02:42:41 $
    1111 *
    1212 *  Copyright 2004-2007 Institute for Astronomy, University of Hawaii
     
    312312        #define KERNEL_VARIANCE_CASE(TYPE) \
    313313            case PS_TYPE_##TYPE: { \
     314                double sumKernel2 = 0.0; /* Sum of kernel squares */ \
    314315                for (int j = 0, yPix = yCentral - (yNum - 1) / 2; j < yNum; j++, yPix++) { \
    315316                    for (int i = 0, xPix = xCentral - (xNum - 1) / 2; i < xNum; i++, xPix++) { \
    316                         *varianceValue += PS_SQR(kernel[j][i]) * variance->data.TYPE[yPix][xPix]; \
     317                        double kernel2 = PS_SQR(kernel[j][i]); /* Kernel squared */ \
     318                        sumKernel2 += kernel2; \
     319                        *varianceValue += kernel2 * variance->data.TYPE[yPix][xPix]; \
    317320                    } \
    318321                } \
     322                *varianceValue /= sumKernel2; /* Normalise so that sum of kernel squares is unity */ \
    319323                break; \
    320324            }
     
    542546        #define SEPARATE_VARIANCE_CASE(TYPE) \
    543547          case PS_TYPE_##TYPE: { \
     548            double ySumKernel2 = 0.0; /* Sum of kernel squared in y */ \
    544549            for (int j = 0, yPix = yCentral - (yNum - 1) / 2; j < yNum; j++, yPix++) { \
     550                double xSumKernel2 = 0.0; /* Sum of kernel squared in x */ \
    545551                double xInterpValue = 0.0; /* Interpolation in x */ \
    546552                for (int i = 0, xPix = xCentral - (xNum - 1) / 2; i < xNum; i++, xPix++) { \
    547                     xInterpValue += PS_SQR(xKernel[i]) * variance->data.TYPE[yPix][xPix]; \
     553                    double kernel2 = PS_SQR(xKernel[i]); /* Kernel squared */ \
     554                    xSumKernel2 += kernel2; \
     555                    xInterpValue += kernel2 * variance->data.TYPE[yPix][xPix]; \
    548556                } \
    549                 *varianceValue += xInterpValue * PS_SQR(yKernel[j]); /* Interpolating in y */ \
     557                double kernel2 = PS_SQR(yKernel[j]); /* Kernel squared */ \
     558                ySumKernel2 += xSumKernel2 * kernel2; \
     559                *varianceValue += xInterpValue * kernel2; /* Interpolating in y */ \
    550560            } \
    551561            break; \
     
    576586
    577587psImageInterpolateStatus psImageInterpolate(double *imageValue, double *varianceValue, psMaskType *maskValue,
    578                         float x, float y, const psImageInterpolateOptions *options)
     588                                            float x, float y, const psImageInterpolateOptions *options)
    579589{
    580590    PS_ASSERT_PTR_NON_NULL(options, PS_INTERPOLATE_STATUS_ERROR);
     
    588598        PS_ASSERT_IMAGE_NON_NULL(variance, PS_INTERPOLATE_STATUS_ERROR);
    589599        PS_ASSERT_IMAGE_TYPE(variance, image->type.type, PS_INTERPOLATE_STATUS_ERROR);
    590         PS_ASSERT_IMAGES_SIZE_EQUAL(variance, image, PS_INTERPOLATE_STATUS_ERROR);
     600        psAssert(image->numCols == variance->numCols && image->numRows == variance->numRows,
     601                 "Image and variance sizes");
    591602    }
    592603    if (maskValue && mask) {
    593604        PS_ASSERT_IMAGE_NON_NULL(mask, PS_INTERPOLATE_STATUS_ERROR);
    594605        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, PS_INTERPOLATE_STATUS_ERROR);
    595         if ((image->numCols != mask->numCols) || (image->numRows != mask->numRows)) {
    596           psAbort ("programming error");
    597         }
    598         PS_ASSERT_IMAGES_SIZE_EQUAL(mask, image, PS_INTERPOLATE_STATUS_ERROR);
    599         // XXX these should probably be asserts, not PS_ASSERTS
     606        psAssert(image->numCols == mask->numCols && image->numRows == mask->numRows, "Image and mask sizes");
    600607    }
    601608
  • trunk/psModules/src/imcombine/pmSubtraction.c

    r17811 r18043  
    44 *  @author GLG, MHPCC
    55 *
    6  *  @version $Revision: 1.92 $ $Name: not supported by cvs2svn $
    7  *  @date $Date: 2008-05-24 23:24:15 $
     6 *  @version $Revision: 1.93 $ $Name: not supported by cvs2svn $
     7 *  @date $Date: 2008-06-10 02:43:01 $
    88 *
    99 *  Copyright 2004-2007 Institute for Astronomy, University of Hawaii
     
    5050
    5151    // Take the square of the normal kernel
     52    double sumNormal = 0.0, sumVariance = 0.0; // Sum of the normal and variance kernels
    5253    for (int v = yMin; v <= yMax; v++) {
    5354        for (int u = xMin; u <= xMax; u++) {
    54             out->kernel[v][u] = PS_SQR(normalKernel->kernel[v][u]);
    55         }
    56     }
     55            float value = normalKernel->kernel[v][u]; // Value of interest
     56            float value2 = PS_SQR(value); // Value squared
     57            sumNormal += value;
     58            sumVariance += value2;
     59            out->kernel[v][u] = value2;
     60        }
     61    }
     62
     63    // Normalise so that the sum of the variance kernel is the square of the sum of the normal kernel
     64    // This is required to keep the relative scaling between the image and the weight map
     65    psBinaryOp(out->image, out->image, "*", psScalarAlloc(PS_SQR(sumNormal) / sumVariance, PS_TYPE_F32));
    5766
    5867    return out;
Note: See TracChangeset for help on using the changeset viewer.