Changeset 5137 for trunk/psLib/src/imageops/psImageStats.c
- Timestamp:
- Sep 26, 2005, 12:35:54 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/imageops/psImageStats.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageStats.c
r5096 r5137 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1.8 0$ $Name: not supported by cvs2svn $12 * @date $Date: 2005-09-2 2 22:49:29$11 * @version $Revision: 1.81 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2005-09-26 22:35:53 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 638 638 // count number of pixels with given mask value 639 639 long psImageCountPixelMask (psImage *mask, 640 psRegion region, 640 641 psMaskType value) 641 642 { 642 643 long Npixels = 0; 643 644 for (long i = 0; i < mask->numRows; i++) { 645 for (long j = 0; j < mask->numCols; j++) { 646 if (mask->data.U8[i][j] & value) { 647 Npixels ++; 648 } 649 } 644 int x0 = 0; 645 int y0 = 0; 646 int x1 = 0; 647 int y1 = 0; 648 psElemType type; 649 if (mask == NULL) { 650 psError(PS_ERR_BAD_PARAMETER_NULL, true, 651 PS_ERRORTEXT_psImage_IMAGE_NULL); 652 return -1; 653 } 654 if (region.x1 > mask->numCols || region.y1 > mask->numRows) { 655 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 656 "psRegion input is outside of image boundary\n"); 657 return -1; 658 } 659 if (region.x0 <= 0 || region.x1 <= 0 || region.y0 <= 0 || region.y1 <= 0) { 660 region = psRegionForImage(mask, region); 661 } 662 if (region.x0 > region.x1 || region.y0 > region.y1) { 663 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 664 "Invalid region. Lower boundary greater than upper boundary.\n"); 665 return -1; 666 } 667 if (region.x0 == region.x1 || region.y0 == region.y1) { 668 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 669 "psRegion input contains 0 pixels\n"); 670 return -1; 671 } 672 673 x0 = (int)(roundf(region.x0)); 674 x1 = (int)(roundf(region.x1)); 675 y0 = (int)(roundf(region.y0)); 676 y1 = (int)(roundf(region.y1)); 677 678 type = mask->type.type; 679 680 switch (type) { 681 case PS_TYPE_U8: 682 for (long i = x0; i < x1; i++) { 683 for (long j = y0; j < y1; j++) { 684 if (mask->data.U8[i][j] & value) { 685 Npixels ++; 686 } 687 } 688 } 689 break; 690 case PS_TYPE_S8: 691 case PS_TYPE_S16: 692 case PS_TYPE_S32: 693 case PS_TYPE_S64: 694 case PS_TYPE_U16: 695 case PS_TYPE_U32: 696 case PS_TYPE_U64: 697 case PS_TYPE_F32: 698 case PS_TYPE_F64: 699 case PS_TYPE_C32: 700 case PS_TYPE_C64: 701 default: 702 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 703 PS_ERRORTEXT_psImage_IMAGE_MASK_TYPE, type, PS_TYPE_U8); 704 return -1; 650 705 } 651 706 return (Npixels); 652 } 653 707 708 709 } 710
Note:
See TracChangeset
for help on using the changeset viewer.
