IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 16, 2007, 1:31:03 PM (19 years ago)
Author:
Paul Price
Message:

Adding psImageConvolveMaskFFT to use FFT convolution to convolve mask --- should be faster than direct convolution for large kernels.

File:
1 edited

Legend:

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

    r14866 r15320  
    77/// @author Eugene Magnier, IfA
    88///
    9 /// @version $Revision: 1.57 $ $Name: not supported by cvs2svn $
    10 /// @date $Date: 2007-09-17 20:49:51 $
     9/// @version $Revision: 1.58 $ $Name: not supported by cvs2svn $
     10/// @date $Date: 2007-10-16 23:31:03 $
    1111///
    1212/// Copyright 2004-2007 Institute for Astronomy, University of Hawaii
     
    313313}
    314314
    315 psImage *psImageConvolveMask(const psImage *mask, psMaskType maskVal, const psKernel *kernel)
     315psImage *psImageConvolveMaskDirect(const psImage *mask, psMaskType maskVal, const psKernel *kernel)
    316316{
    317317    PS_ASSERT_IMAGE_NON_NULL(mask, NULL);
     
    491491
    492492    return out;
     493}
     494
     495
     496psImage *psImageConvolveMaskFFT(const psImage *mask, psMaskType maskVal, const psKernel *kernel, float thresh)
     497{
     498    PS_ASSERT_IMAGE_NON_NULL(mask, NULL);
     499    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, NULL);
     500    PS_ASSERT_PTR_NON_NULL(kernel, NULL);
     501    PS_ASSERT_PTR_NON_NULL(kernel->kernel, NULL);
     502    PS_ASSERT_FLOAT_LARGER_THAN(thresh, 0.0, NULL);
     503    PS_ASSERT_FLOAT_LESS_THAN(thresh, 1.0, NULL);
     504
     505    int numRows = mask->numRows, numCols = mask->numCols; // Size of image
     506
     507    psImage *onoff = (psImage*)psBinaryOp(NULL, (const psPtr)mask, "&", // Casting away const so I can use
     508                                          psScalarAlloc(maskVal, PS_TYPE_MASK)); // Pixels on or off
     509    psImage *copy = psImageCopy(NULL, onoff, PS_TYPE_F32); // Floating-point copy
     510    psImage *convolved = psImageConvolveFFT(copy, NULL, 0, kernel, 0.0);
     511    psFree(copy);
     512
     513    thresh *= maskVal;
     514    for (int y = 0; y < numRows; y++) {
     515        for (int x = 0; x < numCols; x++) {
     516            onoff->data.PS_TYPE_MASK_DATA[y][x] = (convolved->data.F32[y][x] >= thresh) ?
     517                (mask->data.PS_TYPE_MASK_DATA[y][x] | maskVal) : mask->data.PS_TYPE_MASK_DATA[y][x];
     518        }
     519    }
     520
     521    psFree(convolved);
     522
     523    return onoff;
    493524}
    494525
Note: See TracChangeset for help on using the changeset viewer.