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.

Location:
trunk/psLib/src/imageops
Files:
4 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
  • trunk/psLib/src/imageops/psImageConvolve.h

    r4540 r4815  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2005-07-12 19:12:01 $
     9 *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2005-08-18 21:44:40 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    126126);
    127127
     128/** Smooths an image by parts using 1D Gaussian independently in x and y.
     129 *
     130 *  Applies a circularly symmetric Gaussian smoothing first in x and then in y
     131 *  directions with just a vector.  This process is 2N faster than 2D convolutions (in general).
     132 */
     133void psImageSmooth(
     134    psImage *image,                    ///< the image to be smoothed
     135    float sigma,                       ///< the width of the smoothing kernel in pixels
     136    float Nsigma                       ///< the size of the smoothing box in sigmas
     137);
     138
     139
    128140#endif // #ifndef PS_IMAGE_CONVOLVE_H
  • trunk/psLib/src/imageops/psImagePixelManip.c

    r4589 r4815  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2005-07-21 01:40:10 $
     12 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2005-08-18 21:44:40 $
    1414 *
    1515 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    396396}
    397397
     398// mask the area contained by the region
     399// the region is defined wrt the parent image
     400void psImageMaskRegion(psImage *image,
     401                       psRegion *region,
     402                       bool logical_and,
     403                       int maskValue)
     404{
     405
     406    for (int iy = 0; iy < image->numRows; iy++) {
     407        for (int ix = 0; ix < image->numCols; ix++) {
     408            if (ix + image->col0 <  region->x0)
     409                continue;
     410            if (ix + image->col0 >= region->x1)
     411                continue;
     412            if (iy + image->row0 <  region->y0)
     413                continue;
     414            if (iy + image->row0 >= region->y1)
     415                continue;
     416            if (logical_and) {
     417                image->data.U8[iy][ix] &= maskValue;
     418            } else {
     419                image->data.U8[iy][ix] |= maskValue;
     420            }
     421        }
     422    }
     423}
     424
     425// mask the area not contained by the region
     426// the region is defined wrt the parent image
     427void psImageKeepRegion(psImage *image,
     428                       psRegion *region,
     429                       bool logical_and,
     430                       int maskValue)
     431{
     432
     433    for (int iy = 0; iy < image->numRows; iy++) {
     434        for (int ix = 0; ix < image->numCols; ix++) {
     435            if (ix + image->col0 <  region->x0)
     436                goto maskit;
     437            if (ix + image->col0 >= region->x1)
     438                goto maskit;
     439            if (iy + image->row0 <  region->y0)
     440                goto maskit;
     441            if (iy + image->row0 >= region->y1)
     442                goto maskit;
     443            continue;
     444maskit:
     445            if (logical_and) {
     446                image->data.U8[iy][ix] &= maskValue;
     447            } else {
     448                image->data.U8[iy][ix] |= maskValue;
     449            }
     450        }
     451    }
     452}
     453
     454// mask the area contained by the region
     455// the region is defined wrt the parent image
     456void psImageMaskCircle(psImage *image,
     457                       double x,
     458                       double y,
     459                       double radius,
     460                       bool logical_and,
     461                       int maskValue)
     462{
     463
     464    double dx, dy, r2, R2;
     465
     466    R2 = PS_SQR(radius);
     467
     468    for (int iy = 0; iy < image->numRows; iy++) {
     469        for (int ix = 0; ix < image->numCols; ix++) {
     470            dx = ix + image->col0 - x;
     471            dy = iy + image->row0 - y;
     472            r2 = PS_SQR(dx) + PS_SQR(dy);
     473            if (r2 > R2)
     474                continue;
     475            if (logical_and) {
     476                image->data.U8[iy][ix] &= maskValue;
     477            } else {
     478                image->data.U8[iy][ix] |= maskValue;
     479            }
     480        }
     481    }
     482}
     483
     484// mask the area contained by the region
     485// the region is defined wrt the parent image
     486void psImageKeepCircle(psImage *image,
     487                       double x,
     488                       double y,
     489                       double radius,
     490                       bool logical_and,
     491                       int maskValue)
     492{
     493
     494    double dx, dy, r2, R2;
     495
     496    R2 = PS_SQR(radius);
     497
     498    for (int iy = 0; iy < image->numRows; iy++) {
     499        for (int ix = 0; ix < image->numCols; ix++) {
     500            dx = ix + image->col0 - x;
     501            dy = iy + image->row0 - y;
     502            r2 = PS_SQR(dx) + PS_SQR(dy);
     503            if (r2 < R2)
     504                continue;
     505            if (logical_and) {
     506                image->data.U8[iy][ix] &= maskValue;
     507            } else {
     508                image->data.U8[iy][ix] |= maskValue;
     509            }
     510        }
     511    }
     512}
     513
  • trunk/psLib/src/imageops/psImagePixelManip.h

    r4589 r4815  
    88 *  @author Robert DeSonia, MHPCC
    99 *
    10  *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2005-07-21 01:40:10 $
     10 *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2005-08-18 21:44:40 $
    1212 *
    1313 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    8787    const char *op                     ///< the operation to perform for overlay
    8888);
     89/** Sets the bits inside the region, ignoring pixels outside.
     90 *
     91 *  The pixels are set by combining the existing pixel value and the given maskValue
     92 *  with a logical operation.  The allowed operations are =, AND, OR, and XOR.
     93 */
     94void psImageMaskRegion(
     95    psImage *image,                    ///< the image to set
     96    psRegion *region,                  ///< the specified region
     97    bool logical_and,                  ///< the logical operation
     98    int maskValue                      ///< the specified bits
     99);
     100
     101/** Sets the bits outside the region, ignoring pixels inside.
     102 *
     103 *  The pixels are set by combining the existing pixel value and the given maskValue
     104 *  with a logical operation.  The allowed operations are =, AND, OR, and XOR.
     105 */
     106void psImageKeepRegion(
     107    psImage *image,                    ///< the image to set
     108    psRegion *region,                  ///< the specified region
     109    bool logical_and,                  ///< the logical operation
     110    int maskValue                      ///< the specified bits
     111);
     112
     113/** Sets the bits inside the circle, ignoring the pixels outside.
     114 *
     115 *  The pixel values are set by combining the existing pixel value and the given maskValue
     116 *  with a logical operation.  The allowed operations are =, AND, OR, and XOR.
     117 */
     118void psImageMaskCircle(
     119    psImage *image,                    ///< the image to set
     120    double x,                          ///< the x coordinate of the circle's center
     121    double y,                          ///< the y coordinate of the circle's center
     122    double radius,                     ///< the radius of the specified circle
     123    bool logical_and,                  ///< the logical operation
     124    int maskValue                      ///< the specified bits
     125);
     126
     127/** Sets the bits outside the circle, ignoring the pixels inside.
     128 *
     129 *  The pixel values are set by combining the existing pixel value and the given maskValue
     130 *  with a logical operation.  The allowed operations are =, AND, OR, and XOR.
     131 */
     132void psImageKeepCircle(
     133    psImage *image,                    ///< the image to set
     134    double x,                          ///< the x coordinate of the circle's center
     135    double y,                          ///< the y coordinate of the circle's center
     136    double radius,                     ///< the radius of the specified circle
     137    bool logical_and,                  ///< the logical operation
     138    int maskValue                      ///< the specified bits
     139);
    89140
    90141#endif // #ifndef PS_IMAGE_PIXEL_MANIP_H
Note: See TracChangeset for help on using the changeset viewer.