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