Changeset 2074
- Timestamp:
- Oct 12, 2004, 4:40:13 PM (22 years ago)
- Location:
- trunk/psLib
- Files:
-
- 4 edited
-
src/dataManip/psStats.c (modified) (2 diffs)
-
src/image/psImageExtraction.c (modified) (5 diffs)
-
src/math/psStats.c (modified) (2 diffs)
-
test/image/tst_psImageExtraction.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/dataManip/psStats.c
r2058 r2074 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1.6 6$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-10-1 2 20:53:02$11 * @version $Revision: 1.67 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-10-13 02:40:13 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 388 388 } 389 389 } else { 390 rangeMin = stats->min;391 rangeMax = stats->max;392 390 if (maskVector != NULL) { 393 391 for (i = 0; i < myVector->n; i++) { -
trunk/psLib/src/image/psImageExtraction.c
r2067 r2074 9 9 * @author Robert DeSonia, MHPCC 10 10 * 11 * @version $Revision: 1.2 2$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-10-13 0 0:10:50$11 * @version $Revision: 1.23 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-10-13 02:40:13 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 195 195 } 196 196 197 if (col1 < 1) { 198 col1 += image->numCols; 199 } 200 201 if (row1 < 1) { 202 row1 += image->numRows; 203 } 204 197 205 if ( col0 < 0 || 198 206 row0 < 0 || 199 col1 > =image->numCols ||200 row1 > =image->numRows ||201 col0 > col1 ||202 row0 > row1 ) {207 col1 > image->numCols || 208 row1 > image->numRows || 209 col0 >= col1 || 210 row0 >= row1 ) { 203 211 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageTrim", 204 212 PS_ERR_BAD_PARAMETER_VALUE, true, 205 213 PS_ERRORTEXT_psImage_SUBSET_RANGE_INVALID, 206 col0, col1, row0, row1, 207 image->numCols, image->numRows); 214 col0, col1-1, row0, row1-1, 215 image->numCols-1, image->numRows-1); 216 psFree(image); 208 217 return NULL; 209 218 } … … 212 221 213 222 unsigned int elementSize = PSELEMTYPE_SIZEOF(image->type.type); 214 unsigned int numCols = col1-col0 +1;215 unsigned int numRows = row1-row0 +1;223 unsigned int numCols = col1-col0; 224 unsigned int numRows = row1-row0; 216 225 unsigned int rowSize = elementSize*numCols; 217 226 unsigned int colOffset = elementSize * col0; 218 void* imageData = image->rawDataBuffer;227 psU8* imageData = image->rawDataBuffer; 219 228 for (int row = row0; row < row1; row++) { 220 229 memmove(imageData,image->data.U8[row] + colOffset,rowSize); 221 imageData = (psU8*)imageData +rowSize;230 imageData += rowSize; 222 231 } 223 232 … … 265 274 } 266 275 267 if (col1 < 0) {276 if (col1 < 1) { 268 277 col1 += in->numCols; 269 278 } 270 279 271 if (row1 < 0) {280 if (row1 < 1) { 272 281 row1 += in->numRows; 273 282 } … … 275 284 if ( col0 < 0 || 276 285 row0 < 0 || 277 col1 > =in->numCols ||278 row1 > =in->numRows ||286 col1 > in->numCols || 287 row1 > in->numRows || 279 288 col0 >= col1 || 280 289 row0 >= row1) { -
trunk/psLib/src/math/psStats.c
r2058 r2074 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1.6 6$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-10-1 2 20:53:02$11 * @version $Revision: 1.67 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-10-13 02:40:13 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 388 388 } 389 389 } else { 390 rangeMin = stats->min;391 rangeMax = stats->max;392 390 if (maskVector != NULL) { 393 391 for (i = 0; i < myVector->n; i++) { -
trunk/psLib/test/image/tst_psImageExtraction.c
r2067 r2074 6 6 * @author Robert DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1.1 2$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-10-13 0 0:10:50$8 * @version $Revision: 1.13 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-10-13 02:40:13 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 42 42 const int r = 1000; 43 43 const int c = 2000; 44 const int m = r / 2 ;45 const int n = r / 4 ;44 const int m = r / 2 -1; 45 const int n = r / 4 -1; 46 46 psVector* out = NULL; 47 47 psImage* image = psImageAlloc( c, r, PS_TYPE_F32 ); … … 77 77 imageRow[ col ] = ( psF32 ) col + rowOffset; 78 78 imgU8Row[ col ] = (psU8) col; 79 if ( row == r/10 ) { 80 maskRow[ col ] = 1; 81 } else { 82 maskRow[ col ] = 0; 83 } 84 // maskRow[ col ] = 0; 79 maskRow[ col ] = 0; 85 80 maskS8Row[ col ] = 0; 86 81 maskSzRow[ col ] = 0; 87 82 } 88 83 } 89 90 // test MxN case91 84 92 85 #define PSIMAGESLICE_TEST1(M,N,DIRECTION,TRUTH_SIZE,TRUTHPIX_X,TRUTHPIX_Y,TESTNUM) \ … … 106 99 \ 107 100 for (int i=0;i<out->n;i++) { \ 108 if (abs(out->data.F64[i]-image->data.F32[r/10+TRUTHPIX_Y][c/10+TRUTHPIX_X]) > 1.0/(psF32)r) { \ 109 psError(__func__,"Improper result at position %d.",i); \ 101 if (fabs(out->data.F64[i]-image->data.F32[r/10+TRUTHPIX_Y][c/10+TRUTHPIX_X]) > 1.0/(psF32)r) { \ 102 psError(__func__,"Improper result at position %d. Got %g, expected %g",i, \ 103 out->data.F64[i],image->data.F32[r/10+TRUTHPIX_Y][c/10+TRUTHPIX_X]); \ 110 104 return TESTNUM*4+3; \ 111 105 } \ … … 751 745 int r = 200; 752 746 int c = 300; 753 int q uarterR = r/4;754 int q uarterC = c/4;747 int qtrR = r/4; 748 int qtrC = c/4; 755 749 int halfR = r/2; 750 int halfC = c/2; 751 756 752 psImage* image = psImageAlloc(c,r,PS_TYPE_F32); 757 753 for (int row = 0; row < image->numRows; row++) { 758 754 for (int col = 0; col < image->numCols; col++) { 759 image->data.F32[row][col] = ((psF32)row+1.0f)/((psF32)col+1.0f); 760 } 761 } 762 755 image->data.F32[row][col] = (psF32)col + (psF32)row/1000.0f; 756 } 757 } 758 759 /* 760 1. invoke psImageTrim with non-NULL image, and a valid region 761 x0,y0->x1,y1 (using only positive values). Verify that: 762 a. the return psImage is the same as the input psImage. 763 b. the size of the psImage is x1-x0 by y1-y0. 764 c. the pixel values coorespond to the region [x0:x1-1,y0:y1-1]. 765 */ 763 766 psImage* image1 = psImageCopy(NULL,image,PS_TYPE_F32); 764 psImage* image2 = psImageTrim(image1,c/4,r/4,c*3/4,r*3/4); 765 766 767 767 psImage* image2 = psImageTrim(image1,qtrC,qtrR,qtrC+halfC,qtrR+halfR); 768 769 if (image1 != image2) { 770 psLogMsg(__func__,PS_LOG_ERROR, 771 "Return value not same as input value. Not done in-place?"); 772 return 1; 773 } 774 775 if (image2->numCols != halfC || 776 image2->numRows != halfR) { 777 psLogMsg(__func__,PS_LOG_ERROR, 778 "The resulting image size was %dx%d, but should be %dx%d.", 779 image2->numCols, image2->numRows, 780 halfC, halfR); 781 return 2; 782 } 783 784 for (int row = 0; row < image2->numRows; row++) { 785 for (int col = 0; col < image2->numCols; col++) { 786 if (fabsf(image2->data.F32[row][col] - image->data.F32[row+qtrR][col+qtrC]) > FLT_EPSILON) { 787 psLogMsg(__func__,PS_LOG_ERROR, 788 "The value at (%d,%d) was %g, but should be %g.", 789 col,row, 790 image2->data.F32[row][col], 791 image->data.F32[row+qtrR][col+qtrC]); 792 return 3; 793 } 794 } 795 } 796 797 /* 798 2. invoke psImageTrim with non-NULL image and valid region where x1=0, 799 y1=0. Verify that: 800 a. the return psImage size is numCols-x0 by numRows-y0 801 b. the pixel values coorespond to the region 802 [x0:numCols-1,y0:numRows-1]. 803 */ 804 image1 = psImageCopy(image1,image,PS_TYPE_F32); 805 image2 = psImageTrim(image1,qtrC,qtrR,0,0); 806 807 if (image1 != image2) { 808 psLogMsg(__func__,PS_LOG_ERROR, 809 "Return value not same as input value. Not done in-place?"); 810 return 11; 811 } 812 813 if (image2->numCols != image->numCols-qtrC || 814 image2->numRows != image->numRows-qtrR) { 815 psLogMsg(__func__,PS_LOG_ERROR, 816 "The resulting image size was %dx%d, but should be %dx%d.", 817 image2->numCols, image2->numRows, 818 image->numCols-qtrC, image->numRows-qtrR); 819 return 12; 820 } 821 822 for (int row = 0; row < image2->numRows; row++) { 823 for (int col = 0; col < image2->numCols; col++) { 824 if (fabsf(image2->data.F32[row][col] - 825 image->data.F32[row+qtrR][col+qtrC]) > FLT_EPSILON) { 826 psLogMsg(__func__,PS_LOG_ERROR, 827 "The value at (%d,%d) was %g, but should be %g.", 828 col,row, 829 image2->data.F32[row][col], 830 image->data.F32[row+qtrR][col+qtrC]); 831 return 13; 832 } 833 } 834 } 835 836 /* 837 4. invoke psImageTrim with x1<0, y1<0. Verify: 838 a. the psImage size is (numCols+x1)-x0 by (numRows+y1)-y0. 839 b. the pixel values coorespond to the region 840 [x0:numCols+x1-1,y0:numRows+y1-1]. 841 842 */ 843 image1 = psImageCopy(image1,image,PS_TYPE_F32); 844 image2 = psImageTrim(image1,qtrC,qtrR,-qtrC,-qtrR); 845 846 if (image1 != image2) { 847 psLogMsg(__func__,PS_LOG_ERROR, 848 "Return value not same as input value. Not done in-place?"); 849 return 21; 850 } 851 852 if (image2->numCols != image->numCols-qtrC-qtrC || 853 image2->numRows != image->numRows-qtrR-qtrR) { 854 psLogMsg(__func__,PS_LOG_ERROR, 855 "The resulting image size was %dx%d, but should be %dx%d.", 856 image2->numCols, image2->numRows, 857 image->numCols-qtrC, image->numRows-qtrR); 858 return 22; 859 } 860 861 for (int row = 0; row < image2->numRows; row++) { 862 for (int col = 0; col < image2->numCols; col++) { 863 if (fabsf(image2->data.F32[row][col] - 864 image->data.F32[row+qtrR][col+qtrC]) > FLT_EPSILON) { 865 psLogMsg(__func__,PS_LOG_ERROR, 866 "The value at (%d,%d) was %g, but should be %g.", 867 col,row, 868 image2->data.F32[row][col], 869 image->data.F32[row+qtrR][col+qtrC]); 870 return 23; 871 } 872 } 873 } 874 875 psFree(image2); 876 877 /* 878 6. invoke psImageTrim with image=NULL Verify: 879 a. execution does not cease. 880 b. return value is NULL 881 c. appropriate error is generated. 882 */ 883 884 image2 = psImageTrim(NULL,qtrC,qtrR,0,0); 885 886 if (image2 != NULL) { 887 psLogMsg(__func__,PS_LOG_ERROR, 888 "psImageTrim did not return NULL given a NULL input image."); 889 return 31; 890 } 891 psErr* err = psErrorLast(); 892 if (err == NULL || err->code != PS_ERR_BAD_PARAMETER_NULL) { 893 psLogMsg(__func__,PS_LOG_ERROR, 894 "psImageTrim did not generate an appropriate error for NULL input image."); 895 psErrorStackPrint(stderr,"Error Stack:"); 896 return 32; 897 } 898 psFree(err); 899 900 image1 = psImageCopy(NULL,image,PS_TYPE_F32); 901 image2 = psImageTrim(image1,-1,0,0,0); 902 903 if (image2 != NULL) { 904 psLogMsg(__func__,PS_LOG_ERROR, 905 "psImageTrim did not return NULL given x0=-1."); 906 return 33; 907 } 908 err = psErrorLast(); 909 if (err == NULL || err->code != PS_ERR_BAD_PARAMETER_VALUE) { 910 psLogMsg(__func__,PS_LOG_ERROR, 911 "psImageTrim did not generate an appropriate error for x0=-1."); 912 psErrorStackPrint(stderr,"Error Stack:"); 913 return 34; 914 } 915 psFree(err); 916 917 image1 = psImageCopy(NULL,image,PS_TYPE_F32); 918 image2 = psImageTrim(image1,0,-1,0,0); 919 920 if (image2 != NULL) { 921 psLogMsg(__func__,PS_LOG_ERROR, 922 "psImageTrim did not return NULL given y0=-1."); 923 return 35; 924 } 925 err = psErrorLast(); 926 if (err == NULL || err->code != PS_ERR_BAD_PARAMETER_VALUE) { 927 psLogMsg(__func__,PS_LOG_ERROR, 928 "psImageTrim did not generate an appropriate error for y0=-1."); 929 psErrorStackPrint(stderr,"Error Stack:"); 930 return 36; 931 } 932 psFree(err); 933 934 image1 = psImageCopy(NULL,image,PS_TYPE_F32); 935 image2 = psImageTrim(image1,0,0,image->numCols+1,0); 936 937 if (image2 != NULL) { 938 psLogMsg(__func__,PS_LOG_ERROR, 939 "psImageTrim did not return NULL given x1=numCols+1."); 940 return 37; 941 } 942 err = psErrorLast(); 943 if (err == NULL || err->code != PS_ERR_BAD_PARAMETER_VALUE) { 944 psLogMsg(__func__,PS_LOG_ERROR, 945 "psImageTrim did not generate an appropriate error for x1=numCols+1."); 946 psErrorStackPrint(stderr,"Error Stack:"); 947 return 38; 948 } 949 psFree(err); 950 951 image1 = psImageCopy(NULL,image,PS_TYPE_F32); 952 image2 = psImageTrim(image1,0,0,0,image->numRows+1); 953 954 if (image2 != NULL) { 955 psLogMsg(__func__,PS_LOG_ERROR, 956 "psImageTrim did not return NULL given y1=numRows+1."); 957 return 39; 958 } 959 err = psErrorLast(); 960 if (err == NULL || err->code != PS_ERR_BAD_PARAMETER_VALUE) { 961 psLogMsg(__func__,PS_LOG_ERROR, 962 "psImageTrim did not generate an appropriate error for y1=numRows+1."); 963 psErrorStackPrint(stderr,"Error Stack:"); 964 return 40; 965 } 966 psFree(err); 967 968 image1 = psImageCopy(NULL,image,PS_TYPE_F32); 969 image2 = psImageTrim(image1,0,0,-image->numCols,0); 970 971 if (image2 != NULL) { 972 psLogMsg(__func__,PS_LOG_ERROR, 973 "psImageTrim did not return NULL given x1=-numCols."); 974 return 41; 975 } 976 err = psErrorLast(); 977 if (err == NULL || err->code != PS_ERR_BAD_PARAMETER_VALUE) { 978 psLogMsg(__func__,PS_LOG_ERROR, 979 "psImageTrim did not generate an appropriate error for x1=-numCols."); 980 psErrorStackPrint(stderr,"Error Stack:"); 981 return 42; 982 } 983 psFree(err); 984 985 image1 = psImageCopy(NULL,image,PS_TYPE_F32); 986 image2 = psImageTrim(image1,0,0,0,-image->numRows); 987 988 if (image2 != NULL) { 989 psLogMsg(__func__,PS_LOG_ERROR, 990 "psImageTrim did not return NULL given y1=-numRows."); 991 return 41; 992 } 993 err = psErrorLast(); 994 if (err == NULL || err->code != PS_ERR_BAD_PARAMETER_VALUE) { 995 psLogMsg(__func__,PS_LOG_ERROR, 996 "psImageTrim did not generate an appropriate error for y1=-numRows."); 997 psErrorStackPrint(stderr,"Error Stack:"); 998 return 42; 999 } 1000 psFree(err); 1001 1002 psFree(image); 768 1003 return 0; 769 1004 }
Note:
See TracChangeset
for help on using the changeset viewer.
