IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18239


Ignore:
Timestamp:
Jun 20, 2008, 10:00:01 AM (18 years ago)
Author:
Paul Price
Message:

Adding penalties for large kernel components.

Location:
branches/pap_branch_080617/psModules/src/imcombine
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/pap_branch_080617/psModules/src/imcombine/pmSubtractionEquation.c

    r17825 r18239  
    382382}
    383383
     384
     385// Add in penalty term to least-squares vector
     386static bool calculatePenalty(int numPixels, // Number of pixels; for normalisation
     387                             psVector *vector, // Vector to which to add in penalty term
     388                             const pmSubtractionKernels *kernels // Kernel parameters
     389    )
     390{
     391    if (kernels->penalty == 0.0) {
     392        return true;
     393    }
     394
     395    float penalty = numPixels * kernels->penalty; // Penalty value
     396    psVector *penalties = kernels->penalties; // Penalties for each kernel component
     397    int spatialOrder = kernels->spatialOrder; // Order of spatial variations
     398    int numKernels = kernels->num; // Number of kernel components
     399    for (int i = 0; i < numKernels; i++) {
     400        for (int yOrder = 0, index = i; yOrder <= spatialOrder; yOrder++) {
     401            for (int xOrder = 0; xOrder <= spatialOrder - yOrder; xOrder++, index += numKernels) {
     402                vector->data.F64[index] -= penalty * penalties->data.F32[i];
     403            }
     404        }
     405    }
     406
     407    return true;
     408}
     409
    384410//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    385411// Semi-public functions
    386 // XXX EAM these cannot be inline :: talk to Josh
     412// XXX We might like to define these functions as "extern inline" but gcc currently doesn't handle this in c99
     413// mode.  See http://gcc.gnu.org/ml/gcc/2006-11/msg00006.html
    387414//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    388415
     
    675702        psVectorInit(sumVector, 0.0);
    676703        psImageInit(sumMatrix, 0.0);
     704        int numStamps = 0;              // Number of good stamps
    677705        for (int i = 0; i < stamps->num; i++) {
    678706            pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest
     
    680708                (void)psBinaryOp(sumMatrix, sumMatrix, "+", stamp->matrix1);
    681709                (void)psBinaryOp(sumVector, sumVector, "+", stamp->vector1);
    682             }
    683         }
     710                numStamps++;
     711            }
     712        }
     713        calculatePenalty(numStamps * PS_SQR(2 * stamps->footprint + 1), sumVector, kernels);
    684714
    685715        psVector *permutation = NULL;       // Permutation vector, required for LU decomposition
     
    716746        psVectorInit(sumVector2, 0.0);
    717747
     748        int numStamps = 0;              // Number of good stamps
    718749        for (int i = 0; i < stamps->num; i++) {
    719750            pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest
     
    724755                (void)psBinaryOp(sumVector1, sumVector1, "+", stamp->vector1);
    725756                (void)psBinaryOp(sumVector2, sumVector2, "+", stamp->vector2);
    726             }
    727         }
     757                numStamps++;
     758            }
     759        }
     760        calculatePenalty(numStamps * PS_SQR(2 * stamps->footprint + 1), sumVector1, kernels);
     761        calculatePenalty(numStamps * PS_SQR(2 * stamps->footprint + 1), sumVector2, kernels);
    728762
    729763#if 0
  • branches/pap_branch_080617/psModules/src/imcombine/pmSubtractionKernels.c

    r18146 r18239  
    2424    psFree(kernels->vStop);
    2525    psFree(kernels->preCalc);
     26    psFree(kernels->penalties);
    2627    psFree(kernels->solution1);
    2728    psFree(kernels->solution2);
     
    6061    kernels->v = psVectorRealloc(kernels->v, start + numNew);
    6162    kernels->preCalc = psArrayRealloc(kernels->preCalc, start + numNew);
     63    kernels->penalties = psVectorRealloc(kernels->penalties, start + numNew);
    6264    kernels->inner = start;
    6365
     
    7476            kernels->v->data.S32[index] = v;
    7577            kernels->preCalc->data[index] = NULL;
     78            kernels->penalties->data.F32[index] = PS_SQR(u) + PS_SQR(v);
    7679
    7780            psTrace("psModules.imcombine", 7, "Kernel %d: %d %d\n", index, u, v);
     
    122125                psKernel *preCalc = psKernelAlloc(-size, size, -size, size);
    123126                double sum = 0.0;       // Normalisation
     127                double moment = 0.0;    // Moment, for penalty
    124128                for (int v = -size; v <= size; v++) {
    125129                    for (int u = -size; u <= size; u++) {
    126130                        sum += preCalc->kernel[v][u] = norm * power(u, uOrder) * power(v, vOrder) *
    127131                            expf(-0.5 * (PS_SQR(u) + PS_SQR(v)) / PS_SQR(sigma));
     132                        moment += preCalc->kernel[v][u] * sqrtf(PS_SQR(u) + PS_SQR(v));
    128133                    }
    129134                }
     
    146151                }
    147152                kernels->preCalc->data[index] = preCalc;
     153                kernels->penalties->data.F32[index] = moment;
    148154
    149155                psTrace("psModules.imcombine", 7, "Kernel %d: %f %d %d\n", index,
     
    173179    kernels->widths = psVectorAlloc(numBasisFunctions, PS_TYPE_F32);
    174180    kernels->preCalc = psArrayAlloc(numBasisFunctions);
     181    kernels->penalty = 0.0;
     182    kernels->penalties = psVectorAlloc(numBasisFunctions, PS_TYPE_F32);
    175183    kernels->uStop = NULL;
    176184    kernels->vStop = NULL;
     
    324332    psFree(widths);
    325333
     334    psWarning("Kernel penalty for dual-convolution is not configured for SPAM kernels.");
     335    psVectorInit(kernels->penalties, 0.0);
     336
    326337    return kernels;
    327338}
     
    413424    psFree(start);
    414425    psFree(stop);
     426
     427    psWarning("Kernel penalty for dual-convolution is not configured for FRIES kernels.");
     428    psVectorInit(kernels->penalties, 0.0);
    415429
    416430    return kernels;
     
    520534                psVector *vCoords = data->data[1] = psVectorAllocEmpty(RINGS_BUFFER, PS_TYPE_S32); // v coords
    521535                psVector *poly = data->data[2] = psVectorAllocEmpty(RINGS_BUFFER, PS_TYPE_F32); // Polynomial
     536                double moment = 0.0;    // Moment, for penalty
    522537
    523538                if (i == 0) {
     
    527542                    uCoords->n = vCoords->n = poly->n = 1;
    528543                    radiusLast = 0;
     544                    moment = 0.0;
    529545                } else {
    530546                    int j = 0;          // Index for data
     
    546562                                    poly->data.F32[j] = polyVal;
    547563                                    norm += polyVal;
     564                                    moment += polyVal * sqrtf(PS_SQR(u) + PS_SQR(v));
    548565
    549566                                    psVectorExtend(uCoords, RINGS_BUFFER, 1);
     
    571588                        psBinaryOp(poly, poly, "*", psScalarAlloc(1.0 / norm, PS_TYPE_F32));
    572589                    }
     590                    moment /= norm;
    573591                }
    574592
     
    578596                kernels->u->data.S32[index] = uOrder;
    579597                kernels->v->data.S32[index] = vOrder;
     598                kernels->penalties->data.F32[index] = moment;
    580599
    581600                psTrace("psModules.imcombine", 7, "Kernel %d: %d %d %d\n", index,
  • branches/pap_branch_080617/psModules/src/imcombine/pmSubtractionKernels.h

    r18146 r18239  
    3333    psVector *uStop, *vStop;            ///< Width of kernel element (SPAM,FRIES only)
    3434    psArray *preCalc;                   ///< Array of images containing pre-calculated kernel (for ISIS)
     35    float penalty;                      ///< Penalty value
     36    psVector *penalties;                ///< Penalty for each kernel component
    3537    int size;                           ///< The half-size of the kernel
    3638    int inner;                          ///< The size of an inner region
  • branches/pap_branch_080617/psModules/src/imcombine/pmSubtractionMatch.c

    r17783 r18239  
    430430                // Generate image with convolution kernels
    431431                int fullSize = 2 * size + 1 + 1;    // Full size of kernel
    432                 psImage *convKernels = psImageAlloc(5 * fullSize - 1, 5 * fullSize - 1, PS_TYPE_F32);
     432                int imageSize = (2 * KERNEL_MOSAIC + 1) * fullSize;
     433                psImage *convKernels = psImageAlloc((mode == PM_SUBTRACTION_MODE_DUAL ? 2 : 1) *
     434                                                    imageSize - 1 +
     435                                                    (mode == PM_SUBTRACTION_MODE_DUAL ? 4 : 0),
     436                                                    imageSize - 1, PS_TYPE_F32);
    433437                psImageInit(convKernels, NAN);
    434438                for (int j = -KERNEL_MOSAIC; j <= KERNEL_MOSAIC; j++) {
     
    451455                        }
    452456                        psFree(kernel);
     457
     458                        if (mode == PM_SUBTRACTION_MODE_DUAL) {
     459                            kernel = pmSubtractionKernelImage(kernels, (float)i / (float)KERNEL_MOSAIC,
     460                                                              (float)j / (float)KERNEL_MOSAIC,
     461                                                              true); // Image of the kernel
     462                            if (!kernel) {
     463                                psError(PS_ERR_UNKNOWN, false, "Unable to generate kernel image.");
     464                                psFree(convKernels);
     465                                goto MATCH_ERROR;
     466                            }
     467
     468                            if (psImageOverlaySection(convKernels, kernel,
     469                                                      (2 * KERNEL_MOSAIC + 1 + i + KERNEL_MOSAIC) * fullSize +
     470                                                      4,
     471                                                      (j + KERNEL_MOSAIC) * fullSize, "=") == 0) {
     472                                psError(PS_ERR_UNKNOWN, false, "Unable to overlay kernel image.");
     473                                psFree(kernel);
     474                                psFree(convKernels);
     475                                goto MATCH_ERROR;
     476                            }
     477                            psFree(kernel);
     478                        }
     479
    453480                    }
    454481                }
Note: See TracChangeset for help on using the changeset viewer.