Changeset 7091 for trunk/psLib/src/imageops/psImageConvolve.c
- Timestamp:
- May 8, 2006, 5:27:25 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/imageops/psImageConvolve.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageConvolve.c
r7089 r7091 5 5 * @author Robert DeSonia, MHPCC 6 6 * 7 * @version $Revision: 1.3 5$ $Name: not supported by cvs2svn $8 * @date $Date: 2006-05-09 03: 16:52$7 * @version $Revision: 1.36 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2006-05-09 03:27:25 $ 9 9 * 10 10 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 487 487 } 488 488 489 // XXX this is the old version from MHPCC490 # if 0491 489 bool psImageSmooth (psImage *image, 492 490 double sigma, 493 491 double Nsigma) 494 {495 PS_ASSERT_IMAGE_NON_NULL(image, NULL);496 497 int Nx, Ny, Npixel, Nrange;498 double factor, g, s;499 psVector *temp;500 501 // relevant terms502 Nrange = sigma*Nsigma + 0.5;503 Npixel = 2*Nrange + 1;504 factor = -0.5/(sigma*sigma);505 506 Nx = image->numCols;507 Ny = image->numRows;508 509 #define IMAGESMOOTH_CASE(TYPE) \510 case PS_TYPE_##TYPE: { \511 /* generate gaussian */ \512 psVector *gaussnorm = psVectorAlloc (Npixel, PS_TYPE_##TYPE); \513 for (int i = -Nrange; i < Nrange + 1; i++) { \514 gaussnorm->data.TYPE[i+Nrange] = exp (factor*i*i); \515 } \516 ps##TYPE *gauss = &gaussnorm->data.TYPE[Nrange]; \517 \518 /* smooth in X direction */ \519 temp = psVectorAlloc (Nx, PS_TYPE_##TYPE); \520 for (int j = 0; j < Ny; j++) { \521 ps##TYPE *vi = image->data.TYPE[j]; \522 ps##TYPE *vo = temp->data.TYPE; \523 for (int i = 0; i < Nx; i++) { \524 g = s = 0; \525 for (int n = -Nrange; n < Nrange + 1; n++) { \526 if (i+n < 0) \527 continue; \528 if (i+n >= Nx) \529 continue; \530 s += gauss[n]*vi[i+n]; \531 g += gauss[n]; \532 } \533 vo[i] = s / g; \534 } \535 memcpy (image->data.TYPE[j], temp->data.TYPE, Nx*sizeof(ps##TYPE)); \536 } \537 psFree (temp); \538 \539 /* smooth in Y direction */ \540 temp = psVectorAlloc (image->numRows, PS_TYPE_##TYPE); \541 for (int i = 0; i < Nx; i++) { \542 ps##TYPE *vo = temp->data.TYPE; \543 ps##TYPE **vi = image->data.TYPE; \544 for (int j = 0; j < Ny; j++) { \545 g = s = 0; \546 for (int n = -Nrange; n < Nrange + 1; n++) { \547 if (j+n < 0) \548 continue; \549 if (j+n >= Ny) \550 continue; \551 s += gauss[n]*vi[j+n][i]; \552 g += gauss[n]; \553 } \554 vo[j] = s / g; \555 } \556 /* replace temp in image */ \557 for (int j = 0; j < Ny; j++) { \558 vi[j][i] = vo[j]; \559 } \560 } \561 psFree (temp); \562 psFree (gaussnorm); \563 break; \564 }565 566 switch (image->type.type) {567 IMAGESMOOTH_CASE(F32);568 IMAGESMOOTH_CASE(F64);569 default: {570 char* typeStr;571 PS_TYPE_NAME(typeStr,image->type.type);572 psError(PS_ERR_BAD_PARAMETER_TYPE, true,573 PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,574 typeStr);575 return false;576 }577 }578 return true;579 }580 # else581 582 // XXX EAM : we MUST use this version : it is a factor of >7 faster than the above583 bool psImageSmooth (psImage *image,584 double sigma,585 double Nsigma)586 492 { 587 493 PS_ASSERT_IMAGE_NON_NULL(image, NULL); … … 763 669 return true; 764 670 } 765 766 # endif
Note:
See TracChangeset
for help on using the changeset viewer.
