IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 18, 2005, 11:44:40 AM (21 years ago)
Author:
drobbin
Message:

folded in code from bug 481. Tests still to be written.

File:
1 edited

Legend:

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

    r4544 r4815  
    55 *  @author Robert DeSonia, MHPCC
    66 *
    7  *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2005-07-12 19:33:49 $
     7 *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2005-08-18 21:44:40 $
    99 *
    1010 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    1212
    1313#include <string.h>
    14 
     14#include <math.h>
    1515#include "psImageConvolve.h"
    1616#include "psImageFFT.h"
     
    279279}
    280280
    281 psImage* psImageConvolve(psImage* out, const psImage* in, const psKernel* kernel, bool direct)
     281psImage* psImageConvolve(psImage* out,
     282                         const psImage* in,
     283                         const psKernel* kernel,
     284                         bool direct)
    282285{
    283286    if (in == NULL) {
     
    476479    return out;
    477480}
     481
     482void psImageSmooth (psImage *image,
     483                    float sigma,
     484                    float Nsigma)
     485{
     486
     487    int Nx, Ny, Npixel, Nrange;
     488    float factor, g, s;
     489    psVector *temp;
     490
     491    // relevant terms
     492    Nrange = sigma*Nsigma + 0.5;
     493    Npixel = 2*Nrange + 1;
     494    factor = -0.5/(sigma*sigma);
     495
     496    Nx = image->numCols;
     497    Ny = image->numRows;
     498
     499    // generate gaussian
     500    psVector *gaussnorm = psVectorAlloc (Npixel, PS_TYPE_F32);
     501    for (int i = -Nrange; i < Nrange + 1; i++) {
     502        gaussnorm->data.F32[i+Nrange] = exp (factor*i*i);
     503    }
     504    psF32 *gauss = &gaussnorm->data.F32[Nrange];
     505
     506    // smooth in X direction
     507    temp = psVectorAlloc (Nx, PS_TYPE_F32);
     508    for (int j = 0; j < Ny; j++) {
     509        psF32 *vi = image->data.F32[j];
     510        psF32 *vo = temp->data.F32;
     511        for (int i = 0; i < Nx; i++) {
     512            g = s = 0;
     513            for (int n = -Nrange; n < Nrange + 1; n++) {
     514                if (i+n < 0)
     515                    continue;
     516                if (i+n >= Nx)
     517                    continue;
     518                s += gauss[n]*vi[i+n];
     519                g += gauss[n];
     520            }
     521            vo[i] = s / g;
     522        }
     523        memcpy (image->data.F32[j], temp->data.F32, Nx*sizeof(psF32));
     524    }
     525    psFree (temp);
     526
     527    // smooth in Y direction
     528    temp = psVectorAlloc (image->numRows, PS_TYPE_F32);
     529    for (int i = 0; i < Nx; i++) {
     530        psF32  *vo = temp->data.F32;
     531        psF32 **vi = image->data.F32;
     532        for (int j = 0; j < Ny; j++) {
     533            g = s = 0;
     534            for (int n = -Nrange; n < Nrange + 1; n++) {
     535                if (j+n < 0)
     536                    continue;
     537                if (j+n >= Ny)
     538                    continue;
     539                s += gauss[n]*vi[j+n][i];
     540                g += gauss[n];
     541            }
     542            vo[j] = s / g;
     543        }
     544        // replace temp in image
     545        for (int j = 0; j < Ny; j++) {
     546            vi[j][i] = vo[j];
     547        }
     548    }
     549    psFree (temp);
     550    psFree (gaussnorm);
     551}
     552
Note: See TracChangeset for help on using the changeset viewer.