Changeset 2204 for trunk/psLib/test/image/tst_psImageManip.c
- Timestamp:
- Oct 26, 2004, 2:57:34 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/image/tst_psImageManip.c (modified) (46 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/image/tst_psImageManip.c
r2105 r2204 6 6 * @author Robert DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1. 29$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-10- 14 01:22:59$8 * @version $Revision: 1.30 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-10-27 00:57:33 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 25 25 #include "psType.h" 26 26 27 static inttestImageClip(void);28 static inttestImageClipNAN(void);29 static inttestImageClipComplexRegion(void);30 static inttestImageOverlay(void);31 static inttestImageRebin(void);32 static inttestImageRoll(void);33 static inttestImageRotate(void);34 static inttestImageShift(void);35 static int testImageShiftCase(int cols, introws, float colShift,float rowShift);36 static inttestImageResample(void);27 static psS32 testImageClip(void); 28 static psS32 testImageClipNAN(void); 29 static psS32 testImageClipComplexRegion(void); 30 static psS32 testImageOverlay(void); 31 static psS32 testImageRebin(void); 32 static psS32 testImageRoll(void); 33 static psS32 testImageRotate(void); 34 static psS32 testImageShift(void); 35 static psS32 testImageShiftCase(psS32 cols, psS32 rows, float colShift,float rowShift); 36 static psS32 testImageResample(void); 37 37 38 38 testDescription tests[] = { … … 49 49 }; 50 50 51 int main(intargc, char* argv[])51 psS32 main(psS32 argc, char* argv[]) 52 52 { 53 53 psLogSetLevel(PS_LOG_INFO); … … 57 57 58 58 59 inttestImageClip(void)59 psS32 testImageClip(void) 60 60 { 61 61 psImage* img = NULL; 62 unsigned intc = 128;63 unsigned intr = 256;62 psU32 c = 128; 63 psU32 r = 256; 64 64 psF64 min; 65 65 psF64 max; 66 intnumClipped = 0;67 intretVal;66 psS32 numClipped = 0; 67 psS32 retVal; 68 68 69 69 psLogMsg(__func__,PS_LOG_INFO, … … 95 95 #define testImageClipByType(datatype) \ 96 96 img = psImageAlloc(c,r,PS_TYPE_##datatype); \ 97 for ( unsigned introw=0;row<r;row++) { \97 for (psU32 row=0;row<r;row++) { \ 98 98 ps##datatype* imgRow = img->data.datatype[row]; \ 99 for ( unsigned intcol=0;col<c;col++) { \99 for (psU32 col=0;col<c;col++) { \ 100 100 imgRow[col] = (ps##datatype)(row+col); \ 101 101 } \ … … 107 107 \ 108 108 numClipped = 0; \ 109 for ( unsigned introw=0;row<r;row++) { \109 for (psU32 row=0;row<r;row++) { \ 110 110 ps##datatype* imgRow = img->data.datatype[row]; \ 111 for ( unsigned intcol=0;col<c;col++) { \111 for (psU32 col=0;col<c;col++) { \ 112 112 ps##datatype value = (ps##datatype)(row+col); \ 113 113 if (value < min) { \ … … 134 134 #define testImageClipByComplexType(datatype) \ 135 135 img = psImageAlloc(c,r,PS_TYPE_##datatype); \ 136 for ( unsigned introw=0;row<r;row++) { \136 for (psU32 row=0;row<r;row++) { \ 137 137 ps##datatype* imgRow = img->data.datatype[row]; \ 138 for ( unsigned intcol=0;col<c;col++) { \138 for (psU32 col=0;col<c;col++) { \ 139 139 imgRow[col] = (ps##datatype)(row+I*col); \ 140 140 } \ … … 146 146 \ 147 147 numClipped = 0; \ 148 for ( unsigned introw=0;row<r;row++) { \148 for (psU32 row=0;row<r;row++) { \ 149 149 ps##datatype* imgRow = img->data.datatype[row]; \ 150 for ( unsigned intcol=0;col<c;col++) { \150 for (psU32 col=0;col<c;col++) { \ 151 151 ps##datatype value = row+I*col; \ 152 152 if (cabs(value) < min) { \ … … 225 225 } 226 226 227 inttestImageClipNAN(void)227 psS32 testImageClipNAN(void) 228 228 { 229 229 psImage* img = NULL; 230 unsigned intc = 128;231 unsigned intr = 256;232 intnumClipped = 0;233 intretVal;230 psU32 c = 128; 231 psU32 r = 256; 232 psS32 numClipped = 0; 233 psS32 retVal; 234 234 235 235 psLogMsg(__func__,PS_LOG_INFO, … … 317 317 } 318 318 319 inttestImageClipComplexRegion(void)319 psS32 testImageClipComplexRegion(void) 320 320 { 321 321 psImage* img = NULL; 322 unsigned intc = 1024;323 unsigned intr = 2048;324 intnumClipped = 0;325 intretVal;322 psU32 c = 1024; 323 psU32 r = 2048; 324 psS32 numClipped = 0; 325 psS32 retVal; 326 326 327 327 psLogMsg(__func__,PS_LOG_INFO, … … 581 581 } 582 582 583 inttestImageOverlay(void)583 psS32 testImageOverlay(void) 584 584 { 585 585 … … 588 588 psImage* img3 = NULL; 589 589 psImage* img4 = NULL; 590 unsigned intc = 128;591 unsigned intr = 256;592 intretVal;590 psU32 c = 128; 591 psU32 r = 256; 592 psS32 retVal; 593 593 594 594 /* … … 833 833 } 834 834 835 static inttestImageRebin(void)835 static psS32 testImageRebin(void) 836 836 { 837 837 … … 869 869 memset(meanTruthWMask->data.F32[0],0,sizeof(psF32)*4*4); \ 870 870 memset(maxTruth->data.F32[0],0,sizeof(psF32)*6*6); \ 871 for ( introw = 0; row<16; row++) { \871 for (psS32 row = 0; row<16; row++) { \ 872 872 ps##DATATYPE* inRow = in->data.DATATYPE[row]; \ 873 873 psF32* meanTruthRow = meanTruth->data.F32[row/4]; \ … … 875 875 psF32* maxTruthRow = maxTruth->data.F32[row/3]; \ 876 876 psU8* maskRow = mask->data.U8[row]; \ 877 for ( intcol = 0; col<16; col++) { \877 for (psS32 col = 0; col<16; col++) { \ 878 878 if(col != 15) { \ 879 879 maskRow[col] = 0; \ … … 891 891 } \ 892 892 } \ 893 for ( introw = 0; row<4; row++) { \893 for (psS32 row = 0; row<4; row++) { \ 894 894 psF32* meanTruthRow = meanTruth->data.F32[row]; \ 895 895 psF32* meanTruthWMaskRow = meanTruthWMask->data.F32[row]; \ 896 for ( intcol = 0; col<4; col++) { \896 for (psS32 col = 0; col<4; col++) { \ 897 897 meanTruthRow[col] /= 16; \ 898 898 if ( col == 3 ) { \ … … 915 915 return 2; \ 916 916 } \ 917 for ( introw = 0; row<4; row++) { \917 for (psS32 row = 0; row<4; row++) { \ 918 918 ps##DATATYPE* outRow = out->data.DATATYPE[row]; \ 919 919 psF32* truthRow = meanTruth->data.F32[row]; \ 920 for ( intcol = 0; col<4; col++) { \920 for (psS32 col = 0; col<4; col++) { \ 921 921 if (fabsf((float)outRow[col]-(float)truthRow[col]) > FLT_EPSILON) { \ 922 922 psError(__func__,"psImageRebin didn't produce the proper mean " \ … … 929 929 stats.options = PS_STAT_SAMPLE_MEAN; \ 930 930 out3 = psImageRebin(NULL,in,mask,1,4,&stats); \ 931 for ( introw = 0; row<4; row++) { \931 for (psS32 row = 0; row<4; row++) { \ 932 932 ps##DATATYPE* outRow = out3->data.DATATYPE[row]; \ 933 933 psF32* truthRow = meanTruthWMask->data.F32[row]; \ 934 for ( intcol = 0; col<4; col++) { \935 if(abs(( int)outRow[col]-(int)truthRow[col]) > FLT_EPSILON) { \934 for ( psS32 col = 0; col<4; col++) { \ 935 if(abs((psS32)outRow[col]-(psS32)truthRow[col]) > FLT_EPSILON) { \ 936 936 psError(__func__,"psImageRebin with mask didn't produce the proper mean " \ 937 937 "result at (%d,%d) [%f vs %f].", \ … … 957 957 return 5; \ 958 958 } \ 959 for ( introw = 0; row<6; row++) { \959 for (psS32 row = 0; row<6; row++) { \ 960 960 ps##DATATYPE* outRow = out->data.DATATYPE[row]; \ 961 961 psF32* truthRow = maxTruth->data.F32[row]; \ 962 for ( intcol = 0; col<6; col++) { \962 for (psS32 col = 0; col<6; col++) { \ 963 963 if (fabsf((float)outRow[col]-(float)truthRow[col]) > FLT_EPSILON) { \ 964 964 psError(__func__,"psImageRebin didn't produce the proper " \ … … 1082 1082 } 1083 1083 1084 static inttestImageRoll(void)1084 static psS32 testImageRoll(void) 1085 1085 { 1086 1086 … … 1088 1088 psImage* out; 1089 1089 psImage* out2; 1090 introws = 64;1091 intcols = 64;1092 introws1 = 8;1093 intcols1 = 8;1090 psS32 rows = 64; 1091 psS32 cols = 64; 1092 psS32 rows1 = 8; 1093 psS32 cols1 = 8; 1094 1094 1095 1095 /* … … 1108 1108 1109 1109 in = psImageAlloc(cols,rows,PS_TYPE_F32); 1110 for ( introw=0;row<rows;row++) {1110 for (psS32 row=0;row<rows;row++) { 1111 1111 psF32* inRow = in->data.F32[row]; 1112 for ( intcol=0;col<cols;col++) {1112 for (psS32 col=0;col<cols;col++) { 1113 1113 inRow[col] = (psF32)row+(psF32)col/1000.0f; 1114 1114 } … … 1116 1116 1117 1117 out = psImageRoll(NULL,in,0,0); 1118 for ( introw=0;row<rows;row++) {1118 for (psS32 row=0;row<rows;row++) { 1119 1119 psF32* inRow = in->data.F32[row]; 1120 1120 psF32* outRow = out->data.F32[row]; 1121 for ( intcol=0;col<cols;col++) {1121 for (psS32 col=0;col<cols;col++) { 1122 1122 if (inRow[col] != outRow[col]) { 1123 1123 psError(__func__,"psImageRoll didn't produce expected result " … … 1130 1130 1131 1131 out2 = psImageRoll(out,in,cols/4,0); 1132 for ( introw=0;row<rows;row++) {1132 for (psS32 row=0;row<rows;row++) { 1133 1133 psF32* inRow = in->data.F32[row]; 1134 1134 psF32* outRow = out->data.F32[row]; 1135 for ( intcol=0;col<cols;col++) {1135 for (psS32 col=0;col<cols;col++) { 1136 1136 if (inRow[(col+cols/4) % cols] != outRow[col]) { 1137 1137 psError(__func__,"psImageRoll didn't produce expected result " … … 1151 1151 1152 1152 out = psImageRoll(out,in,0,rows/4); 1153 for ( introw=0;row<rows;row++) {1153 for (psS32 row=0;row<rows;row++) { 1154 1154 psF32* inRow = in->data.F32[(row+rows/4)%rows]; 1155 1155 psF32* outRow = out->data.F32[row]; 1156 for ( intcol=0;col<cols;col++) {1156 for (psS32 col=0;col<cols;col++) { 1157 1157 if (inRow[col] != outRow[col]) { 1158 1158 psError(__func__,"psImageRoll didn't produce expected result " … … 1165 1165 1166 1166 out = psImageRoll(out,in,cols/4,rows/4); 1167 for ( introw=0;row<rows;row++) {1167 for (psS32 row=0;row<rows;row++) { 1168 1168 psF32* inRow = in->data.F32[(row+rows/4)%rows]; 1169 1169 psF32* outRow = out->data.F32[row]; 1170 for ( intcol=0;col<cols;col++) {1170 for (psS32 col=0;col<cols;col++) { 1171 1171 if (inRow[(col+cols/4) % cols] != outRow[col]) { 1172 1172 psError(__func__,"psImageRoll didn't produce expected result " … … 1179 1179 1180 1180 out = psImageRoll(out,in,-cols/4,0); 1181 for ( introw=0;row<rows;row++) {1181 for (psS32 row=0;row<rows;row++) { 1182 1182 psF32* inRow = in->data.F32[row]; 1183 1183 psF32* outRow = out->data.F32[row]; 1184 for ( intcol=0;col<cols;col++) {1184 for (psS32 col=0;col<cols;col++) { 1185 1185 if (inRow[(col+(cols-cols/4)) % cols] != outRow[col]) { 1186 1186 psError(__func__,"psImageRoll didn't produce expected result " … … 1193 1193 1194 1194 out = psImageRoll(out,in,0,-rows/4); 1195 for ( introw=0;row<rows;row++) {1195 for (psS32 row=0;row<rows;row++) { 1196 1196 psF32* inRow = in->data.F32[(row+rows-rows/4)%rows]; 1197 1197 psF32* outRow = out->data.F32[row]; 1198 for ( intcol=0;col<cols;col++) {1198 for (psS32 col=0;col<cols;col++) { 1199 1199 if (inRow[col] != outRow[col]) { 1200 1200 psError(__func__,"psImageRoll didn't produce expected result " … … 1207 1207 1208 1208 out = psImageRoll(out,in,-cols/4,-rows/4); 1209 for ( introw=0;row<rows;row++) {1209 for (psS32 row=0;row<rows;row++) { 1210 1210 psF32* inRow = in->data.F32[(row+rows-rows/4)%rows]; 1211 1211 psF32* outRow = out->data.F32[row]; 1212 for ( intcol=0;col<cols;col++) {1212 for (psS32 col=0;col<cols;col++) { 1213 1213 if (inRow[(col+cols-cols/4) % cols] != outRow[col]) { 1214 1214 psError(__func__,"psImageRoll didn't produce expected result " … … 1236 1236 in = psImageAlloc(rows1,cols1,PS_TYPE_##DATATYPE); \ 1237 1237 \ 1238 for ( introw=0;row<rows1;row++) { \1238 for (psS32 row=0;row<rows1;row++) { \ 1239 1239 ps##DATATYPE* inRow = in->data.DATATYPE[row]; \ 1240 for ( intcol=0;col<cols1;col++) { \1240 for (psS32 col=0;col<cols1;col++) { \ 1241 1241 inRow[col] = (ps##DATATYPE)row+(ps##DATATYPE)col; \ 1242 1242 } \ … … 1244 1244 \ 1245 1245 out = psImageRoll(NULL,in,rows1/4,cols1/4); \ 1246 for ( introw=0;row<rows1;row++) { \1246 for (psS32 row=0;row<rows1;row++) { \ 1247 1247 ps##DATATYPE* inRow = in->data.DATATYPE[(row+rows1/4)%rows1]; \ 1248 1248 ps##DATATYPE* outRow = out->data.DATATYPE[row]; \ 1249 for ( intcol=0;col<cols1;col++) { \1249 for (psS32 col=0;col<cols1;col++) { \ 1250 1250 if (inRow[(col+cols1/4)%cols1] != outRow[col]) { \ 1251 1251 psError(__func__,"psImageRoll didn't produce expected result " \ … … 1270 1270 } 1271 1271 1272 inttestImageRotate(void)1272 psS32 testImageRotate(void) 1273 1273 { 1274 1274 /* … … 1300 1300 psImage* fBiTruth = NULL; 1301 1301 psImage* sBiTruth = NULL; 1302 introws = 64;1303 intcols = 64;1302 psS32 rows = 64; 1303 psS32 cols = 64; 1304 1304 psImage* fImg = psImageAlloc(cols,rows,PS_TYPE_F32); 1305 1305 psImage* sImg = psImageAlloc(cols,rows,PS_TYPE_S16); 1306 1306 psImage* s32Img = psImageAlloc(cols,rows,PS_TYPE_S32); 1307 1307 1308 for( introw=0;row<rows;row++) {1308 for(psS32 row=0;row<rows;row++) { 1309 1309 psF32* fRow = fImg->data.F32[row]; 1310 1310 psS16* sRow = sImg->data.S16[row]; 1311 1311 psS32* s32Row = s32Img->data.S32[row]; 1312 for ( intcol=0;col<cols;col++) {1312 for (psS32 col=0;col<cols;col++) { 1313 1313 fRow[col] = (psF32)(row)+(psF32)(col)/100.0f; 1314 1314 sRow[col] = row-2*col; … … 1336 1336 ("temp/sBiOut.fits"); 1337 1337 ; 1338 intindex = 0;1339 bool fail = false;1340 for ( introt=-180;rot<=180;rot+=45) {1338 psS32 index = 0; 1339 psBool fail = false; 1340 for (psS32 rot=-180;rot<=180;rot+=45) { 1341 1341 psImage* oldOut = fOut; 1342 1342 psImage* oldBiOut = fBiOut; … … 1388 1388 fail = true; 1389 1389 } else { 1390 for ( introw=0;row<fTruth->numRows;row++) {1390 for (psS32 row=0;row<fTruth->numRows;row++) { 1391 1391 psF32* truthRow = fTruth->data.F32[row]; 1392 1392 psF32* outRow = fOut->data.F32[row]; 1393 for ( intcol=0;col<fTruth->numCols;col++) {1393 for (psS32 col=0;col<fTruth->numCols;col++) { 1394 1394 if (fabsf(truthRow[col]-outRow[col]) > 1) { 1395 1395 psError(__func__,"Float Image mismatch (%f vs %f) at %d,%d.", … … 1409 1409 if (sTruth->numRows != sOut->numRows || 1410 1410 sTruth->numCols != sOut->numCols) { 1411 psError(__func__,"Rotated shortimage size did not match truth "1411 psError(__func__,"Rotated psS16 image size did not match truth " 1412 1412 "image for %d deg rotation.",rot); 1413 1413 fail = true; 1414 1414 } else { 1415 for ( introw=0;row<sTruth->numRows;row++) {1415 for (psS32 row=0;row<sTruth->numRows;row++) { 1416 1416 psS16* truthRow = sTruth->data.S16[row]; 1417 1417 psS16* outRow = sOut->data.S16[row]; 1418 for ( intcol=0;col<sTruth->numCols;col++) {1418 for (psS32 col=0;col<sTruth->numCols;col++) { 1419 1419 if (fabsf(truthRow[col]-outRow[col]) > 1) { 1420 1420 psError(__func__,"Short Image mismatch (%d vs %d) " … … 1440 1440 fail = true; 1441 1441 } else { 1442 for ( introw=0;row<fBiTruth->numRows;row++) {1442 for (psS32 row=0;row<fBiTruth->numRows;row++) { 1443 1443 psF32* truthRow = fBiTruth->data.F32[row]; 1444 1444 psF32* outRow = fBiOut->data.F32[row]; 1445 for ( intcol=0;col<fBiTruth->numCols;col++) {1445 for (psS32 col=0;col<fBiTruth->numCols;col++) { 1446 1446 if (fabsf(truthRow[col]-outRow[col]) > 1) { 1447 1447 psError(__func__,"Float Image mismatch (%f vs %f) at %d,%d. BILINEAR", … … 1461 1461 if (sBiTruth->numRows != sBiOut->numRows || 1462 1462 sBiTruth->numCols != sBiOut->numCols) { 1463 psError(__func__,"Rotated shortimage size did not match truth "1463 psError(__func__,"Rotated psS16 image size did not match truth " 1464 1464 "image for %d deg rotation. BILINEAR",rot); 1465 1465 fail = true; 1466 1466 } else { 1467 for ( introw=0;row<sBiTruth->numRows;row++) {1467 for (psS32 row=0;row<sBiTruth->numRows;row++) { 1468 1468 psS16* truthRow = sBiTruth->data.S16[row]; 1469 1469 psS16* outRow = sBiOut->data.S16[row]; 1470 for ( intcol=0;col<sBiTruth->numCols;col++) {1470 for (psS32 col=0;col<sBiTruth->numCols;col++) { 1471 1471 if (fabsf(truthRow[col]-outRow[col]) > 1) { 1472 1472 psError(__func__,"Short Image mismatch (%d vs %d) " … … 1537 1537 } 1538 1538 1539 static inttestImageShift(void)1539 static psS32 testImageShift(void) 1540 1540 { 1541 1541 /* psImageShift: … … 1558 1558 */ 1559 1559 1560 intretVal=0;1560 psS32 retVal=0; 1561 1561 1562 1562 // integer shift … … 1627 1627 } 1628 1628 1629 static int testImageShiftCase(intcols,1630 introws,1631 float colShift,1632 float rowShift)1629 static psS32 testImageShiftCase(psS32 cols, 1630 psS32 rows, 1631 float colShift, 1632 float rowShift) 1633 1633 { 1634 1634 psImage* fOut = NULL; … … 1643 1643 psImage* sBiOut = psImageAlloc(cols,rows,PS_TYPE_S16); 1644 1644 1645 for( introw=0;row<rows;row++) {1645 for(psS32 row=0;row<rows;row++) { 1646 1646 psF32* fRow = fImg->data.F32[row]; 1647 1647 psS16* sRow = sImg->data.S16[row]; 1648 for ( intcol=0;col<cols;col++) {1648 for (psS32 col=0;col<cols;col++) { 1649 1649 fRow[col] = (psF32)(row)+(psF32)(col)/100.0f; 1650 1650 sRow[col] = row-2*col; … … 1657 1657 sBiOut = psImageShift(sBiOut, sImg, colShift, rowShift, -1, PS_INTERPOLATE_BILINEAR); 1658 1658 1659 for( introw=0;row<rows;row++) {1659 for(psS32 row=0;row<rows;row++) { 1660 1660 psF32* fRow = fOut->data.F32[row]; 1661 1661 psS16* sRow = sOut->data.S16[row]; … … 1663 1663 psS16* sBiRow = sBiOut->data.S16[row]; 1664 1664 1665 for ( intcol=0;col<cols;col++) {1665 for (psS32 col=0;col<cols;col++) { 1666 1666 psF32 fValue = psImagePixelInterpolate(fImg,col+colShift, 1667 1667 row+rowShift,NULL,0,NAN,PS_INTERPOLATE_FLAT); … … 1707 1707 } 1708 1708 1709 static inttestImageResample(void)1709 static psS32 testImageResample(void) 1710 1710 { 1711 1711 1712 introws = 60;1713 intcols = 80;1712 psS32 rows = 60; 1713 psS32 cols = 80; 1714 1714 psImage* result = NULL; 1715 intscale = 4;1715 psS32 scale = 4; 1716 1716 psErr* err; 1717 1717 1718 1718 psImage* image = psImageAlloc(cols,rows,PS_TYPE_F32); 1719 for( introw=0;row<rows;row++) {1719 for(psS32 row=0;row<rows;row++) { 1720 1720 psF32* imageRow = image->data.F32[row]; 1721 for ( intcol=0;col<cols;col++) {1721 for (psS32 col=0;col<cols;col++) { 1722 1722 imageRow[col] = row+2*col; 1723 1723 } … … 1753 1753 1754 1754 psF32 truthValue; 1755 for( introw=0;row<result->numRows;row++) {1756 for ( intcol=0;col<result->numCols;col++) {1755 for(psS32 row=0;row<result->numRows;row++) { 1756 for (psS32 col=0;col<result->numCols;col++) { 1757 1757 truthValue = psImagePixelInterpolate(image, 1758 1758 (float)col/(float)scale,(float)row/(float)scale,
Note:
See TracChangeset
for help on using the changeset viewer.
