core/vil1/vil1_convolve.h

Go to the documentation of this file.
00001 // This is core/vil1/vil1_convolve.h
00002 #ifndef vil1_convolve_h_
00003 #define vil1_convolve_h_
00004 //:
00005 // \file
00006 // \author fsm
00007 
00008 #include <vcl_compiler.h>
00009 #include <vil1/vil1_memory_image_of.h>
00010 
00011 //: Available options for boundary behavior
00012 // When convolving a finite signal the boundaries may be
00013 // treated in various ways which can often be expressed in terms
00014 // of ways to extend the signal outside its original range.
00015 enum vil1_convolve_boundary_option {
00016   // Do not to extend the signal, but pad with zeros.
00017   //     |                               |
00018   // K                       ----*-------
00019   // in   ... ---------------------------
00020   // out  ... --------------------0000000
00021   vil1_convolve_no_extend,
00022 
00023   // Zero-extend the input signal beyond the boundary.
00024   //     |                               |
00025   // K                              ----*--------
00026   // in   ... ---------------------------000000000000...
00027   // out  ... ---------------------------
00028   vil1_convolve_zero_extend,
00029 
00030   // Extend the signal to be constant beyond the boundary
00031   //     |                               |
00032   // K                              ----*--------
00033   // in   ... --------------------------aaaaaaaaaaaaa...
00034   // out  ... ---------------------------
00035   vil1_convolve_constant_extend,
00036 
00037   // Extend the signal periodically beyond the boundary.
00038   //     |                               |
00039   // K                              ----*--------
00040   // in   abc...-------------------------abc...------..
00041   // out  ... ---------------------------
00042   vil1_convolve_periodic_extend,
00043 
00044   // Extend the signal by reflection about the boundary.
00045   //     |                               |
00046   // K                               ----*--------
00047   // in   ... -------------------...edcbabcde...
00048   // out  ... ---------------------------
00049   vil1_convolve_reflect_extend,
00050 
00051   // This one is slightly different. The input signal is not
00052   // extended in any way, but the kernel is trimmed to allow
00053   // convolution to proceed up to the boundary and reweighed
00054   // to keep the total area the same.
00055   // *** may not work with kernels which take negative values.
00056   vil1_convolve_trim
00057 };
00058 
00059 //: Parameters for convolution
00060 // These structs exist purely to group the parameters to the
00061 // convolution routines. It is not intended that they be
00062 // expressive or even useful in any other context.
00063 //
00064 // Usually, begin <= origin < end. Expect assertion failures
00065 // if that is not the case.
00066 template <class T>
00067 struct vil1_convolve_signal_1d {
00068   T *array_;
00069   int begin_;
00070   int origin_;
00071   int end_;
00072   vil1_convolve_signal_1d(T *a, int b, int o, int e)
00073     : array_(a), begin_(b), origin_(o), end_(e) { }
00074 };
00075 
00076 //: Parameters for convolution
00077 template <class T>
00078 struct vil1_convolve_signal_2d {
00079   T * const *array_;
00080   int beginx_, originx_, endx_;
00081   int beginy_, originy_, endy_;
00082   vil1_convolve_signal_2d(T * const *a,
00083                           int bx, int ox, int ex,
00084                           int by, int oy, int ey)
00085     : array_(a)
00086     , beginx_(bx), originx_(ox), endx_(ex)
00087     , beginy_(by), originy_(oy), endy_(ey)
00088     { }
00089 };
00090 
00091 // Note. The convolution operation is defined by
00092 //    (f*g)(x) = \int f(x-y) g(y) dy,
00093 // i.e. one operand is reflected before the integration is performed.
00094 // If you don't want this to happen, the behaviour you want is not
00095 // called "convolution". So don't break the convolution routines in
00096 // that particular way.
00097 
00098 //: Convolution in x-direction : out(x, y) = \sum_i kernel[i]*in(x-i, y)
00099 template <class I1, class I2, class AC, class O>
00100 void vil1_convolve_1d_x(vil1_convolve_signal_1d<I1 const> const &kernel,
00101                         vil1_convolve_signal_2d<I2 const> const &input,
00102                         AC * /*accumulator type*/,
00103                         vil1_convolve_signal_2d<O> const &output,
00104                         vil1_convolve_boundary_option b,
00105                         vil1_convolve_boundary_option e);
00106 
00107 //: Convolution in y-direction : out(x, y) = \sum_j kernel[j]*in(x, y-j)
00108 template <class I1, class I2, class AC, class O>
00109 void vil1_convolve_1d_y(vil1_convolve_signal_1d<I1 const> const &kernel,
00110                         vil1_convolve_signal_2d<I2 const> const &input,
00111                         AC * /*accumulator type*/,
00112                         vil1_convolve_signal_2d<O> const &output,
00113                         vil1_convolve_boundary_option b,
00114                         vil1_convolve_boundary_option e);
00115 
00116 template <class I1, class I2, class AC, class O>
00117 void vil1_convolve_separable(I1 const kernel[], unsigned N,
00118                              vil1_memory_image_of<I2>& buf,
00119                              vil1_memory_image_of<AC>& tmp,
00120                              vil1_memory_image_of<O>& out);
00121 
00122 template <class I1, class I2, class AC, class O>
00123 vil1_image vil1_convolve_separable(vil1_image const& in,
00124                                    I1 const* kernel,
00125                                    int N, I2*, AC*, O*);
00126 
00127 // *** the following function is implemented in vil1_convolve_1d_x.txx
00128 
00129 //: Convolution in x-direction, using a symmetric kernel.
00130 template <class I1, class I2, class AC, class O>
00131 void vil1_convolve_1d_x(I1 const *half_kernel, unsigned kernel_size,
00132                         vil1_convolve_signal_2d<I2 const> const &input,
00133                         AC * /*accumulator type*/,
00134                         vil1_convolve_signal_2d<O> const &output,
00135                         vil1_convolve_boundary_option b,
00136                         vil1_convolve_boundary_option e);
00137 
00138 // *** the following function is implemented in vil1_convolve_1d_y.txx
00139 
00140 //: Convolution in y-direction, using a symmetric kernel.
00141 template <class I1, class I2, class AC, class O>
00142 void vil1_convolve_1d_y(I1 const *half_kernel, unsigned kernel_size,
00143                         vil1_convolve_signal_2d<I2 const> const &input,
00144                         AC * /*accumulator type*/,
00145                         vil1_convolve_signal_2d<O> const &output,
00146                         vil1_convolve_boundary_option b,
00147                         vil1_convolve_boundary_option e);
00148 
00149 #endif // vil1_convolve_h_

Generated on Sat Nov 22 05:08:29 2008 for core/vil1 by  doxygen 1.5.1