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