Changeset 2087
- Timestamp:
- Oct 13, 2004, 12:04:29 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/image/tst_psImageExtraction.c (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/image/tst_psImageExtraction.c
r2079 r2087 6 6 * @author Robert DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1.1 4$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-10-13 2 0:27:36$8 * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-10-13 22:04:29 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 22 22 static int testImageSubsection(void); 23 23 static int testImageTrim(void); 24 static int testImageCut(void); 25 static int testImageRadialCut(void); 24 26 25 27 … … 30 32 {testImageSlice, 552, "psImageSlice", 0, false}, 31 33 {testImageTrim, 744, "psImageTrim", 0, false}, 34 {testImageCut, 555, "psImageCut", 0, false}, 35 {testImageRadialCut, 557, "psImageRadialCut", 0, false}, 32 36 {NULL} 33 37 }; … … 45 49 const int n = r / 4 -1; 46 50 psVector* out = NULL; 47 psImage* image = psImageAlloc( c, r, PS_TYPE_F32 ); 48 psImage* imgU8 = psImageAlloc( c, r, PS_TYPE_U8 ); 51 psImage* image; 49 52 psVector* positions = psVectorAlloc( r, PS_TYPE_U32 ); 50 53 psImage* mask = psImageAlloc( c, r, PS_TYPE_MASK ); 51 psImage* maskS8 = psImageAlloc( c, r, PS_TYPE_S8 );52 psImage* maskSz = psImageAlloc( r, c, PS_TYPE_MASK );53 54 psStats* stat = psStatsAlloc( PS_STAT_SAMPLE_MEDIAN ); 54 55 … … 68 69 69 70 for ( int row = 0;row < r;row++ ) { 70 psF32* imageRow = image->data.F32[ row ]; 71 psU8* imgU8Row = imgU8->data.U8[ row ]; 72 psMaskType* maskRow = mask->data.V[ row ]; 73 psMaskType* maskSzRow = maskSz->data.V[ row ]; 74 psS8* maskS8Row = maskS8->data.V[ row ]; 75 psF32 rowOffset = ( psF32 ) row / ( psF32 ) r; 71 psMaskType* maskRow = mask->data.PS_TYPE_MASK_DATA[row]; 76 72 for ( int col = 0;col < c;col++ ) { 77 imageRow[ col ] = ( psF32 ) col + rowOffset;78 imgU8Row[ col ] = (psU8) col;79 73 maskRow[ col ] = 0; 80 maskS8Row[ col ] = 0; 81 maskSzRow[ col ] = 0; 82 } 83 } 84 85 #define PSIMAGESLICE_TEST1(M,N,DIRECTION,TRUTH_SIZE,TRUTHPIX_X,TRUTHPIX_Y,TESTNUM) \ 74 } 75 } 76 77 #define PSIMAGESLICE_TEST1(TYPE,M,N,DIRECTION,TRUTH_SIZE,TRUTHPIX_X,TRUTHPIX_Y,TESTNUM) \ 78 image = psImageAlloc( c, r, PS_TYPE_##TYPE ); \ 79 for ( int row = 0;row < r;row++ ) { \ 80 ps##TYPE *imageRow = image->data.TYPE[ row ]; \ 81 ps##TYPE rowOffset = row * 2; \ 82 for ( int col = 0;col < c;col++ ) { \ 83 imageRow[ col ] = col + rowOffset; \ 84 } \ 85 } \ 86 86 out = psImageSlice(out,positions,image,mask,1,c/10,r/10,c/10+M,r/10+N,DIRECTION,stat); \ 87 87 \ … … 117 117 } \ 118 118 } \ 119 } 119 } \ 120 psFree(image); 120 121 121 122 // test MxN case 122 PSIMAGESLICE_TEST1( m, n, PS_CUT_X_POS, m, i, n / 2, 0 );123 PSIMAGESLICE_TEST1( m, n, PS_CUT_X_NEG, m, m - 1 - i, n / 2, 1 );124 PSIMAGESLICE_TEST1( m, n, PS_CUT_Y_POS, n, m / 2, i, 2 );125 PSIMAGESLICE_TEST1( m, n, PS_CUT_Y_NEG, n, m / 2, n - 1 - i, 3 );123 PSIMAGESLICE_TEST1(F32, m, n, PS_CUT_X_POS, m, i, n / 2, 0 ); 124 PSIMAGESLICE_TEST1(F32, m, n, PS_CUT_X_NEG, m, m - 1 - i, n / 2, 1 ); 125 PSIMAGESLICE_TEST1(F32, m, n, PS_CUT_Y_POS, n, m / 2, i, 2 ); 126 PSIMAGESLICE_TEST1(F32, m, n, PS_CUT_Y_NEG, n, m / 2, n - 1 - i, 3 ); 126 127 127 128 // test Mx1 case 128 PSIMAGESLICE_TEST1( m, 1, PS_CUT_X_POS, m, i, 0, 4 );129 PSIMAGESLICE_TEST1( m, 1, PS_CUT_X_NEG, m, m - 1 - i, 0, 5 );130 PSIMAGESLICE_TEST1( m, 1, PS_CUT_Y_POS, 1, m / 2, 0, 6 );131 PSIMAGESLICE_TEST1( m, 1, PS_CUT_Y_NEG, 1, m / 2, 0, 7 );129 PSIMAGESLICE_TEST1(F32, m, 1, PS_CUT_X_POS, m, i, 0, 4 ); 130 PSIMAGESLICE_TEST1(F32, m, 1, PS_CUT_X_NEG, m, m - 1 - i, 0, 5 ); 131 PSIMAGESLICE_TEST1(F32, m, 1, PS_CUT_Y_POS, 1, m / 2, 0, 6 ); 132 PSIMAGESLICE_TEST1(F32, m, 1, PS_CUT_Y_NEG, 1, m / 2, 0, 7 ); 132 133 133 134 // test 1xN case 134 PSIMAGESLICE_TEST1( 1, n, PS_CUT_X_POS, 1, 0, n / 2, 8 );135 PSIMAGESLICE_TEST1( 1, n, PS_CUT_X_NEG, 1, 0, n / 2, 9 );136 PSIMAGESLICE_TEST1( 1, n, PS_CUT_Y_POS, n, 0, i, 10 );137 PSIMAGESLICE_TEST1( 1, n, PS_CUT_Y_NEG, n, 0, n - 1 - i, 11 );135 PSIMAGESLICE_TEST1(F32, 1, n, PS_CUT_X_POS, 1, 0, n / 2, 8 ); 136 PSIMAGESLICE_TEST1(F32, 1, n, PS_CUT_X_NEG, 1, 0, n / 2, 9 ); 137 PSIMAGESLICE_TEST1(F32, 1, n, PS_CUT_Y_POS, n, 0, i, 10 ); 138 PSIMAGESLICE_TEST1(F32, 1, n, PS_CUT_Y_NEG, n, 0, n - 1 - i, 11 ); 138 139 139 140 // test 1x1 case 140 PSIMAGESLICE_TEST1( 1, 1, PS_CUT_X_POS, 1, 0, 0, 12 );141 PSIMAGESLICE_TEST1( 1, 1, PS_CUT_X_NEG, 1, 0, 0, 13 );142 PSIMAGESLICE_TEST1( 1, 1, PS_CUT_Y_POS, 1, 0, 0, 14 );143 PSIMAGESLICE_TEST1( 1, 1, PS_CUT_Y_NEG, 1, 0, 0, 15 );141 PSIMAGESLICE_TEST1(F32, 1, 1, PS_CUT_X_POS, 1, 0, 0, 12 ); 142 PSIMAGESLICE_TEST1(F32, 1, 1, PS_CUT_X_NEG, 1, 0, 0, 13 ); 143 PSIMAGESLICE_TEST1(F32, 1, 1, PS_CUT_Y_POS, 1, 0, 0, 14 ); 144 PSIMAGESLICE_TEST1(F32, 1, 1, PS_CUT_Y_NEG, 1, 0, 0, 15 ); 144 145 145 146 /* … … 298 299 psLogMsg( __func__, PS_LOG_INFO, "Following should be an error mask size != image size."); 299 300 stat->options = PS_STAT_SAMPLE_MEDIAN; 301 psImage* maskSz = psImageAlloc( r, c, PS_TYPE_MASK ); 300 302 out = psImageSlice( out, NULL, 301 303 image, … … 313 315 */ 314 316 psLogMsg( __func__, PS_LOG_INFO, "Following should be an error invalid mask type."); 317 psImage* maskS8 = psImageAlloc( c, r, PS_TYPE_S8 ); 315 318 out = psImageSlice( out, NULL, 316 319 image, … … 327 330 /* Verify the input image is an invalid type */ 328 331 psLogMsg( __func__, PS_LOG_INFO, "Following should be an error invalid image type."); 332 psImage* imgU8 = psImageAlloc( c, r, PS_TYPE_U8 ); 329 333 out = psImageSlice( out, NULL, 330 334 imgU8, … … 881 885 c. appropriate error is generated. 882 886 */ 883 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error for NULL image."); 887 884 888 image2 = psImageTrim(NULL,qtrC,qtrR,0,0); 885 889 … … 899 903 900 904 image1 = psImageCopy(NULL,image,PS_TYPE_F32); 901 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error for trim outside.");902 905 image2 = psImageTrim(image1,-1,0,0,0); 903 906 … … 917 920 918 921 image1 = psImageCopy(NULL,image,PS_TYPE_F32); 919 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error for trim outside.");920 922 image2 = psImageTrim(image1,0,-1,0,0); 921 923 … … 935 937 936 938 image1 = psImageCopy(NULL,image,PS_TYPE_F32); 937 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error for trim outside.");938 939 image2 = psImageTrim(image1,0,0,image->numCols+1,0); 939 940 … … 953 954 954 955 image1 = psImageCopy(NULL,image,PS_TYPE_F32); 955 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error for trim outside.");956 956 image2 = psImageTrim(image1,0,0,0,image->numRows+1); 957 957 … … 971 971 972 972 image1 = psImageCopy(NULL,image,PS_TYPE_F32); 973 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error for trim outside.");974 973 image2 = psImageTrim(image1,0,0,-image->numCols,0); 975 974 … … 989 988 990 989 image1 = psImageCopy(NULL,image,PS_TYPE_F32); 991 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error for trim outside.");992 990 image2 = psImageTrim(image1,0,0,0,-image->numRows); 993 991 … … 1009 1007 return 0; 1010 1008 } 1009 1010 static int testImageCut(void) 1011 { 1012 // XXX - fill in 1013 int c = 300; 1014 int r = 200; 1015 int numPoints = 15; 1016 float startCol[] = { 40,150, 40, 0,280, 40,280, -1,300, 20, 20, 20, 20, 20, 20}; 1017 float endCol[] = {240,150,240,299, 40,240, 40,240,240, -1,300,240,240,240,240}; 1018 float startRow[] = { 20, 10,100, 0, 20,180,180, 10, 10, 10, 10, -1,200, 10, 10}; 1019 float endRow[] = {160,180,100,199,160, 10, 10,180,180,180,180,180,180, -1,200}; 1020 bool success[] = {true,true,true,true,true,true,true,false,false,false,false,false,false,false,false}; 1021 unsigned int length = 100; 1022 1023 psImage* image = psImageAlloc(c,r,PS_TYPE_F32); 1024 psImage* mask = psImageAlloc(c,r,PS_TYPE_MASK); 1025 for (int row = 0; row < image->numRows; row++) { 1026 for (int col = 0; col < image->numCols; col++) { 1027 image->data.F32[row][col] = (psF32)col + (psF32)row/1000.0f; 1028 if ((row & 0x0F) == 0) { 1029 mask->data.PS_TYPE_MASK_DATA[row][col] = 1; 1030 } else { 1031 mask->data.PS_TYPE_MASK_DATA[row][col] = 0; 1032 } 1033 } 1034 } 1035 psVector* rows = psVectorAlloc(length,PS_TYPE_F32); 1036 psVector* cols = psVectorAlloc(length,PS_TYPE_F32); 1037 1038 psVector* result = NULL; 1039 for (int n = 0; n < numPoints; n++) { 1040 psVector* orig = result; 1041 if (! success[n]) { 1042 psLogMsg(__func__,PS_LOG_INFO,"The following should be an error."); 1043 } 1044 if (n == 1) { 1045 result = psImageCut(result, 1046 cols,rows, 1047 image, 1048 NULL,0, 1049 startCol[n], startRow[n], 1050 endCol[n], endRow[n], 1051 length, 1052 PS_INTERPOLATE_FLAT); 1053 } else { 1054 result = psImageCut(result, 1055 cols,rows, 1056 image, 1057 mask,1, 1058 startCol[n], startRow[n], 1059 endCol[n], endRow[n], 1060 length, 1061 PS_INTERPOLATE_FLAT); 1062 } 1063 1064 if (success[n]) { 1065 if (result == NULL) { 1066 psLogMsg(__func__,PS_LOG_ERROR, 1067 "psImageCut returned NULL instead of a valid result."); 1068 return n*10+1; 1069 } 1070 1071 if (orig != NULL && orig != result) { 1072 psLogMsg(__func__,PS_LOG_ERROR, 1073 "psImageCut didn't recycle the out parameter properly."); 1074 return n*10+2; 1075 } 1076 1077 float deltaRow = (endRow[n]-startRow[n])/(length-1); 1078 float deltaCol = (endCol[n]-startCol[n])/(length-1); 1079 psF32 truth; 1080 for (int i = 0; i < length; i++) { 1081 float x = (float)startCol[n]+(float)i*deltaCol; 1082 float y = (float)startRow[n]+(float)i*deltaRow; 1083 if (n == 1) { 1084 truth = psImagePixelInterpolate( image, x, y, 1085 NULL,0,0,PS_INTERPOLATE_FLAT); 1086 } else { 1087 truth = psImagePixelInterpolate( image, x, y, 1088 mask,1,0,PS_INTERPOLATE_FLAT); 1089 } 1090 if (fabs(result->data.F32[i]-truth) > FLT_EPSILON) { 1091 psLogMsg(__func__,PS_LOG_ERROR, 1092 "Bad result in position %d; Found %g but expected %g.", 1093 i, result->data.F32[i], truth); 1094 return n*10+5; 1095 } 1096 if (fabsf(x - cols->data.F32[i]) > FLT_EPSILON || 1097 fabsf(y - rows->data.F32[i]) > FLT_EPSILON) { 1098 psLogMsg(__func__,PS_LOG_ERROR, 1099 "Bad resulting col/row at index %d; Found (%g,%g) but expected (%g,%g).", 1100 i, cols->data.F32[i], rows->data.F32[i], x, y); 1101 return n*10+6; 1102 } 1103 } 1104 } else { 1105 if (result != NULL) { 1106 psLogMsg(__func__,PS_LOG_ERROR, 1107 "psImageCut did not return NULL with a cut of (%g,%g)->(%g,%g).", 1108 startCol[n],startRow[n],endCol[n],endRow[n]); 1109 return n*10+7; 1110 } 1111 psErr* err = psErrorLast(); 1112 if (err->code != PS_ERR_BAD_PARAMETER_VALUE) { 1113 psLogMsg(__func__,PS_LOG_ERROR, 1114 "psImageCut did not generate proper error message."); 1115 return 105; 1116 } 1117 psFree(err); 1118 } 1119 } 1120 1121 psLogMsg(__func__,PS_LOG_INFO,"Following should be an error (NULL image)."); 1122 result = psImageCut(result, 1123 cols,rows, 1124 NULL, 1125 mask,1, 1126 startCol[0], startRow[0], 1127 endCol[0], endRow[0], 1128 length, 1129 PS_INTERPOLATE_FLAT); 1130 if (result != NULL) { 1131 psLogMsg(__func__,PS_LOG_ERROR, 1132 "psImageCut did not return NULL given NULL image."); 1133 return 100; 1134 } 1135 psErr* err = psErrorLast(); 1136 if (err->code != PS_ERR_BAD_PARAMETER_NULL) { 1137 psLogMsg(__func__,PS_LOG_ERROR, 1138 "psImageCut did not generate proper error message given NULL image."); 1139 return 101; 1140 } 1141 psFree(err); 1142 1143 psLogMsg(__func__,PS_LOG_INFO,"Following should be an error (length=0)."); 1144 result = psImageCut(result, 1145 cols,rows, 1146 image, 1147 mask,1, 1148 startCol[0], startRow[0], 1149 endCol[0], endRow[0], 1150 0, 1151 PS_INTERPOLATE_FLAT); 1152 if (result != NULL) { 1153 psLogMsg(__func__,PS_LOG_ERROR, 1154 "psImageCut did not return NULL given length=0."); 1155 return 102; 1156 } 1157 err = psErrorLast(); 1158 if (err->code != PS_ERR_BAD_PARAMETER_VALUE) { 1159 psLogMsg(__func__,PS_LOG_ERROR, 1160 "psImageCut did not generate proper error message given length=0."); 1161 return 103; 1162 } 1163 psFree(err); 1164 1165 psFree(result); 1166 psFree(image); 1167 psFree(mask); 1168 psFree(rows); 1169 psFree(cols); 1170 1171 return 0; 1172 } 1173 1174 static int testImageRadialCut(void) 1175 { 1176 // XXX - fill in 1177 1178 return 0; 1179 }
Note:
See TracChangeset
for help on using the changeset viewer.
