IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 24298


Ignore:
Timestamp:
Jun 2, 2009, 10:10:32 AM (17 years ago)
Author:
Paul Price
Message:

Fixing application of ISIS and POIS kernels to stamps: was effectively
doing [y+v][x+u] instead of [y-v][x-u], so the ISIS kernel was around
the wrong way (relative to when it gets applied to the image; not
entirely sure why POIS wasn't affected). I think this is the big
nasty bug that Armin and Mark have been looking for!

Also removed the convolveSubsetAlloc/convolveSubsetFree functions
which are no longer necessary following Gene's addition of threading
care into psImageSubset.

File:
1 edited

Legend:

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

    r23989 r24298  
    196196{
    197197    psKernel *convolved = psKernelAlloc(-footprint, footprint, -footprint, footprint); // Convolved image
    198     int numBytes = (2 * footprint + 1) * PSELEMTYPE_SIZEOF(PS_TYPE_F32); // Number of bytes to copy
    199198    for (int y = -footprint; y <= footprint; y++) {
    200         // Convolution with a delta function is just the value specified by the offset
    201         memcpy(&convolved->kernel[y][-footprint], &image->kernel[y - v][-footprint - u], numBytes);
     199        for (int x = -footprint; x <= footprint; x++) {
     200            convolved->kernel[y][x] = image->kernel[y - v][x - u];
     201        }
    202202    }
    203203    return convolved;
    204204}
    205205
    206 // Take a subset of an image
    207 static inline psImage *convolveSubsetAlloc(psImage *image, // Image to be convolved
    208                                            psRegion region, // Region of interest (with border)
    209                                            bool threaded // Are we running threaded?
    210                                            )
    211 {
    212     if (!image) {
    213         return NULL;
    214     }
    215     // XXX if (threaded) {
    216     // XXX     psMutexLock(image);
    217     // XXX }
    218     psImage *subset = psImageSubset(image, region); // Subset image, to return
    219     // XXX if (threaded) {
    220     // XXX     psMutexUnlock(image);
    221     // XXX }
    222     return subset;
    223 }
    224 
    225 // Free the subset of an image
    226 static inline void convolveSubsetFree(psImage *parent, // Parent image
    227                                       psImage *child, // Child (subset) image
    228                                       bool threaded // Are we running threaded?
    229                                       )
    230 {
    231     if (!child || !parent) {
    232         return;
    233     }
    234     // XXX if (threaded) {
    235     // XXX     psMutexLock(parent);
    236     // XXX }
    237     psFree(child);
    238     // XXX if (threaded) {
    239     // XXX     psMutexUnlock(parent);
    240     // XXX }
    241     return;
    242 }
    243206
    244207// Convolve an image using FFT
     
    256219                                  region.y0 - size, region.y1 + size); // Add a border
    257220
    258     bool threaded = pmSubtractionThreaded(); // Are we running threaded?
    259 
    260     psImage *subImage = convolveSubsetAlloc(image, border, threaded); // Subimage to convolve
    261     psImage *subMask = convolveSubsetAlloc(mask, border, threaded); // Subimage mask
     221    psImage *subImage = image ? psImageSubset(image, border) : NULL; // Subimage to convolve
     222    psImage *subMask = mask ? psImageSubset(mask, border) : NULL; // Subimage mask
    262223
    263224    psImage *convolved = psImageConvolveFFT(NULL, subImage, subMask, maskVal, kernel); // Convolution
    264225
    265     convolveSubsetFree(image, subImage, threaded);
    266     convolveSubsetFree(mask, subMask, threaded);
     226    psFree(subImage);
     227    psFree(subMask);
    267228
    268229    // Now, we have to stick it in where it belongs
     
    300261                                  region.y0 - size, region.y1 + size); // Add a border
    301262
    302     bool threaded = pmSubtractionThreaded(); // Are we running threaded?
    303 
    304     psImage *subVariance = convolveSubsetAlloc(variance, border, threaded); // Variance map
    305     psImage *subSys = convolveSubsetAlloc(sys, border, threaded); // Systematic error image
    306     psImage *subMask = convolveSubsetAlloc(mask, border, threaded); // Mask
     263    psImage *subVariance = variance ? psImageSubset(variance, border) : NULL; // Variance map
     264    psImage *subSys = sys ? psImageSubset(sys, border) : NULL; // Systematic error image
     265    psImage *subMask = mask ? psImageSubset(mask, border) : NULL; // Mask
    307266
    308267    // XXX Can trim this a little by combining the convolution: only have to take the FFT of the kernel once
     
    310269    psImage *convSys = subSys ? psImageConvolveFFT(NULL, subSys, subMask, maskVal, kernel) : NULL; // Conv sys
    311270
    312     convolveSubsetFree(variance, subVariance, threaded);
    313     convolveSubsetFree(sys, subSys, threaded);
    314     convolveSubsetFree(mask, subMask, threaded);
     271    psFree(subVariance);
     272    psFree(subSys);
     273    psFree(subMask);
    315274
    316275    // Now, we have to stick it in where it belongs
     
    420379        if (box > 0) {
    421380            int colMin = region.x0, colMax = region.x1, rowMin = region.y0, rowMax = region.y1; // Bounds
    422             bool threaded = pmSubtractionThreaded(); // Are we running threaded?
    423 
    424381            psRegion region = psRegionSet(colMin - box, colMax + box,
    425382                                          rowMin - box, rowMax + box); // Region to convolve
    426383
    427             psImage *image = convolveSubsetAlloc(subMask, region, threaded); // Mask to convolve
     384            psImage *image = subMask ? psImageSubset(subMask, region) : NULL; // Mask to convolve
    428385
    429386            psImage *convolved = psImageConvolveMask(NULL, image, subBad, subConvBad,
    430387                                                     -box, box, -box, box); // Convolved subtraction mask
    431388
    432             convolveSubsetFree(subMask, image, threaded);
     389            psFree(image);
    433390
    434391            psAssert(convolved->numCols - 2 * box == colMax - colMin, "Bad number of columns");
     
    653610                  float value = 0.0;    // Value of convolved pixel
    654611                  int uMin = x - size, uMax = x + size; // Range for u
    655                   psF32 *xKernelData = xKernel->data.F32; // Kernel values
     612                  psF32 *xKernelData = &xKernel->data.F32[xKernel->n - 1]; // Kernel values
    656613                  psF32 *imageData = &image->kernel[y][uMin]; // Image values
    657                   for (int u = uMin; u <= uMax; u++, xKernelData++, imageData++) {
     614                  for (int u = uMin; u <= uMax; u++, xKernelData--, imageData++) {
    658615                      value += *xKernelData * *imageData;
    659616                  }
     
    668625                  float value = 0.0;    // Value of convolved pixel
    669626                  int vMin = y - size, vMax = y + size; // Range for v
    670                   psF32 *yKernelData = yKernel->data.F32; // Kernel values
     627                  psF32 *yKernelData = &yKernel->data.F32[yKernel->n - 1]; // Kernel values
    671628                  psF32 *imageData = &temp->kernel[x][vMin]; // Image values; NOTE: wrong way!
    672                   for (int v = vMin; v <= vMax; v++, yKernelData++, imageData++) {
     629                  for (int v = vMin; v <= vMax; v++, yKernelData--, imageData++) {
    673630                      value += *yKernelData * *imageData;
    674631                  }
Note: See TracChangeset for help on using the changeset viewer.