IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 28, 2004, 3:10:27 PM (22 years ago)
Author:
desonia
Message:

fixed psImageSlice to match current SDR specifications (image range
specified differently).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/image/psImageExtraction.c

    r1920 r1924  
    99 *  @author Robert DeSonia, MHPCC
    1010 *
    11  *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-09-28 23:26:48 $
     11 *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-09-29 01:10:27 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    146146                           const char* section)
    147147{
    148     int x1;
    149     int x2;
    150     int y1;
    151     int y2;
    152 
    153     // section should be of the form '[x1:x2,y1:y2]'
     148    int col0;
     149    int col1;
     150    int row0;
     151    int row1;
     152
     153    // section should be of the form '[col0:col1,row0:row1]'
    154154    if (section == NULL) {
    155155        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSubsection",
     
    159159    }
    160160
    161     if (sscanf(section,"[%d:%d,%d:%d]",&x1,&x2,&y1,&y2) < 4) {
     161    if (sscanf(section,"[%d:%d,%d:%d]",&col0,&col1,&row0,&row1) < 4) {
    162162        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSubsection",
    163163                   PS_ERR_BAD_PARAMETER_NULL, true,
     
    166166        return NULL;
    167167    }
    168     return imageSubset(NULL,image,x1,y1,x2,y2);
     168    return imageSubset(NULL,image,col0,row0,col1,row1);
    169169}
    170170
    171 psImage* psImageTrim(psImage* image, int x0, int y0, int x1, int y1)
     171psImage* psImageTrim(psImage* image, int col0, int row0, int col1, int row1)
    172172{
    173173    if (image == NULL || image->data.V == NULL) {
     
    181181        return imageSubset(image,
    182182                           (psImage*)image->parent,
    183                            x0+image->col0,
    184                            y0+image->row0,
    185                            x1+image->col0,
    186                            y1+image->row0);
    187     }
    188 
    189     if (x0 < 0 || x1 < 0 || y0 < 0 || y1 < 0 ||
    190             x0 >= image->numCols || x1 >= image->numCols ||
    191             y0 >= image->numRows || y1 >= image->numRows ||
    192             x0 > x1 || y0 > y1 ) {
     183                           col0+image->col0,
     184                           row0+image->row0,
     185                           col1+image->col0,
     186                           row1+image->row0);
     187    }
     188
     189    if (    col0 < 0 ||
     190            row0 < 0 ||
     191            col1 >= image->numCols ||
     192            row1 >= image->numRows ||
     193            col0 > col1 ||
     194            row0 > row1 ) {
    193195        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageTrim",
    194196                   PS_ERR_BAD_PARAMETER_VALUE, true,
    195197                   PS_ERRORTEXT_psImage_SUBSET_RANGE_INVALID,
    196                    x0, x1, y0, y1,
     198                   col0, col1, row0, row1,
    197199                   image->numCols, image->numRows);
    198200        return NULL;
     
    202204
    203205    unsigned int elementSize = PSELEMTYPE_SIZEOF(image->type.type);
    204     unsigned int numCols = x1-x0+1;
    205     unsigned int numRows = y1-y0+1;
     206    unsigned int numCols = col1-col0+1;
     207    unsigned int numRows = row1-row0+1;
    206208    unsigned int rowSize = elementSize*numCols;
    207     unsigned int colOffset = elementSize * x0;
     209    unsigned int colOffset = elementSize * col0;
    208210    void* imageData = image->rawDataBuffer;
    209     for (int row = y0; row < y1; row++) {
     211    for (int row = row0; row < row1; row++) {
    210212        memmove(imageData,image->data.U8[row] + colOffset,rowSize);
    211213        imageData = (psU8*)imageData + rowSize;
     
    399401                       const psImage* restrict mask,
    400402                       unsigned int maskVal,
    401                        unsigned int col,
    402                        unsigned int row,
    403                        unsigned int numCols,
    404                        unsigned int numRows,
     403                       int col0,
     404                       int row0,
     405                       int col1,
     406                       int row1,
    405407                       psImageCutDirection direction,
    406408                       const psStats* stats)
     
    422424    }
    423425
    424     if (numRows < 1 || numCols < 1) {
     426    if (col1 < 0) {
     427        col1 += in->numCols;
     428    }
     429
     430    if (row1 < 0) {
     431        row1 += in->numRows;
     432    }
     433
     434    if (    col0 < 0 ||
     435            row0 < 0 ||
     436            col1 >= in->numCols ||
     437            row1 >= in->numRows ||
     438            col0 >= col1 ||
     439            row0 >= row1) {
    425440        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice",
    426                    PS_ERR_BAD_PARAMETER_NULL, true,
    427                    PS_ERRORTEXT_psImage_SUBSET_ZERO_SIZE,
    428                    col,col+numCols,row,row+numRows);
     441                   PS_ERR_BAD_PARAMETER_VALUE, true,
     442                   PS_ERRORTEXT_psImage_SUBSET_RANGE_INVALID,
     443                   col0, col1, row0, row1,
     444                   in->numCols, in->numRows);
    429445        psFree(out);
    430446        return NULL;
     
    437453    if (direction == PS_CUT_X_NEG || direction == PS_CUT_Y_NEG) {
    438454        delta = -1;
    439     }
    440     // if numRows/numCols is negative, invert the
    441     // problem to give positive
    442     // numRows/numCols (and cut in opposite
    443     // direction).
    444     if (numRows < 0) {
    445         numRows = -numRows;
    446         row -= (numRows - 1);
    447         delta = -delta;
    448     }
    449 
    450     if (numCols < 0) {
    451         numCols = -numCols;
    452         col -= (numCols - 1);
    453         delta = -delta;
    454455    }
    455456
     
    474475    }
    475476
    476     if (row >= inRows || col >= inCols || col + numCols > inCols || row + numRows > inRows) {
    477         psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice",
    478                    PS_ERR_BAD_PARAMETER_VALUE, true,
    479                    PS_ERRORTEXT_psImage_SUBSET_RANGE_INVALID,
    480                    col, row, col+numCols, row+numRows,
    481                    inCols, inRows);
    482         psFree(out);
    483         return NULL;
    484     }
    485 
    486477    if (stats == NULL) {
    487478        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice",
     
    505496    myStats = psAlloc(sizeof(psStats));
    506497    *myStats = *stats;
     498
     499    int numCols = col1-col0;
     500    int numRows = row1-row0;
    507501
    508502    if (direction == PS_CUT_X_POS || direction == PS_CUT_X_NEG) {
     
    534528    case PS_TYPE_##TYPE: { \
    535529            psMaskType* maskVecData = NULL; \
    536             for (int c=0;c<numCols;c++) { \
    537                 ps##TYPE *imgData = in->data.TYPE[row] + col + c; \
     530            for (int c=col0;c<col1;c++) { \
     531                ps##TYPE *imgData = in->data.TYPE[row0] + c; \
    538532                ps##TYPE *imgVecData = imgVec->data.TYPE; \
    539533                if (maskVec != NULL) { \
    540534                    maskVecData = maskVec->data.V; \
    541                     maskData = (psMaskType* )(mask->data.V[row]) + col + c; \
     535                    maskData = (psMaskType* )(mask->data.V[row0]) + c; \
    542536                } \
    543                 for (int r=0;r<numRows;r++) { \
     537                for (int r=row0;r<row1;r++) { \
    544538                    *(imgVecData++) = *imgData; \
    545539                    imgData += inCols; \
     
    553547                *outData = statVal; \
    554548                if (outPosition != NULL) { \
    555                     *outPosition = col+c; \
     549                    *outPosition = c; \
    556550                    outPosition += delta; \
    557551                } \
     
    594588        psU32* outPosition = NULL;
    595589
    596         // fill in psVectors to fake out the
    597         // statistics functions.
     590        // fill in psVector to fake out the statistics functions.
    598591        imgVec = psAlloc(sizeof(psVector));
    599592        imgVec->type = in->type;
     
    614607        outData = out->data.F64;
    615608        if (delta < 0) {
    616             outData += numRows - 1;
     609            outData += numRows-1;
    617610            if (outPosition != NULL) {
    618                 outPosition += numRows - 1;
     611                outPosition += numRows-1;
    619612            }
    620613        }
    621614
    622         for (int r = 0; r < numRows; r++) {
     615        for (int r = row0; r < row1; r++) {
    623616            // point the vector struct to the
    624617            // data to calculate the stats
    625             imgVec->data.V = (void *)(in->data.U8[row + r] + col * elementSize);
     618            imgVec->data.V = (void *)(in->data.U8[r] + col0 * elementSize);
    626619            if (maskVec != NULL) {
    627                 maskVec->data.V = (void *)(mask->data.U8[row + r] + col * sizeof(psMaskType));
     620                maskVec->data.V = (void *)(mask->data.U8[r] + col0 * sizeof(psMaskType));
    628621            }
    629622            myStats = psVectorStats(myStats, imgVec, maskVec, maskVal);
     
    631624            *outData = statVal;
    632625            if (outPosition != NULL) {
    633                 *outPosition = row + r;
     626                *outPosition = r;
    634627                outPosition += delta;
    635628
Note: See TracChangeset for help on using the changeset viewer.