IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1924


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
Files:
4 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
  • trunk/psLib/test/image/tst_psImageExtraction.c

    r1797 r1924  
    66*  @author Robert DeSonia, MHPCC
    77*
    8 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    9 *  @date $Date: 2004-09-11 02:55:29 $
     8*  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     9*  @date $Date: 2004-09-29 01:10:27 $
    1010*
    1111*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2020
    2121testDescription tests[] = {
    22                               {
    23                                   testImageSlice, 552, "psImageSlice", 0, false
    24                               },
    25                               {
    26                                   NULL
    27                               }
     22                              {testImageSlice, 552, "psImageSlice", 0, false},
     23                              {NULL}
    2824                          };
    2925
     
    7268
    7369    #define PSIMAGESLICE_TEST1(M,N,DIRECTION,TRUTH_SIZE,TRUTHPIX_X,TRUTHPIX_Y,TESTNUM) \
    74     out = psImageSlice(out,positions,image,mask,1,c/10,r/10,M,N,DIRECTION,stat); \
     70    out = psImageSlice(out,positions,image,mask,1,c/10,r/10,c/10+M,r/10+N,DIRECTION,stat); \
    7571    \
    7672    if (out->n != TRUTH_SIZE) { \
     
    136132    */
    137133    psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." );
    138     out = psImageSlice( out, NULL, NULL, NULL, 0, c / 10, r / 10, 1, 1, PS_CUT_X_POS, stat );
     134    out = psImageSlice( out,
     135                        NULL, NULL,
     136                        NULL, 0,
     137                        c/10, r/10,
     138                        c/10 + 1, r/10 + 1,
     139                        PS_CUT_X_POS,
     140                        stat );
    139141    if ( out != NULL ) {
    140142        psError( __func__, "Giving a NULL image, psImageSlice didn't return NULL as expected" );
     
    148150    */
    149151    psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." );
    150     out = psImageSlice( out, NULL, image, mask, 1, c / 10, r / 10, 1, 1, PS_CUT_X_POS, NULL );
     152    out = psImageSlice( out,
     153                        NULL, image,
     154                        mask, 1,
     155                        c/10, r/10,
     156                        c/10 + 1,
     157                        r/10 + 1,
     158                        PS_CUT_X_POS,
     159                        NULL );
    151160    if ( out != NULL ) {
    152161        psError( __func__, "Giving a NULL stat struct, psImageSlice didn't return NULL as expected" );
     
    161170    */
    162171    psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." );
    163     out = psImageSlice( out, NULL, image, mask, 1, c / 10, r / 10, 1, 1, 5, stat );
     172    out = psImageSlice( out, NULL,
     173                        image,
     174                        mask, 1,
     175                        c/10, r/10,
     176                        c/10+1, r/10+1,
     177                        5,
     178                        stat);
    164179    if ( out != NULL ) {
    165180        psError( __func__, "Giving a bogus direction flag, psImageSlice didn't return NULL as expected" );
     
    172187    */
    173188    psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." );
    174     out = psImageSlice( out, NULL, image, mask, 1, c / 10, r / 10, 0, 0, PS_CUT_X_POS, stat );
     189    out = psImageSlice( out,
     190                        NULL,
     191                        image,
     192                        mask, 1,
     193                        c/10, r/10,
     194                        c/10, r/10,
     195                        PS_CUT_X_POS,
     196                        stat );
    175197    if ( out != NULL ) {
    176198        psError( __func__, "Giving a 0x0 region, psImageSlice didn't return NULL as expected" );
     
    184206    */
    185207    psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." );
    186     out = psImageSlice( out, NULL, image, mask, 1, c + 1, r / 10, 1, 1, PS_CUT_X_POS, stat );
     208    out = psImageSlice( out, NULL,
     209                        image,
     210                        mask, 1,
     211                        c+1, r/10,
     212                        c+2, r/10+10,
     213                        PS_CUT_X_POS,
     214                        stat );
    187215    if ( out != NULL ) {
    188216        psError( __func__, "Giving an invalid x position, psImageSlice didn't return NULL as expected" );
     
    191219
    192220    psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." );
    193     out = psImageSlice( out, NULL, image, mask, 1, c / 10, r + 1, 1, 1, PS_CUT_X_POS, stat );
     221    out = psImageSlice( out, NULL,
     222                        image,
     223                        mask, 1,
     224                        c/10, r+1,
     225                        c/10+1,r+5,
     226                        PS_CUT_X_POS,
     227                        stat );
    194228    if ( out != NULL ) {
    195229        psError( __func__, "Giving an invalid y position, psImageSlice didn't return NULL as expected" );
     
    198232
    199233    psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." );
    200     out = psImageSlice( out, NULL, image, mask, 1, c / 10, r / 10, c, 1, PS_CUT_X_POS, stat );
     234    out = psImageSlice( out, NULL,
     235                        image,
     236                        mask, 1,
     237                        c/10, r/10,
     238                        c+1, r/10+1,
     239                        PS_CUT_X_POS,
     240                        stat);
    201241    if ( out != NULL ) {
    202242        psError( __func__, "Giving an invalid numCols, psImageSlice didn't return NULL as expected" );
     
    205245
    206246    psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." );
    207     out = psImageSlice( out, NULL, image, mask, 1, c / 10, r / 10, 1, r, PS_CUT_X_POS, stat );
     247    out = psImageSlice( out, NULL,
     248                        image,
     249                        mask, 1,
     250                        c/10, r/10,
     251                        c/10+1, r + 1,
     252                        PS_CUT_X_POS,
     253                        stat);
    208254    if ( out != NULL ) {
    209255        psError( __func__, "Giving an invalid numRows, psImageSlice didn't return NULL as expected" );
     
    218264    psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." );
    219265    stat->options = 0;
    220     out = psImageSlice( out, NULL, image, mask, 1, c / 10, r / 10, 1, 1, PS_CUT_X_POS, stat );
     266    out = psImageSlice( out, NULL,
     267                        image,
     268                        mask, 1,
     269                        c/10, r/10,
     270                        c/10+1, r/10+1,
     271                        PS_CUT_X_POS,
     272                        stat);
    221273    if ( out != NULL ) {
    222274        psError( __func__, "Giving an invalid numRows, psImageSlice didn't return NULL as expected" );
  • trunk/psLib/test/image/verified/tst_psImageExtraction.stderr

    r1920 r1924  
    2020    Following should be an error.
    2121<DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
    22     Specified subset, [200:<LINENO>,100:<LINENO>], contains no pixel data.
     22    Specified subset range, [200:<LINENO>,100:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
    2323<DATE><TIME>|<HOST>|I|testImageSlice
    2424    Following should be an error.
    2525<DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
    26     Specified subset range, [2001:<LINENO>,2002:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
     26    Specified subset range, [2001:<LINENO>,100:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
    2727<DATE><TIME>|<HOST>|I|testImageSlice
    2828    Following should be an error.
    2929<DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
    30     Specified subset range, [200:<LINENO>,201:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
     30    Specified subset range, [200:<LINENO>,1001:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
    3131<DATE><TIME>|<HOST>|I|testImageSlice
    3232    Following should be an error.
    3333<DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
    34     Specified subset range, [200:<LINENO>,2200:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
     34    Specified subset range, [200:<LINENO>,100:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
    3535<DATE><TIME>|<HOST>|I|testImageSlice
    3636    Following should be an error.
    3737<DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
    38     Specified subset range, [200:<LINENO>,201:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
     38    Specified subset range, [200:<LINENO>,100:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
    3939<DATE><TIME>|<HOST>|I|testImageSlice
    4040    Following should be an error.
Note: See TracChangeset for help on using the changeset viewer.