IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1924 for trunk/psLib/src/image


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).

Location:
trunk/psLib/src/image
Files:
2 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
  • trunk/psLib/src/image/psImageExtraction.h

    r1920 r1924  
    1010*  @author Robert DeSonia, MHPCC
    1111*
    12 *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2004-09-28 23:26:48 $
     12*  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2004-09-29 01:10:27 $
    1414*
    1515*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    114114/** Extract pixels from rectlinear region to a vector (array of floats).
    115115 *
    116  *  The output vector contains either nx or ny elements, based on the value of
    117  *  the direction: e.g., if direction is PS_CUT_X_POS, there are nx elements.
    118  *  The input region is collapsed in the perpendicular direction, and each
    119  *  element of the output vectors is derived from the statistics of the pixels
    120  *  at that direction coordinate. The statistic used to derive the output
    121  *  vector value is specified by stats. Only one of the statistics choices may
    122  *  be specified, otherwise the function must return an error. This function
    123  *  must be defined for the following types: psS8, psU16, psF32, psF64.
     116 *  The output vector contains either col1-col0 or row1-row0 elements, based
     117 *  on the value of the direction: e.g., if direction is PS_CUT_X_POS, there
     118 *  are col1-col0 elements. The region to be  sliced  is defined by the
     119 *  lower-left corner, (col0,row0), and the upper-right corner, (col1,row1).
     120 *  Note that the row and column of the  upper right-hand corner  are NOT
     121 *  included in the region. In the event that col1 or row1 are negative, they
     122 *  shall be interpreted as being relative to the size of the parent image in
     123 *  that dimension. The input region is collapsed in the direction perpendicular
     124 *  to that specified by direction, and each element of the output vectors is
     125 *  derived from the statistics of the pixels at that direction coordinate. The
     126 *  statistic used to derive the output vector value is specified by stats.
     127 *  If mask is non-NULL, pixels for which the corresponding mask pixel
     128 *  matches maskVal are excluded from operations. If coords is not NULL, the
     129 *  calculated coordinates along the slice are returned in this vector. Only
     130 *  one of the statistics choices may be specified, otherwise the function
     131 *  must return an error.
     132 *
     133 *  This function is defined for the following types: psS8, psU16, psF32, psF64.
    124134 *
    125135 * @return psVector    the resulting vector
     
    134144    const psImage* restrict mask,      ///< the mask for the input image.
    135145    unsigned int maskVal,              ///< the mask value to apply to the mask
    136     unsigned int col,                  ///< the leftmost column of the slice region
    137     unsigned int row,                  ///< the bottommost row of the slice region
    138     unsigned int numCols,              ///< the number of columns in the slice region
    139     unsigned int numRows,              ///< the number of rows in the slice region
     146    int col0,                          ///< the leftmost column of the slice region
     147    int row0,                          ///< the bottommost row of the slice region
     148    int col1,                          ///< exclusive end column of the slice region
     149    int row1,                           ///< exclusive end row of the slice region
    140150    psImageCutDirection direction,     ///< the slice dimension and direction
    141151    const psStats* stats               ///< the statistic to perform in slice operation
Note: See TracChangeset for help on using the changeset viewer.