IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16351


Ignore:
Timestamp:
Feb 6, 2008, 6:03:22 PM (18 years ago)
Author:
Paul Price
Message:

I no longer believe that I should be normalising the variance kernel.
This isn't done by Andy Becker in hotpants, and I can't see it in the
math:

If I(x,y) is the image, V(x,y) is the variance map and k(u,v) is the
kernel, then the convolved image is: sum_u,v I(x-u,y-v).k(u,v). Then
the variance of the convolved image is: sum_u,v V(x-u,y-v).k(u,v)2.
If you want to normalise by the sum of the kernel, then the convolved
image is: sum_u,v I(x-u,y-v).k(u,v)/sum_u,v k(u,v) and the variance
is: sum_u,v V(x-u,y-v).k(u,v)
2/(sum_u,v k(u,v))2. But, of course in
practise you absorb the normalisation into the kernel itself, so you
get the first form. This has no division by the sum of the square.

See also psModules/src/imcombine/pmSubtraction.c

File:
1 edited

Legend:

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

    r15640 r16351  
    77 *  @author Paul Price, IfA
    88 *
    9  *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2007-11-17 00:39:29 $
     9 *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2008-02-07 04:03:22 $
    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 */ \
    315314                for (int j = 0, yPix = yCentral - (yNum - 1) / 2; j < yNum; j++, yPix++) { \
    316315                    for (int i = 0, xPix = xCentral - (xNum - 1) / 2; i < xNum; i++, xPix++) { \
    317                         double kernel2 = PS_SQR(kernel[j][i]); /* Kernel squared */ \
    318                         sumKernel2 += kernel2; \
    319                         *varianceValue += kernel2 * variance->data.TYPE[yPix][xPix]; \
     316                        *varianceValue += PS_SQR(kernel[j][i]) * variance->data.TYPE[yPix][xPix]; \
    320317                    } \
    321318                } \
    322                 *varianceValue /= sumKernel2; /* Normalise so that sum of kernel squares is unity */ \
    323319                break; \
    324320            }
     
    546542        #define SEPARATE_VARIANCE_CASE(TYPE) \
    547543          case PS_TYPE_##TYPE: { \
    548             double ySumKernel2 = 0.0; /* Sum of kernel squared in y */ \
    549544            for (int j = 0, yPix = yCentral - (yNum - 1) / 2; j < yNum; j++, yPix++) { \
    550545                double xInterpValue = 0.0; /* Interpolation in x */ \
    551                 double xSumKernel2 = 0.0; /* Sum of kernel squared in x */ \
    552546                for (int i = 0, xPix = xCentral - (xNum - 1) / 2; i < xNum; i++, xPix++) { \
    553                     double kernel2 = PS_SQR(xKernel[i]); /* Kernel squared */ \
    554                     xSumKernel2 += kernel2; \
    555                     xInterpValue += kernel2 * variance->data.TYPE[yPix][xPix]; \
     547                    xInterpValue += PS_SQR(xKernel[i]) * variance->data.TYPE[yPix][xPix]; \
    556548                } \
    557                 double kernel2 = PS_SQR(yKernel[j]); /* Kernel squared */ \
    558                 ySumKernel2 += xSumKernel2 * kernel2; \
    559                 *varianceValue += xInterpValue * kernel2; /* Interpolating in y */ \
     549                *varianceValue += xInterpValue * PS_SQR(yKernel[j]); /* Interpolating in y */ \
    560550            } \
    561             *varianceValue /= ySumKernel2; /* Normalise so that sum of kernel squares is unity */ \
    562551            break; \
    563552          }
     
    604593        PS_ASSERT_IMAGE_NON_NULL(mask, PS_INTERPOLATE_STATUS_ERROR);
    605594        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, PS_INTERPOLATE_STATUS_ERROR);
    606         if ((image->numCols != mask->numCols) || (image->numRows != mask->numRows)) {
    607           psAbort ("programming error");
    608         }
     595        if ((image->numCols != mask->numCols) || (image->numRows != mask->numRows)) {
     596          psAbort ("programming error");
     597        }
    609598        PS_ASSERT_IMAGES_SIZE_EQUAL(mask, image, PS_INTERPOLATE_STATUS_ERROR);
    610         // XXX these should probably be asserts, not PS_ASSERTS
     599        // XXX these should probably be asserts, not PS_ASSERTS
    611600    }
    612601
Note: See TracChangeset for help on using the changeset viewer.