IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 25, 2005, 1:59:08 PM (21 years ago)
Author:
gusciora
Message:

I code-reviewed it to ensure we had (x, y) (row, col) issues addressed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/pmImageSubtract.c

    r4035 r4036  
    55 *  @author GLG, MHPCC
    66 *
    7  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2005-05-25 23:08:33 $
     7 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2005-05-25 23:59:08 $
    99 *
    1010 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     11 *
     12 *   XXX: sync with iFa on this:
     13 *   The (x, y) (row, col) issue is becoming a problem.  In this file, and I
     14 *   think, the rest of psLib and psModules, the following conventions are used:
     15 *
     16 * 1) x will correspond to the column, and y will correspond to the row.
     17 * 2) When used in function prototypes, the column (and hence x) appears
     18 *    first.
     19 * 3) When used to index 2-D arrays, obviously, the row (and hence, y)
     20 *    appears first. (2 and 3 are the source of confusion).
     21 * 4) When (u, v) are used in certain structures.
     22 *  u corresponds to x
     23 *  v corresponds to y
     24 * 5) When element (a, b) is casually referred to in comments, or
     25 *    documentation it is unclear where a is the row, or the column.
     26 * 6) A convention on loop index variables (i, j) would be convenient.
     27 *    Currently, sometimes i corresponds to the column (x),
     28 *    usually it corresponds to the row (y).
    1129 *
    1230 */
     
    1836#include "pmImageSubtract.h"
    1937
    20 // XXX: Put this is psConstants.h
    21 #define PS_ASSERT_VECTOR_SIZE(VEC, SIZE, RVAL) \
    22 if (VEC->n != SIZE) { \
    23     psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
    24             "psVector %s has size %d, should be %d." \
    25             #VEC, VEC->n, SIZE); \
    26     return(RVAL); \
    27 }
    28 
    2938/*******************************************************************************
    30 XXX: Store the size and spatialOrder in a private member of the
    3139psSubtractionKernels struct.
    3240 ******************************************************************************/
     
    6775    // for convenience.
    6876    //
     77    // XXX: replace (i, j) with (xOrder, yOrder) for clarity.
     78    //
    6979    psS32 ptr = 0;
    7080    for (psS32 order = 0; order <= spatialOrder; order++) {
     
    8999                // Iterate over spatial order.  This loop creates the terms for
    90100                // x^i * y^j  such that (i+j) <= spatialOrder.
     101                //
     102                // XXX: replace (i, j) with (xOrder, yOrder) for clarity.
    91103                //
    92104                for (psS32 order = 0; order <= spatialOrder; order++) {
     
    132144    psS32 numSigmas = sigmas->n;
    133145    psS32 nBF = 0;
    134     for (psS32 i = 0 ; i < numSigmas ; i++) {
     146    for (psS32 s = 0 ; s < numSigmas ; s++) {
    135147        nBF+= ((orders->n + 1) * (orders->n + 2) / 2);
    136148    }
     
    146158    // XXX: There should be a macro or a psLib vectorDuplicate().
    147159    tmp->sigma = psVectorAlloc(numSigmas, PS_TYPE_F32);
    148     for (psS32 i = 0 ; i < numSigmas ; i++) {
    149         tmp->sigma->data.F32[i] = sigmas->data.F32[i];
     160    for (psS32 s = 0 ; s < numSigmas ; s++) {
     161        tmp->sigma->data.F32[s] = sigmas->data.F32[s];
    150162    }
    151163    tmp->xOrder = psVectorAlloc(nBF, PS_TYPE_F32);
     
    165177    // This loop creates
    166178    //
    167     //
    168     //
     179    // XXX: Put the v loop before the u loop.
     180    // XXX: Put the orderYTerm loop before the orderXTerm loop.
    169181    // XXX: must loop on the sigmas.
     182    //
    170183    psS32 sigPtr = 0;
    171184    // XXX: Review ptr.
     
    175188        for (psS32 orderXTerm = 0; orderXTerm <= order; orderXTerm++) {
    176189            psS32 orderYTerm = order - orderXTerm;
    177             //            psS32 imgPtr = orderYTerm + (orderXTerm * spatialOrder);
     190            // psS32 imgPtr = orderYTerm + (orderXTerm * spatialOrder);
    178191            psImage *currKernel = (psImage *) psImageAlloc(1 + (2 * size), 1 + (2 * size), PS_TYPE_F32);
    179192
     
    194207    }
    195208
    196 
    197209    //
    198210    // sigPtr loops through each sigma value in the *sigmas argument.
     211    // XXX: Put the v loop before the u loop.
     212    // XXX: Put the orderYTerm loop before the orderXTerm loop.
     213    //
    199214    psS32 ptr = 0;
    200215    for (psS32 sigPtr = 0 ; sigPtr < numSigmas ; sigPtr++) {
     
    218233                for (psS32 order = 0; order <= spatialOrder; order++) {
    219234                    for (psS32 orderXTerm = 0; orderXTerm <= order; orderXTerm++) {
     235                        psS32 orderYTerm = order - orderXTerm;
     236
    220237                        // XXX: Should simply add a pointer to an existing image and increase
    221238                        // the memory reference counter for equivalent spatial orders.
     
    227244                        }
    228245
    229                         psS32 orderYTerm = order - orderXTerm;
    230246                        tmp->u->data.F32[ptr] = xOrderP;
    231247                        tmp->v->data.F32[ptr] = yOrderP;
     
    331347    //
    332348    psS32 num = 0;
    333     for (psS32 i = 0; i < xNum; i++) {
    334         for (psS32 j = 0; j < yNum; j++) {
     349    for (psS32 j = 0; j < yNum; j++) {
     350        for (psS32 i = 0; i < xNum; i++) {
    335351            pmStamp *stamp = (pmStamp *) stamps->data[num];
    336352
     
    351367                // border of pixels from the image edge.
    352368                //
    353                 // XXX: must set these
    354                 psS32 numX = 0;
    355                 psS32 numY = 0;
    356                 for (psS32 x = border + i * (numRows - 2.0 * border) / numX;
    357                         x < border + (i + 1) * (numRows - 2.0 * border) / numX; x++) {
    358                     for (psS32 y = border + j * (numCols - 2.0 * border) / numY;
    359                             y < border + (j + 1) * (numCols - 2.0 * border) / numY; y++) {
     369                // XXX: verify this (numX, numY), then get rid of it.
     370                //
     371                psS32 numX = xNum;
     372                psS32 numY = yNum;
     373                for (psS32 y = border + j * (numCols - 2.0 * border) / numY;
     374                        y < border + (j + 1) * (numCols - 2.0 * border) / numY; y++) {
     375                    for (psS32 x = border + i * (numRows - 2.0 * border) / numX;
     376                            x < border + (i + 1) * (numRows - 2.0 * border) / numX; x++) {
    360377
    361378                        // Determine if this pixel is larger than the max, and unmasked.
    362                         if ((image->data.F32[x][y] > max) &&
    363                                 !(mask->data.U8[x][y] & mask->data.U8[x][y])) {
    364                             max = image->data.F32[x][y];
     379                        if ((image->data.F32[y][x] > max) &&
     380                                !(mask->data.U8[y][x] & mask->data.U8[y][x])) {
     381                            max = image->data.F32[y][x];
    365382                            bestx = x;
    366383                            besty = y;
     
    373390                // Otherwise, mark the stamp as PM_STAMP_NONE
    374391                //
    375                 if (image->data.F32[bestx][besty] > threshold) {
     392                if (image->data.F32[besty][bestx] > threshold) {
    376393                    stamp->x = bestx;
    377394                    stamp->y = besty;
     
    394411 
    395412XXX: Modify loop so that terms higher than spatialOrder are not computed.
     413 
     414XXX: Modify this so that [i][j] location is calculated as (x^j * y^i)?
    396415 ******************************************************************************/
    397416static psImage *GenSpatialOrder(psS32 spatialOrder,
     
    490509            //
    491510            psImage *polyValues = GenSpatialOrder(spatialOrder,
    492                                                   ((psF64) (stamp->y - numHalfCols)) / ((psF64) numHalfCols),
    493                                                   ((psF64) (stamp->x - numHalfRows)) / ((psF64) numHalfRows));
     511                                                  ((psF64) (stamp->x - numHalfCols)) / ((psF64) numHalfCols),
     512                                                  ((psF64) (stamp->y - numHalfRows)) / ((psF64) numHalfRows));
    494513
    495514            //
    496515            // Iterate over all pixels surrounding this stamp.
    497516            //
     517            // XXX: I modified the y,x loop order, and an [x][y] reference (1.0/reference->data.F32[y][x]).
     518            //      Verify it.
    498519            //
    499             for (psS32 x = stamp->x - footprint; x < stamp->x + footprint; x++) {
    500                 for (psS32 y = stamp->y - footprint; y < stamp->y + footprint; y++) {
    501                     psF32 invNoise2 = 1.0/reference->data.F32[x][y]; // The inverse of the noise, squared.
     520            for (psS32 y = stamp->y - footprint; y < stamp->y + footprint; y++) {
     521                for (psS32 x = stamp->x - footprint; x < stamp->x + footprint; x++) {
     522                    psF32 invNoise2 = 1.0/reference->data.F32[y][x]; // The inverse of the noise, squared.
    502523
    503524                    // XXX: Think about a better decomposition of the computation
     
    711732        psF32 imageX = (((psF32) col) - numColsHalf) / numColsHalf; // Normalised position
    712733        psF32 imageY = (((psF32) row) - numRowsHalf) / numRowsHalf; // Normalised position
    713 
    714         // XXX: Ensure you have the (x, y) order correct.
    715734        psImage *polyValues = GenSpatialOrder(spatialOrder, imageX, imageY);
    716735
     
    722741            // XXX: What's the story with this?
    723742            #if 0
    724             // XXX: x/y order correct?
     743
    725744            psS32 xOrder = (psS32) kernels->xOrder->data.F32[k];
    726745            psS32 yOrder = (psS32) kernels->yOrder->data.F32[k];
     
    777796        psF32 imageX = (((psF32) col) - numColsHalf) / numColsHalf; // Normalised position
    778797        psF32 imageY = (((psF32) row) - numRowsHalf) / numRowsHalf; // Normalised position
    779 
    780         // XXX: Ensure you have the (x, y) order correct.
    781798        psImage *polyValues = GenSpatialOrder(spatialOrder, imageX, imageY);
    782799
     
    785802            // XXX: What's the story with this?
    786803            #if 0
    787             // XXX: x/y order correct?
    788804            psS32 xOrder = (psS32) kernels->xOrder->data.F32[k];
    789805            psS32 yOrder = (psS32) kernels->yOrder->data.F32[k];
     
    798814                for (psS32 xx = -kernelSize ; xx < kernelSize ; xx++) {
    799815                    // XXX: Should I do something special for the k==0 kernel?
    800                     // The POIS code does.
    801 
    802816                    conv += solution->data.F64[k] *
    803817                            input->data.F32[yy+row][xx+col] *
     
    943957        psS32 y = stamp->y;               // Stamp y coord
    944958        if (stamp->status == PM_STAMP_USED) {
    945             // XXX: Verify proper x,y order
    946             psRegion myReg = psRegionSet(y - ySize, y + ySize, x - xSize, x + xSize);
     959            psRegion myReg = psRegionSet(x - xSize, x + xSize, y - ySize, y + ySize);
    947960            psImage *refStamp = psImageSubset((psImage *) refImage, myReg);
    948961            psImage *inStamp = psImageSubset((psImage *) inImage, myReg);
     
    954967            (void)psBinaryOp(subStamp, subStamp, "/", inStamp);
    955968            (void)psBinaryOp(subStamp, subStamp, "*", subStamp);
    956             // XXX: Verify proper x,y order
    957969            myReg = psRegionSet(kernelSize, kernelSize + 2 * footprint,
    958970                                kernelSize, kernelSize + 2 * footprint);
     
    10691081
    10701082/*******************************************************************************
     1083XXX: There are definite (x, y) (row, col) problems here.
    10711084 ******************************************************************************/
    10721085psImage *pmSubtractionKernelImage(psImage *out,
     
    11071120        // centered at the specified (x, y) position.
    11081121        //
    1109         numRows = (psS32) ceilf( ((psF32) kernelSize) / ((x + 1.0)/2.0));
    1110         numRows = PS_MAX(numRows, (((psF32) kernelSize) / (1.0 - ((x + 1.0)/2.0))));
     1122        numRows = (psS32) ceilf( ((psF32) kernelSize) / ((y + 1.0)/2.0));
     1123        numRows = PS_MAX(numRows, (((psF32) kernelSize) / (1.0 - ((y + 1.0)/2.0))));
    11111124        numCols = (psS32) ceilf( ((psF32) kernelSize) / ((x + 1.0)/2.0));
    11121125        numCols = PS_MAX(numRows, (((psF32) kernelSize) / (1.0 - ((x + 1.0)/2.0))));
     
    11191132    PS_IMAGE_SET_F32(out, 0.0);
    11201133
     1134    // XXX: switch (i, j) so they correspond to (x, y).
    11211135    if (kernels->type == PM_SUBTRACTION_KERNEL_ISIS) {
    11221136        for (psS32 k = 0 ; k < nBF ; k++) {
     
    11431157            psS32 xOrder = kernels->xOrder->data.F32[nBF];
    11441158            psS32 yOrder = kernels->yOrder->data.F32[nBF];
    1145             // XXX: Verify that (u, v) correspond to (x, y) and that we have the row,col stuff correct.
    1146             // XXX: Verify the same for xOrder,yOrder.
    11471159            // XXX: Verify that this is correct.
    11481160            out->data.F32[yCenter - (psS32) v][xCenter - (psS32) u]+= solution->data.F64[nBF] *
     
    11541166    return(out);
    11551167}
    1156 // This code is
Note: See TracChangeset for help on using the changeset viewer.