IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7091


Ignore:
Timestamp:
May 8, 2006, 5:27:25 PM (20 years ago)
Author:
Paul Price
Message:

Removing old version of psImageSmooth. The new version is much faster, and it has now been tested.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/imageops/psImageConvolve.c

    r7089 r7091  
    55 *  @author Robert DeSonia, MHPCC
    66 *
    7  *  @version $Revision: 1.35 $ $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 $
    99 *
    1010 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    487487}
    488488
    489 // XXX this is the old version from MHPCC
    490 # if 0
    491489bool psImageSmooth (psImage *image,
    492490                    double  sigma,
    493491                    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 terms
    502     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 # else
    581 
    582     // XXX EAM : we MUST use this version : it is a factor of >7 faster than the above
    583     bool psImageSmooth (psImage *image,
    584                         double  sigma,
    585                         double  Nsigma)
    586492{
    587493    PS_ASSERT_IMAGE_NON_NULL(image, NULL);
     
    763669    return true;
    764670}
    765 
    766 # endif
Note: See TracChangeset for help on using the changeset viewer.