00001
00002 #ifndef vil1_convolve_txx_
00003 #define vil1_convolve_txx_
00004
00005 #include "vil1_convolve.h"
00006 #include <vcl_iostream.h>
00007
00008 template <class I1, class I2, class AC, class O>
00009 void vil1_convolve_separable(I1 const kernel[], unsigned N,
00010 vil1_memory_image_of<I2>& buf,
00011 vil1_memory_image_of<AC>& tmp,
00012 vil1_memory_image_of<O>& out)
00013 {
00014 vil1_convolve_signal_1d<I1 const> K(kernel, 0, N/2, N);
00015 vil1_memory_image_of<I2> const& bufc = buf;
00016 vil1_memory_image_of<AC> const& tmpc = tmp;
00017
00018 unsigned w = buf.width();
00019 unsigned h = buf.height();
00020
00021 vcl_cerr << "convolve x..." << vcl_flush;
00022 vil1_convolve_1d_x(K,
00023 vil1_convolve_signal_2d<I2 const>(bufc.row_array(), 0, 0, w, 0, 0, h),
00024 (AC*)0,
00025 vil1_convolve_signal_2d<AC >(tmp.row_array(), 0, 0, w, 0, 0, h),
00026 vil1_convolve_trim, vil1_convolve_trim);
00027 vcl_cerr << "done\n"
00028 << "convolve y...";
00029 vil1_convolve_1d_y(K,
00030 vil1_convolve_signal_2d<AC const>(tmpc.row_array(), 0, 0, w, 0, 0, h),
00031 (AC*)0,
00032 vil1_convolve_signal_2d<O >(out.row_array(), 0, 0, w, 0, 0, h),
00033 vil1_convolve_trim, vil1_convolve_trim);
00034 vcl_cerr << "done\n";
00035 }
00036
00037 template <class I1, class I2, class AC, class O>
00038 vil1_image vil1_convolve_separable(vil1_image const & in,
00039 I1 const* kernel,
00040 int N, I2*, AC*, O*)
00041 {
00042
00043
00044 vil1_memory_image_of<I2> inbuf(in);
00045
00046 vil1_memory_image_of<AC> tmp(in.width(), in.height());
00047
00048 #if 0
00049
00050 vil1_image out = vil1_new(in.width(), in.height(), in);
00051 #endif
00052
00053
00054 vil1_memory_image_of<O> outbuf(in.width(), in.height());
00055
00056
00057 vil1_convolve_separable(kernel, N, inbuf, tmp, outbuf);
00058
00059 #if 0
00060
00061 if (!out.get_property("memory"))
00062 out.put_section(outbuf.get_buffer(), 0,0, out.width(), out.height());
00063 return out;
00064 #endif
00065 return outbuf;
00066 }
00067
00068
00069
00070 #undef VIL1_CONVOLVE_INSTANTIATE
00071 #define VIL1_CONVOLVE_INSTANTIATE(T) \
00072 template struct vil1_convolve_signal_1d<T >; \
00073 template struct vil1_convolve_signal_2d<T >; \
00074 template void vil1_convolve_separable(float const kernel[], unsigned N, \
00075 vil1_memory_image_of<T >& buf, \
00076 vil1_memory_image_of<double>& tmp, \
00077 vil1_memory_image_of<float>& out); \
00078 template vil1_image vil1_convolve_separable(vil1_image const& in, \
00079 float const* kernel, \
00080 int N, T*, double*, float*)
00081
00082 #endif