00001
00002 #ifndef vil_gauss_filter_h_
00003 #define vil_gauss_filter_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <vcl_vector.h>
00013 #include <vil/vil_image_view.h>
00014 #include <vil/algo/vil_convolve_1d.h>
00015 #include <vil/vil_transpose.h>
00016
00017 class vil_gauss_filter_5tap_params
00018 {
00019 double sigma_;
00020 double filt2_, filt1_, filt0_;
00021 double filt_edge2_, filt_edge1_, filt_edge0_;
00022 double filt_pen_edge2_, filt_pen_edge1_,
00023 filt_pen_edge0_, filt_pen_edge_n1_;
00024 public:
00025
00026 explicit vil_gauss_filter_5tap_params(double sigma_);
00027
00028 double sigma() const {return sigma_;}
00029
00030
00031
00032 double filt2() const { return filt2_;}
00033
00034
00035 double filt1() const { return filt1_;}
00036
00037
00038 double filt0() const { return filt0_;}
00039
00040
00041
00042
00043 double filt_edge2() const { return filt_edge2_;}
00044
00045
00046
00047 double filt_edge1() const { return filt_edge1_;}
00048
00049
00050
00051 double filt_edge0() const { return filt_edge0_;}
00052
00053
00054
00055
00056 double filt_pen_edge2() const { return filt_pen_edge2_;}
00057
00058
00059
00060 double filt_pen_edge1() const { return filt_pen_edge1_;}
00061
00062
00063
00064 double filt_pen_edge0() const { return filt_pen_edge0_;}
00065
00066
00067
00068 double filt_pen_edge_n1() const { return filt_pen_edge_n1_;}
00069 };
00070
00071
00072
00073
00074
00075 template <class srcT, class destT>
00076 void vil_gauss_filter_5tap(const srcT* src_im, vcl_ptrdiff_t src_ystep,
00077 unsigned ni, unsigned nj,
00078 destT* dest_im, vcl_ptrdiff_t dest_ystep,
00079 const vil_gauss_filter_5tap_params& params,
00080 destT* work);
00081
00082
00083
00084 template <class srcT, class destT>
00085 void vil_gauss_filter_5tap(const vil_image_view<srcT>& src_im,
00086 vil_image_view<destT>& dest_im,
00087 const vil_gauss_filter_5tap_params ¶ms,
00088 vil_image_view<destT> &work);
00089
00090
00091
00092
00093 template <class srcT, class destT>
00094 inline void vil_gauss_filter_5tap(const vil_image_view<srcT>& src_im,
00095 vil_image_view<destT>& dest_im,
00096 const vil_gauss_filter_5tap_params ¶ms)
00097 {
00098 vil_image_view<destT> work;
00099 vil_gauss_filter_5tap(src_im, dest_im, params, work);
00100 }
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 void vil_gauss_filter_gen_ntap(double sd, unsigned diff,
00116 vcl_vector<double> &filter_dest);
00117
00118
00119
00120
00121
00122 template <class srcT, class destT>
00123 inline void vil_gauss_filter_1d(const vil_image_view<srcT>& src_im,
00124 vil_image_view<destT>& dest_im,
00125 double sd, unsigned half_width)
00126 {
00127 vcl_vector<double> filter(2*half_width+1);
00128 vil_gauss_filter_gen_ntap(sd,0,filter);
00129 vil_convolve_1d(src_im,dest_im,&filter[half_width],-int(half_width),half_width,
00130 float(),vil_convolve_zero_extend,vil_convolve_zero_extend);
00131 }
00132
00133
00134
00135
00136
00137
00138 template <class srcT, class destT>
00139 inline void vil_gauss_filter_2d(const vil_image_view<srcT>& src_im,
00140 vil_image_view<destT>& dest_im,
00141 double sd, unsigned half_width,
00142 vil_convolve_boundary_option boundary = vil_convolve_zero_extend)
00143 {
00144
00145 vcl_vector<double> filter(2*half_width+1);
00146 vil_gauss_filter_gen_ntap(sd,0,filter);
00147
00148
00149 vil_image_view<destT> work_im;
00150 vil_convolve_1d(src_im,work_im,&filter[half_width],-int(half_width),half_width,
00151 float(), boundary, boundary);
00152
00153
00154 dest_im.set_size(src_im.ni(),src_im.nj(),src_im.nplanes());
00155 vil_image_view<destT> work_im_t = vil_transpose(work_im);
00156 vil_image_view<destT> dest_im_t = vil_transpose(dest_im);
00157
00158 vil_convolve_1d(work_im_t,dest_im_t,
00159 &filter[half_width],-int(half_width),half_width,
00160 float(), boundary, boundary);
00161 }
00162
00163 #endif // vil_gauss_filter_h_