IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 4, 2007, 1:56:07 PM (19 years ago)
Author:
Paul Price
Message:

Consolidating some code. Making it so that the convolutions of the reference don't have to be performed twice if the optimum kernel is computed (before, the convolutions were calculated twice --- once in getting the optimum kernel set, and once in calculating the least-squares matrix).

File:
1 edited

Legend:

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

    r14735 r14738  
    221221    }
    222222
    223     // Generate the convolutions
    224     for (int i = 0; i < numStamps; i++) {
    225         pmSubtractionStamp *stamp = stamps->data[i]; // Stamp of interest
    226         if (stamp->status == PM_SUBTRACTION_STAMP_REJECTED || stamp->status == PM_SUBTRACTION_STAMP_NONE) {
    227             continue;
    228         }
    229         if (!stamp->convolutions) {
    230             stamp->convolutions = psArrayAlloc(numKernels);
    231         }
    232 
    233         for (int j = 0; j < numKernels; j++) {
    234             psKernel *kernel = kernels->preCalc->data[j]; // Precalculated kernel
    235             stamp->convolutions->data[j] = p_pmSubtractionConvolveStampPrecalc(stamp->reference, kernel);
    236         }
    237     }
    238 
    239     // Calculate sums invariant with the input image
     223    // Generate the convolutions, accumulate sums, and measure initial chi^2
    240224    double sum1 = 0.0;                  // sum of 1/sigma(x,y)^2
    241     for (int i = 0; i < numStamps; i++) {
    242         pmSubtractionStamp *stamp = stamps->data[i]; // Stamp of interest
    243         if (stamp->status == PM_SUBTRACTION_STAMP_REJECTED || stamp->status == PM_SUBTRACTION_STAMP_NONE) {
    244             continue;
    245         }
    246         psKernel *weight = stamp->weight; // Weight map for stamp
    247 
    248         for (int v = -footprint; v <= footprint; v++) {
    249             psF32 *wt = &weight->kernel[v][-footprint]; // Dereference weight map
    250             for (int u = -footprint; u <= footprint; u++, wt++) {
    251                 sum1 += 1.0 / *wt;
    252             }
    253         }
    254         if (!isfinite(sum1)) {
    255             psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    256                     "Sum of 1/sigma^2 is non-finite for stamp %d (%d,%d)\n",
    257                     i, (int)stamp->x, (int)stamp->y);
    258             psFree(kernels);
    259             return NULL;
    260         }
    261     }
    262225    psVector *sumC = psVectorAlloc(numKernels, PS_TYPE_F64); // sum of R(x)*k(u)/sigma(x)^2
    263226    psVector *sumCC = psVectorAlloc(numKernels, PS_TYPE_F64); // sum of [R(x)*k(u)]^2/sigma(x)^2
    264227    psVectorInit(sumC, 0.0);
    265228    psVectorInit(sumCC, 0.0);
    266     for (int i = 0; i < numKernels; i++) {
    267         for (int j = 0; j < numStamps; j++) {
    268             pmSubtractionStamp *stamp = stamps->data[j]; // Stamp of interest
    269             if (stamp->status == PM_SUBTRACTION_STAMP_REJECTED ||
    270                 stamp->status == PM_SUBTRACTION_STAMP_NONE) {
    271                 continue;
    272             }
    273             accumulateConvolutions(&sumC->data.F64[i], &sumCC->data.F64[i], stamp, i, footprint);
    274         }
    275     }
    276 
    277     // Initial chi^2
    278229    double lastChi2 = 0.0;              // Chi^2 from last iteration
    279230    int numPixels = 0;                  // Number of pixels contributing to chi^2
     
    283234            continue;
    284235        }
     236        if (!pmSubtractionConvolveStamp(stamp, kernels, footprint)) {
     237            psError(PS_ERR_UNKNOWN, false, "Unable to convolve stamp %d.", i);
     238            psFree(inputs);
     239            psFree(kernels);
     240            return NULL;
     241        }
     242
     243        // This sum is invariant to the kernel
     244        psKernel *weight = stamp->weight; // Weight map for stamp
     245        for (int v = -footprint; v <= footprint; v++) {
     246            psF32 *wt = &weight->kernel[v][-footprint]; // Dereference weight map
     247            for (int u = -footprint; u <= footprint; u++, wt++) {
     248                sum1 += 1.0 / *wt;
     249            }
     250        }
     251        if (!isfinite(sum1)) {
     252            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     253                    "Sum of 1/sigma^2 is non-finite for stamp %d (%d,%d)\n",
     254                    i, (int)stamp->x, (int)stamp->y);
     255            psFree(inputs);
     256            psFree(kernels);
     257            return NULL;
     258        }
     259
     260        for (int j = 0; j < numKernels; j++) {
     261            accumulateConvolutions(&sumC->data.F64[j], &sumCC->data.F64[j], stamp, j, footprint);
     262        }
     263
    285264        lastChi2 += initialChi2(inputs->data[i], stamp, footprint);
    286265        numPixels += PS_SQR(2 * footprint + 1);
     
    395374    psVector *widthsNew = psVectorAlloc(newSize, PS_TYPE_F32);
    396375    psArray *preCalcNew = psArrayAlloc(newSize);
     376    psArray *convNew = psArrayAlloc(numStamps);
     377    for (int i = 0; i < numStamps; i++) {
     378        convNew->data[i] = psArrayAlloc(newSize);
     379    }
    397380
    398381    for (int i = 0; i < numKernels; i++) {
     
    403386            widthsNew->data.F32[rank] = kernels->widths->data.F32[i];
    404387            preCalcNew->data[rank] = psMemIncrRefCounter(kernels->preCalc->data[i]);
     388
     389            for (int j = 0; j < numStamps; j++) {
     390                psArray *convolutions = convNew->data[j]; // Convolutions for this stamp
     391                pmSubtractionStamp *stamp = stamps->data[j]; // Stamp of interest
     392                convolutions->data[rank] = psMemIncrRefCounter(stamp->convolutions->data[i]);
     393            }
    405394        }
    406395    }
     
    415404    kernels->num = newSize;
    416405
     406    for (int i = 0; i < numStamps; i++) {
     407        pmSubtractionStamp *stamp = stamps->data[i]; // Stamp of interest
     408        psFree(stamp->convolutions);
     409        stamp->convolutions = convNew->data[i];
     410    }
     411
    417412    psFree(ranking);
    418413
Note: See TracChangeset for help on using the changeset viewer.