Changeset 1924
- Timestamp:
- Sep 28, 2004, 3:10:27 PM (22 years ago)
- Location:
- trunk/psLib
- Files:
-
- 4 edited
-
src/image/psImageExtraction.c (modified) (16 diffs)
-
src/image/psImageExtraction.h (modified) (3 diffs)
-
test/image/tst_psImageExtraction.c (modified) (12 diffs)
-
test/image/verified/tst_psImageExtraction.stderr (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/image/psImageExtraction.c
r1920 r1924 9 9 * @author Robert DeSonia, MHPCC 10 10 * 11 * @version $Revision: 1.1 7$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-09-2 8 23:26:48$11 * @version $Revision: 1.18 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-09-29 01:10:27 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 146 146 const char* section) 147 147 { 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]' 154 154 if (section == NULL) { 155 155 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSubsection", … … 159 159 } 160 160 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) { 162 162 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSubsection", 163 163 PS_ERR_BAD_PARAMETER_NULL, true, … … 166 166 return NULL; 167 167 } 168 return imageSubset(NULL,image, x1,y1,x2,y2);168 return imageSubset(NULL,image,col0,row0,col1,row1); 169 169 } 170 170 171 psImage* psImageTrim(psImage* image, int x0, int y0, int x1, int y1)171 psImage* psImageTrim(psImage* image, int col0, int row0, int col1, int row1) 172 172 { 173 173 if (image == NULL || image->data.V == NULL) { … … 181 181 return imageSubset(image, 182 182 (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 ) { 193 195 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageTrim", 194 196 PS_ERR_BAD_PARAMETER_VALUE, true, 195 197 PS_ERRORTEXT_psImage_SUBSET_RANGE_INVALID, 196 x0, x1, y0, y1,198 col0, col1, row0, row1, 197 199 image->numCols, image->numRows); 198 200 return NULL; … … 202 204 203 205 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; 206 208 unsigned int rowSize = elementSize*numCols; 207 unsigned int colOffset = elementSize * x0;209 unsigned int colOffset = elementSize * col0; 208 210 void* imageData = image->rawDataBuffer; 209 for (int row = y0; row < y1; row++) {211 for (int row = row0; row < row1; row++) { 210 212 memmove(imageData,image->data.U8[row] + colOffset,rowSize); 211 213 imageData = (psU8*)imageData + rowSize; … … 399 401 const psImage* restrict mask, 400 402 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, 405 407 psImageCutDirection direction, 406 408 const psStats* stats) … … 422 424 } 423 425 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) { 425 440 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); 429 445 psFree(out); 430 446 return NULL; … … 437 453 if (direction == PS_CUT_X_NEG || direction == PS_CUT_Y_NEG) { 438 454 delta = -1; 439 }440 // if numRows/numCols is negative, invert the441 // problem to give positive442 // numRows/numCols (and cut in opposite443 // 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;454 455 } 455 456 … … 474 475 } 475 476 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 486 477 if (stats == NULL) { 487 478 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice", … … 505 496 myStats = psAlloc(sizeof(psStats)); 506 497 *myStats = *stats; 498 499 int numCols = col1-col0; 500 int numRows = row1-row0; 507 501 508 502 if (direction == PS_CUT_X_POS || direction == PS_CUT_X_NEG) { … … 534 528 case PS_TYPE_##TYPE: { \ 535 529 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; \ 538 532 ps##TYPE *imgVecData = imgVec->data.TYPE; \ 539 533 if (maskVec != NULL) { \ 540 534 maskVecData = maskVec->data.V; \ 541 maskData = (psMaskType* )(mask->data.V[row ]) + col+ c; \535 maskData = (psMaskType* )(mask->data.V[row0]) + c; \ 542 536 } \ 543 for (int r= 0;r<numRows;r++) { \537 for (int r=row0;r<row1;r++) { \ 544 538 *(imgVecData++) = *imgData; \ 545 539 imgData += inCols; \ … … 553 547 *outData = statVal; \ 554 548 if (outPosition != NULL) { \ 555 *outPosition = c ol+c; \549 *outPosition = c; \ 556 550 outPosition += delta; \ 557 551 } \ … … 594 588 psU32* outPosition = NULL; 595 589 596 // fill in psVectors to fake out the 597 // statistics functions. 590 // fill in psVector to fake out the statistics functions. 598 591 imgVec = psAlloc(sizeof(psVector)); 599 592 imgVec->type = in->type; … … 614 607 outData = out->data.F64; 615 608 if (delta < 0) { 616 outData += numRows -1;609 outData += numRows-1; 617 610 if (outPosition != NULL) { 618 outPosition += numRows -1;611 outPosition += numRows-1; 619 612 } 620 613 } 621 614 622 for (int r = 0; r < numRows; r++) {615 for (int r = row0; r < row1; r++) { 623 616 // point the vector struct to the 624 617 // data to calculate the stats 625 imgVec->data.V = (void *)(in->data.U8[r ow + r] + col* elementSize);618 imgVec->data.V = (void *)(in->data.U8[r] + col0 * elementSize); 626 619 if (maskVec != NULL) { 627 maskVec->data.V = (void *)(mask->data.U8[r ow + r] + col* sizeof(psMaskType));620 maskVec->data.V = (void *)(mask->data.U8[r] + col0 * sizeof(psMaskType)); 628 621 } 629 622 myStats = psVectorStats(myStats, imgVec, maskVec, maskVal); … … 631 624 *outData = statVal; 632 625 if (outPosition != NULL) { 633 *outPosition = r ow + r;626 *outPosition = r; 634 627 outPosition += delta; 635 628 -
trunk/psLib/src/image/psImageExtraction.h
r1920 r1924 10 10 * @author Robert DeSonia, MHPCC 11 11 * 12 * @version $Revision: 1.1 5$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-09-2 8 23:26:48$12 * @version $Revision: 1.16 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-09-29 01:10:27 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 114 114 /** Extract pixels from rectlinear region to a vector (array of floats). 115 115 * 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. 124 134 * 125 135 * @return psVector the resulting vector … … 134 144 const psImage* restrict mask, ///< the mask for the input image. 135 145 unsigned int maskVal, ///< the mask value to apply to the mask 136 unsigned int col,///< the leftmost column of the slice region137 unsigned int row,///< the bottommost row of the slice region138 unsigned int numCols, ///< the number of columns inthe slice region139 unsigned int numRows, ///< the number of rows inthe slice region146 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 140 150 psImageCutDirection direction, ///< the slice dimension and direction 141 151 const psStats* stats ///< the statistic to perform in slice operation -
trunk/psLib/test/image/tst_psImageExtraction.c
r1797 r1924 6 6 * @author Robert DeSonia, MHPCC 7 7 * 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 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 20 20 21 21 testDescription tests[] = { 22 { 23 testImageSlice, 552, "psImageSlice", 0, false 24 }, 25 { 26 NULL 27 } 22 {testImageSlice, 552, "psImageSlice", 0, false}, 23 {NULL} 28 24 }; 29 25 … … 72 68 73 69 #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); \ 75 71 \ 76 72 if (out->n != TRUTH_SIZE) { \ … … 136 132 */ 137 133 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 ); 139 141 if ( out != NULL ) { 140 142 psError( __func__, "Giving a NULL image, psImageSlice didn't return NULL as expected" ); … … 148 150 */ 149 151 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 ); 151 160 if ( out != NULL ) { 152 161 psError( __func__, "Giving a NULL stat struct, psImageSlice didn't return NULL as expected" ); … … 161 170 */ 162 171 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); 164 179 if ( out != NULL ) { 165 180 psError( __func__, "Giving a bogus direction flag, psImageSlice didn't return NULL as expected" ); … … 172 187 */ 173 188 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 ); 175 197 if ( out != NULL ) { 176 198 psError( __func__, "Giving a 0x0 region, psImageSlice didn't return NULL as expected" ); … … 184 206 */ 185 207 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 ); 187 215 if ( out != NULL ) { 188 216 psError( __func__, "Giving an invalid x position, psImageSlice didn't return NULL as expected" ); … … 191 219 192 220 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 ); 194 228 if ( out != NULL ) { 195 229 psError( __func__, "Giving an invalid y position, psImageSlice didn't return NULL as expected" ); … … 198 232 199 233 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); 201 241 if ( out != NULL ) { 202 242 psError( __func__, "Giving an invalid numCols, psImageSlice didn't return NULL as expected" ); … … 205 245 206 246 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); 208 254 if ( out != NULL ) { 209 255 psError( __func__, "Giving an invalid numRows, psImageSlice didn't return NULL as expected" ); … … 218 264 psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." ); 219 265 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); 221 273 if ( out != NULL ) { 222 274 psError( __func__, "Giving an invalid numRows, psImageSlice didn't return NULL as expected" ); -
trunk/psLib/test/image/verified/tst_psImageExtraction.stderr
r1920 r1924 20 20 Following should be an error. 21 21 <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>]. 23 23 <DATE><TIME>|<HOST>|I|testImageSlice 24 24 Following should be an error. 25 25 <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>]. 27 27 <DATE><TIME>|<HOST>|I|testImageSlice 28 28 Following should be an error. 29 29 <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>]. 31 31 <DATE><TIME>|<HOST>|I|testImageSlice 32 32 Following should be an error. 33 33 <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>]. 35 35 <DATE><TIME>|<HOST>|I|testImageSlice 36 36 Following should be an error. 37 37 <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>]. 39 39 <DATE><TIME>|<HOST>|I|testImageSlice 40 40 Following should be an error.
Note:
See TracChangeset
for help on using the changeset viewer.
