Changeset 1924 for trunk/psLib/src/image
- Timestamp:
- Sep 28, 2004, 3:10:27 PM (22 years ago)
- Location:
- trunk/psLib/src/image
- Files:
-
- 2 edited
-
psImageExtraction.c (modified) (16 diffs)
-
psImageExtraction.h (modified) (3 diffs)
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
Note:
See TracChangeset
for help on using the changeset viewer.
