Changeset 5573
- Timestamp:
- Nov 22, 2005, 10:15:35 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/imageops/psImageConvolve.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageConvolve.c
r5057 r5573 5 5 * @author Robert DeSonia, MHPCC 6 6 * 7 * @version $Revision: 1.2 6$ $Name: not supported by cvs2svn $8 * @date $Date: 2005- 09-15 21:22:22$7 * @version $Revision: 1.27 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2005-11-22 20:15:35 $ 9 9 * 10 10 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 504 504 Ny = image->numRows; 505 505 506 // generate gaussian 507 psVector *gaussnorm = psVectorAlloc (Npixel, PS_TYPE_F64); 508 for (int i = -Nrange; i < Nrange + 1; i++) { 509 gaussnorm->data.F64[i+Nrange] = exp (factor*i*i); 510 } 511 psF64 *gauss = &gaussnorm->data.F64[Nrange]; 512 513 // smooth in X direction 514 temp = psVectorAlloc (Nx, PS_TYPE_F64); 515 for (int j = 0; j < Ny; j++) { 516 psF64 *vi = image->data.F64[j]; 517 psF64 *vo = temp->data.F64; 518 for (int i = 0; i < Nx; i++) { 519 g = s = 0; 520 for (int n = -Nrange; n < Nrange + 1; n++) { 521 if (i+n < 0) 522 continue; 523 if (i+n >= Nx) 524 continue; 525 s += gauss[n]*vi[i+n]; 526 g += gauss[n]; 527 } 528 vo[i] = s / g; 529 } 530 memcpy (image->data.F64[j], temp->data.F64, Nx*sizeof(psF64)); 531 } 532 psFree (temp); 533 534 // smooth in Y direction 535 temp = psVectorAlloc (image->numRows, PS_TYPE_F64); 536 for (int i = 0; i < Nx; i++) { 537 psF64 *vo = temp->data.F64; 538 psF64 **vi = image->data.F64; 539 for (int j = 0; j < Ny; j++) { 540 g = s = 0; 541 for (int n = -Nrange; n < Nrange + 1; n++) { 542 if (j+n < 0) 543 continue; 544 if (j+n >= Ny) 545 continue; 546 s += gauss[n]*vi[j+n][i]; 547 g += gauss[n]; 548 } 549 vo[j] = s / g; 550 } 551 // replace temp in image 552 for (int j = 0; j < Ny; j++) { 553 vi[j][i] = vo[j]; 554 } 555 } 556 psFree (temp); 557 psFree (gaussnorm); 506 #define IMAGESMOOTH_CASE(TYPE) \ 507 case PS_TYPE_##TYPE: { \ 508 /* generate gaussian */ \ 509 psVector *gaussnorm = psVectorAlloc (Npixel, PS_TYPE_##TYPE); \ 510 for (int i = -Nrange; i < Nrange + 1; i++) { \ 511 gaussnorm->data.TYPE[i+Nrange] = exp (factor*i*i); \ 512 } \ 513 ps##TYPE *gauss = &gaussnorm->data.TYPE[Nrange]; \ 514 \ 515 /* smooth in X direction */ \ 516 temp = psVectorAlloc (Nx, PS_TYPE_##TYPE); \ 517 for (int j = 0; j < Ny; j++) { \ 518 ps##TYPE *vi = image->data.TYPE[j]; \ 519 ps##TYPE *vo = temp->data.TYPE; \ 520 for (int i = 0; i < Nx; i++) { \ 521 g = s = 0; \ 522 for (int n = -Nrange; n < Nrange + 1; n++) { \ 523 if (i+n < 0) \ 524 continue; \ 525 if (i+n >= Nx) \ 526 continue; \ 527 s += gauss[n]*vi[i+n]; \ 528 g += gauss[n]; \ 529 } \ 530 vo[i] = s / g; \ 531 } \ 532 memcpy (image->data.TYPE[j], temp->data.TYPE, Nx*sizeof(ps##TYPE)); \ 533 } \ 534 psFree (temp); \ 535 \ 536 /* smooth in Y direction */ \ 537 temp = psVectorAlloc (image->numRows, PS_TYPE_##TYPE); \ 538 for (int i = 0; i < Nx; i++) { \ 539 ps##TYPE *vo = temp->data.TYPE; \ 540 ps##TYPE **vi = image->data.TYPE; \ 541 for (int j = 0; j < Ny; j++) { \ 542 g = s = 0; \ 543 for (int n = -Nrange; n < Nrange + 1; n++) { \ 544 if (j+n < 0) \ 545 continue; \ 546 if (j+n >= Ny) \ 547 continue; \ 548 s += gauss[n]*vi[j+n][i]; \ 549 g += gauss[n]; \ 550 } \ 551 vo[j] = s / g; \ 552 } \ 553 /* replace temp in image */ \ 554 for (int j = 0; j < Ny; j++) { \ 555 vi[j][i] = vo[j]; \ 556 } \ 557 } \ 558 psFree (temp); \ 559 psFree (gaussnorm); \ 560 } 561 562 switch (image->type.type) { 563 IMAGESMOOTH_CASE(F32); 564 IMAGESMOOTH_CASE(F64); 565 default: { 566 char* typeStr; 567 PS_TYPE_NAME(typeStr,image->type.type); 568 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 569 PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED, 570 typeStr); 571 } 572 } 558 573 } 559 574
Note:
See TracChangeset
for help on using the changeset viewer.
