Changeset 11703 for trunk/psLib/src/imageops/psImageConvolve.h
- Timestamp:
- Feb 7, 2007, 6:17:58 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/imageops/psImageConvolve.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageConvolve.h
r11248 r11703 5 5 * @author Robert DeSonia, MHPCC 6 6 * 7 * @version $Revision: 1.1 5$ $Name: not supported by cvs2svn $8 * @date $Date: 2007-0 1-23 22:47:23$7 * @version $Revision: 1.16 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2007-02-08 04:17:58 $ 9 9 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 10 10 */ … … 20 20 #include "psType.h" 21 21 22 #define PS_TYPE_KERNEL PS_TYPE_F32 / **< the data member to use for kernel image */23 #define PS_TYPE_KERNEL_DATA F32 / **< the data member to use for kernel image */24 #define PS_TYPE_KERNEL_NAME "psF32" / **< the data type for kernel as a string */22 #define PS_TYPE_KERNEL PS_TYPE_F32 ///< the data member to use for kernel image */ 23 #define PS_TYPE_KERNEL_DATA F32 ///< the data member to use for kernel image */ 24 #define PS_TYPE_KERNEL_NAME "psF32" ///< the data type for kernel as a string */ 25 25 26 /** Kernel Type 27 * 28 * A floating-point data type used for storing kernel data. 29 * 30 */ 31 //typedef float psKernelType; 32 33 /** A convolution kernel */ 26 /// A convolution kernel 34 27 typedef struct 35 28 { 36 psImage *image; ///< Kernel data, in the form of an image29 psImage *image; ///< Kernel data, in the form of an image 37 30 int xMin; ///< Most negative x index 38 31 int yMin; ///< Most negative y index 39 32 int xMax; ///< Most positive x index 40 33 int yMax; ///< Most positive y index 41 float **kernel; ///< Pointer to the kernel data42 float **p_kernelRows; ///< Pointer to the rows of the kernel data; not intended for user use.34 float **kernel; ///< Pointer to the kernel data 35 float **p_kernelRows; ///< Pointer to the rows of the kernel data; not intended for user use. 43 36 } 44 37 psKernel; 45 38 46 / **Allocates a convolution kernel of the given range47 * 48 *In order to perform a convolution, we need to define the convolution49 *kernel. We need a more general object than a psImage so that we can50 *incorporate the offset from the (0, 0) pixel to the (0, 0) value of the51 *kernel. It might be convenient to allow both positive and negative52 *indices to convey the positive and negative shifts. One might consider53 *setting the x0 and y0 members of a psImage to the appropriate offsets,54 *but this is not the purpose of these members, and doing so may affect the55 *behavior of other psImage operations.56 * 57 *This construction allows the kernel member to use negative indices, while58 *preserving the location of psMemBlocks relative to allocated memory.59 * 60 *The maximum extent of the kernel shifts shall be defined by the xMin,61 *xMax, yMin and yMax members. Note that xMin and yMin, under normal62 *circumstances, should be negative numbers. That is,63 *myKernel->kernel[-3][-2] may be defined if yMin and xMin are equal to or64 *more negative than -3 and -2, respectively.65 * 66 *In the event that one of the minimum values is greater than the67 *corresponding maximum value, the function shall generate a warning, and68 *the offending values shall be exchanged.69 * 70 *@return psKernel* A new kernel object71 */72 psKernel *psKernelAlloc(39 /// Allocates a convolution kernel of the given range 40 /// 41 /// In order to perform a convolution, we need to define the convolution 42 /// kernel. We need a more general object than a psImage so that we can 43 /// incorporate the offset from the (0, 0) pixel to the (0, 0) value of the 44 /// kernel. It might be convenient to allow both positive and negative 45 /// indices to convey the positive and negative shifts. One might consider 46 /// setting the x0 and y0 members of a psImage to the appropriate offsets, 47 /// but this is not the purpose of these members, and doing so may affect the 48 /// behavior of other psImage operations. 49 /// 50 /// This construction allows the kernel member to use negative indices, while 51 /// preserving the location of psMemBlocks relative to allocated memory. 52 /// 53 /// The maximum extent of the kernel shifts shall be defined by the xMin, 54 /// xMax, yMin and yMax members. Note that xMin and yMin, under normal 55 /// circumstances, should be negative numbers. That is, 56 /// myKernel->kernel[-3][-2] may be defined if yMin and xMin are equal to or 57 /// more negative than -3 and -2, respectively. 58 /// 59 /// In the event that one of the minimum values is greater than the 60 /// corresponding maximum value, the function shall generate a warning, and 61 /// the offending values shall be exchanged. 62 /// 63 /// @return psKernel* A new kernel object 64 /// 65 psKernel *psKernelAlloc( 73 66 int xMin, ///< Most negative x index 74 67 int xMax, ///< Most positive x index … … 77 70 ); 78 71 79 / **Checks the type of a particular pointer.80 * 81 *Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.82 * 83 *@return bool: True if the pointer matches a psKernel structure, false otherwise.84 */72 /// Checks the type of a particular pointer. 73 /// 74 /// Uses the appropriate deallocation function in psMemBlock to check the ptr datatype. 75 /// 76 /// @return bool: True if the pointer matches a psKernel structure, false otherwise. 77 /// 85 78 bool psMemCheckKernel( 86 79 psPtr ptr ///< the pointer whose type to check … … 88 81 89 82 90 /** Generates a kernel given a list of shift values 91 * 92 * Given a list of values (e.g., shifts made in the course of OT guiding), 93 * psKernelGenerate shall return the appropriate kernel. The vectors xShifts 94 * and yShifts, which are a list of shifts relative to some starting point, 95 * will be supplied by the user. The elements of the vectors should be of an 96 * integer type; otherwise the values shall be truncated to integers. The 97 * output kernel shall be normalized such that the sum over the kernel is 98 * unity. 99 * 100 * If the vectors are not of the same number of elements, then the function 101 * shall generate a warning shall be generated, following which, the longer 102 * vector trimmed to the length of the shorter, and the function shall continue. 103 * 104 * @return psKernel* new Kernel object 105 */ 106 psKernel* psKernelGenerate( 107 const psVector* tShifts, ///< list of time shifts 108 const psVector* xShifts, ///< list of x-axis shifts 109 const psVector* yShifts, ///< list of y-axis shifts 110 bool relative 111 /**< specifies the starting point for the shifts; true=relative to previous shift 112 * false = relative to some other starting point. */ 83 /// Generates a kernel given a list of shift values 84 /// 85 /// Given a list of values (e.g., shifts made in the course of OT guiding), 86 /// psKernelGenerate shall return the appropriate kernel. The vectors xShifts 87 /// and yShifts, which are a list of shifts relative to some starting point, 88 /// will be supplied by the user. The elements of the vectors should be of an 89 /// integer type; otherwise the values shall be truncated to integers. The 90 /// output kernel shall be normalized such that the sum over the kernel is 91 /// unity. 92 /// 93 /// If the vectors are not of the same number of elements, then the function 94 /// shall generate a warning shall be generated, following which, the longer 95 /// vector trimmed to the length of the shorter, and the function shall continue. 96 /// 97 /// @return psKernel* new Kernel object 98 /// 99 psKernel *psKernelGenerate( 100 const psVector *tShifts, ///< list of time shifts (F32) 101 const psVector *xShifts, ///< list of x-axis shifts (S32) 102 const psVector *yShifts, ///< list of y-axis shifts (S32) 103 bool tRelative, ///< Are times relative (durations) or absolute? 104 bool xyRelative ///< Are x,y positions relative (shifts) or absolute? 113 105 ); 114 106 115 /** convolve an image with a kernel 116 * 117 * Given an input image and the convolution kernel, psImageConvolve shall 118 * convolve the input image, in, with the kernel, kernel and return the 119 * convolved image, out. 120 * 121 * Two methods shall be available for the convolution: if direct is true, 122 * then the convolution shall be performed in real space (appropriate for 123 * small kernels); otherwise, the convolution shall be performed using Fast 124 * Fourier Transforms (FFTs; appropriate for larger kernels). The latter 125 * option involves padding the input image, copying the kernel into an image 126 * of the same size as the padded input image, performing an FFT on each, 127 * multiplying the FFTs, and performing an inverse FFT before trimming the 128 * image back to the original size. 129 * 130 * @return psImage* resulting image 131 */ 132 psImage* psImageConvolve( 133 psImage* out, ///< a psImage to recycle. If NULL, a new psImage is made. 134 const psImage* in, ///< the psImage to convolve 135 const psKernel* kernel, ///< kernel to colvolve with 136 bool direct ///< specifies method, true=direct convolution, false=fourier 107 /// Convolve an image with a kernel, using a direct convolution 108 /// 109 /// This is appropriate for small kernels, where there is no time saving to use FFT method. 110 /// 111 /// @return psImage* resulting image 112 /// 113 psImage *psImageConvolveDirect( 114 psImage *out, ///< a psImage to recycle. If NULL, a new psImage is made. 115 const psImage *in, ///< the psImage to convolve 116 const psKernel *kernel ///< kernel to colvolve with 137 117 ); 138 118 139 /** Smooths an image by parts using 1D Gaussian independently in x and y. 140 * 141 * Applies a circularly symmetric Gaussian smoothing first in x and then in y 142 * directions with just a vector. This process is 2N faster than 2D convolutions (in general). 143 * 144 * @return bool TRUE if successful, otherwise FALSE 145 */ 119 /// Convolve an image with a kernel, using the FFT 120 /// 121 /// This is appropriate for larger kernels, where the direct convolution is slow. The input image and kernel 122 /// are suitably padded to avoid wrap-around effects. 123 psImage *psImageConvolveFFT( 124 psImage *out, ///< a psImage to recycle. If NULL, a new psImage is made. 125 const psImage *in, ///< the psImage to convolve 126 const psKernel *kernel, ///< kernel to colvolve with 127 float pad ///< Value to use to pad the input image 128 ); 129 130 /// Smooths an image by parts using 1D Gaussian independently in x and y. 131 /// 132 /// Applies a circularly symmetric Gaussian smoothing first in x and then in y 133 /// directions with just a vector. This process is 2N faster than 2D convolutions (in general). 134 /// 135 /// @return bool TRUE if successful, otherwise FALSE 136 /// 146 137 bool psImageSmooth( 147 138 psImage *image, ///< the image to be smoothed
Note:
See TracChangeset
for help on using the changeset viewer.
