Go to the documentation of this file.00001 #ifndef vil_exp_grad_filter_1d_h_
00002 #define vil_exp_grad_filter_1d_h_
00003
00004
00005
00006
00007
00008 #include <vil/vil_image_view.h>
00009
00010
00011
00012
00013
00014
00015 template <class srcT, class destT, class accumT>
00016 inline void vil_exp_grad_filter_1d(const srcT* src, vcl_ptrdiff_t sstep,
00017 destT* dest, vcl_ptrdiff_t dstep,
00018 int n, accumT k)
00019 {
00020 const srcT* s = src;
00021 const srcT* src_end = src + (n-1)*sstep;
00022
00023
00024 dest[0]=0; dest+=dstep;
00025
00026
00027
00028 accumT rt= -1*(accumT) *s; s+=sstep;
00029 accumT k_sum=(accumT) 1;
00030
00031 while (s!=src_end)
00032 {
00033 *dest = (destT)(rt/k_sum);
00034 rt *= k; k_sum *= k;
00035 rt -= *s; k_sum += 1.0f;
00036 s+=sstep; dest+=dstep;
00037 }
00038
00039
00040 dest[0]=0; dest-=dstep;
00041 rt= (accumT) *s; s-=sstep;
00042 k_sum=(accumT) 1;
00043 src_end = src;
00044 while (s!=src_end)
00045 {
00046 *dest += (destT)(rt/k_sum);
00047 rt *= k; k_sum *= k;
00048 rt += *s; k_sum += 1.0f;
00049 s-=sstep; dest-=dstep;
00050 }
00051 }
00052
00053
00054
00055
00056
00057 template <class srcT, class destT, class accumT>
00058 inline void vil_exp_grad_filter_i(const vil_image_view<srcT>& src_im,
00059 vil_image_view<destT>& dest_im,
00060 accumT k)
00061 {
00062 unsigned ni = src_im.ni();
00063 unsigned nj = src_im.nj();
00064 dest_im.set_size(ni,nj,src_im.nplanes());
00065 vcl_ptrdiff_t s_istep = src_im.istep(), s_jstep = src_im.jstep();
00066 vcl_ptrdiff_t d_istep = dest_im.istep(),d_jstep = dest_im.jstep();
00067
00068 for (unsigned p=0;p<src_im.nplanes();++p)
00069 {
00070 const srcT* src_row = src_im.top_left_ptr()+p*src_im.planestep();
00071 destT* dest_row = dest_im.top_left_ptr()+p*dest_im.planestep();
00072
00073 for (unsigned j=0;j<nj;++j,src_row+=s_jstep,dest_row+=d_jstep)
00074 vil_exp_grad_filter_1d(src_row,s_istep, dest_row,d_istep, ni, k);
00075 }
00076 }
00077
00078
00079
00080
00081
00082 template <class srcT, class destT, class accumT>
00083 inline void vil_exp_grad_filter_j(const vil_image_view<srcT>& src_im,
00084 vil_image_view<destT>& dest_im,
00085 accumT k)
00086 {
00087 unsigned ni = src_im.ni();
00088 unsigned nj = src_im.nj();
00089 dest_im.set_size(ni,nj,src_im.nplanes());
00090 vcl_ptrdiff_t s_istep = src_im.istep(), s_jstep = src_im.jstep();
00091 vcl_ptrdiff_t d_istep = dest_im.istep(),d_jstep = dest_im.jstep();
00092
00093 for (unsigned p=0;p<src_im.nplanes();++p)
00094 {
00095 const srcT* src_col = src_im.top_left_ptr()+p*src_im.planestep();
00096 destT* dest_col = dest_im.top_left_ptr()+p*dest_im.planestep();
00097
00098 for (unsigned i=0;i<ni;++i,src_col+=s_istep,dest_col+=d_istep)
00099 vil_exp_grad_filter_1d(src_col,s_jstep, dest_col,d_jstep, nj, k);
00100 }
00101 }
00102
00103 #endif // vil_exp_grad_filter_1d_h_