Changeset 3702 for trunk/psLib/test/image/tst_psImageConvolve.c
- Timestamp:
- Apr 14, 2005, 2:12:09 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/image/tst_psImageConvolve.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/image/tst_psImageConvolve.c
r3682 r3702 5 5 * @author Robert DeSonia, MHPCC 6 6 * 7 * @version $Revision: 1. 9$ $Name: not supported by cvs2svn $8 * @date $Date: 2005-04- 07 20:27:42$7 * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2005-04-15 00:12:09 $ 9 9 * 10 10 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 22 22 static psS32 testKernelAlloc(void); 23 23 static psS32 testKernelGenerate(void); 24 //static psS32 testImageConvolve(void);24 static psS32 testImageConvolve(void); 25 25 26 26 testDescription tests[] = { 27 27 {testKernelAlloc,731,"psKernelAlloc",0,false}, 28 28 {testKernelGenerate,732,"psKernelGenerate",0,false}, 29 //{testImageConvolve,733,"psImageConvolve",0,false},29 {testImageConvolve,733,"psImageConvolve",0,false}, 30 30 {NULL} 31 31 }; … … 286 286 } 287 287 288 /*289 288 static psS32 testImageConvolve(void) 290 289 { … … 292 291 const psS32 c = 300; 293 292 psS32 sum; 294 293 295 294 // approximate a normalized gaussian kernel. 296 295 psKernel* g = psKernelAlloc(-1,1,-1,1); … … 304 303 g->kernel[0][1] = 0.0838; 305 304 g->kernel[0][0] = 0.6193; 306 305 307 306 // create a normalized non-symetric kernel. 308 307 psKernel* nsk = psKernelAlloc(0,2,0,2); … … 319 318 } 320 319 } 321 322 320 321 323 322 psImage* img = psImageAlloc(c,r,PS_TYPE_F32); 324 323 memset(img->data.F32[0],0,c*r*PSELEMTYPE_SIZEOF(PS_TYPE_F32)); … … 326 325 img->data.F32[r/2][c/2] = 1.0f; 327 326 img->data.F32[r-1][c/2] = 1.0f; 328 327 329 328 // test spacial convolution of gaussian 330 329 psLogMsg(__func__,PS_LOG_INFO,"Testing direct gaussian convolution"); 331 330 psImage* out = psImageConvolve(NULL, img, g, true); 332 331 333 332 if (out == NULL) { 334 333 psError(PS_ERR_UNKNOWN, true, "psImageConvolve returned a NULL for direct gaussian case."); 335 334 return 1; 336 335 } 337 336 338 337 if (out->numCols != c || out->numRows != r) { 339 338 psError(PS_ERR_UNKNOWN, true, "psImageConvolve result image is %dx%d, but expected %dx%d.", … … 342 341 return 2; 343 342 } 344 343 345 344 if (out->type.type != PS_TYPE_F32) { 346 345 char* typeStr; … … 350 349 return 3; 351 350 } 352 351 353 352 // test values 354 353 for (psS32 i=-1;i<1;i++) { … … 374 373 } 375 374 } 376 375 377 376 // test fourier convolution of gaussian 378 377 psLogMsg(__func__,PS_LOG_INFO,"Testing fourier gaussian convolution"); 379 psKernel* gg = psKernelAlloc(1,3,1,3); 380 gg->kernel[1][1] = 381 gg->kernel[1][3] = 382 gg->kernel[3][1] = 383 gg->kernel[3][3] = 0.0113; 384 gg->kernel[3][2] = 385 gg->kernel[1][2] = 386 gg->kernel[2][1] = 387 gg->kernel[2][3] = 0.0838; 388 gg->kernel[2][2] = 0.6193; 389 img->data.F32[0][0] = 0.0f; 390 img->data.F32[r/2][c/2] = 1.0f; 391 img->data.F32[r-1][c/2] = 0.0f; 392 psImage* out2 = psImageConvolve(out, img, gg, false); 393 378 psImage* out2 = psImageConvolve(out, img, g, false); 379 394 380 if (out == NULL) { 395 381 psError(PS_ERR_UNKNOWN, true, "psImageConvolve returned a NULL for gaussian case."); 396 382 return 10; 397 383 } 398 384 399 385 if (out != out2) { 400 386 psError(PS_ERR_UNKNOWN, true, "psImageConvolve didn't recycle the supplied out image struct."); 401 387 return 11; 402 388 } 403 389 404 390 if (out->numCols != c || out->numRows != r) { 405 391 psError(PS_ERR_UNKNOWN, true, "psImageConvolve result image is %dx%d, but expected %dx%d.", … … 408 394 return 12; 409 395 } 410 396 411 397 if (out->type.type != PS_TYPE_F32) { 412 398 char* typeStr; … … 416 402 return 13; 417 403 } 418 419 psImageWriteSection(out2,0,0,0,NULL,0,"out2.fits"); 404 420 405 // test values 421 406 for (psS32 i=-1;i<1;i++) { 422 407 for (psS32 j=-1;j<1;j++) { 423 if (fabsf(out->data.F32[r/2+i][c/2+j] - g->kernel[i][j]) > 0.0 001) {408 if (fabsf(out->data.F32[r/2+i][c/2+j] - g->kernel[i][j]) > 0.01) { 424 409 psError(PS_ERR_UNKNOWN, true,"Convolved image wrong at %d,%d. Value is %g, expected %g.", 425 410 c/2+j,r/2+i, 426 411 out->data.F32[r/2+i][c/2+j], g->kernel[i][j]); 427 psImageWriteSection(out,0,0,0,NULL,0,"problem.fits");428 412 return 14; 429 413 } 430 if (i >= 0 && j >= 0 && fabsf(out->data.F32[i][j] - g->kernel[i][j]) > 0.0 001) {414 if (i >= 0 && j >= 0 && fabsf(out->data.F32[i][j] - g->kernel[i][j]) > 0.01) { 431 415 psError(PS_ERR_UNKNOWN, true,"Convolved image wrong at %d,%d. Value is %g, expected %g.", 432 416 j,i, … … 434 418 return 15; 435 419 } 436 if (i <= 0 && fabsf(out->data.F32[r-1+i][c/2+j] - g->kernel[i][j]) > 0.0 001) {420 if (i <= 0 && fabsf(out->data.F32[r-1+i][c/2+j] - g->kernel[i][j]) > 0.01) { 437 421 psError(PS_ERR_UNKNOWN, true,"Convolved image wrong at %d,%d. Value is %g, expected %g.", 438 422 c/2+j,r-1+i, … … 442 426 } 443 427 } 444 428 445 429 psFree(g); 446 430 psFree(img); … … 449 433 return 0; 450 434 } 451 */ 452 435
Note:
See TracChangeset
for help on using the changeset viewer.
