IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15320


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.

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

    r14866 r15320  
    55 * @author Robert DeSonia, MHPCC
    66 *
    7  * @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
    8  * @date $Date: 2007-09-17 20:49:51 $
     7 * @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
     8 * @date $Date: 2007-10-16 23:31:03 $
    99 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    1010 */
     
    153153);
    154154
    155 /// Convolve a mask image with a kernel
     155/// Convolve a mask image with a kernel, using direct convolution
    156156///
    157157/// Returns a mask, grown by the supplied kernel.  Only those pixels specified by the maskVal are grown; the
    158158/// rest are simply propagated.
    159 psImage *psImageConvolveMask(const psImage *mask, ///< Mask to convolve
    160                              psMaskType maskVal, ///< Mask value to convolve
    161                              const psKernel *kernel ///< Kernel by which to convolve
     159psImage *psImageConvolveMaskDirect(const psImage *mask, ///< Mask to convolve
     160                                   psMaskType maskVal, ///< Mask value to convolve
     161                                   const psKernel *kernel ///< Kernel by which to convolve
     162    );
     163
     164/// Convolve a mask image with a kernel, using the FFT
     165///
     166/// Returns a mask, grown by the supplied kernel.  Only those pixels specified by the maskVal are grown; the
     167/// rest are simply propagated.  Uses psImageConvolveFFT to convolve the mask, and then thresholds at the
     168/// specified level.
     169psImage *psImageConvolveMaskFFT(const psImage *mask, ///< Mask to convolve
     170                                psMaskType maskVal, ///< Mask value to convolve
     171                                const psKernel *kernel, ///< Kernel by which to convolve
     172                                float thresh ///< Threshold (0..1) for convolved floating-point image
    162173    );
    163174
Note: See TracChangeset for help on using the changeset viewer.