Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

vil_gauss_reduce.h

Go to the documentation of this file.
00001 // This is core/vil/algo/vil_gauss_reduce.h
00002 #ifndef vil_gauss_reduce_h_
00003 #define vil_gauss_reduce_h_
00004 //:
00005 // \file
00006 // \brief Functions to smooth and sub-sample image in one direction
00007 // \author Tim Cootes
00008 // Some of these are not templated because
00009 // - Each type tends to need a slightly different implementation
00010 // - Let's not have too many templates.
00011 
00012 //Amended by Martin Roberts 15th Sep 2005
00013 //Au contraire, let's have a generic template implementation after all
00014 //The previous specific types one plane functions become template specialisations
00015 
00016 #include <vil/vil_image_view.h>
00017 #include <vxl_config.h> // for vxl_byte
00018 
00019 //: Smooth and subsample src_im to produce dest_im
00020 //  Applies 1-5-8-5-1 smoothing filter in x and y, then samples every other pixel.
00021 //  work_im provides workspace
00022 // \relates vil_image_view
00023 template<class T>
00024 void vil_gauss_reduce(const vil_image_view<T>& src,
00025                       vil_image_view<T>& dest,
00026                       vil_image_view<T>& work_im);
00027 
00028 //: Smooth and subsample src_im to produce dest_im (2/3 size)
00029 //  Applies filter in x and y, then samples every other pixel.
00030 //  work_im provides workspace
00031 // \relates vil_image_view
00032 template<class T>
00033 void vil_gauss_reduce_2_3(const vil_image_view<T>& src_im,
00034                           vil_image_view<T>& dest_im,
00035                           vil_image_view<T>& work_im);
00036 
00037 //: Smooth and subsample src_im to produce dest_im
00038 //  Applies 1-2-1 smoothing filter in x and y, then samples every other pixel.
00039 // \relates vil_image_view
00040 template<class T>
00041 void vil_gauss_reduce_121(const vil_image_view<T>& src,
00042                           vil_image_view<T>& dest);
00043 
00044 
00045 class vil_gauss_reduce_params
00046 {
00047   double scale_step_;
00048   double filt2_, filt1_, filt0_;
00049   double filt_edge2_, filt_edge1_, filt_edge0_;
00050   double filt_pen_edge2_, filt_pen_edge1_,
00051          filt_pen_edge0_, filt_pen_edge_n1_;
00052  public:
00053   explicit vil_gauss_reduce_params(double scale_step);
00054   //: the scale step between pyramid levels
00055   double scale_step() const {return scale_step_;}
00056 
00057   //: Filter tap value
00058   // The value of the two outside elements of the 5-tap 1D FIR filter
00059   double filt2() const { return filt2_;}
00060   //: Filter tap value
00061   // The value of elements 2 and 4 of the 5-tap 1D FIR filter
00062   double filt1() const { return filt1_;}
00063   //: Filter tap value
00064   // The value of the central element of the 5-tap 1D FIR filter
00065   double filt0() const { return filt0_;}
00066 
00067   //: Filter tap value
00068   // The value of the first element of the 3 tap 1D FIR filter for use at the edge of the window
00069   // Corresponds to the filt2_ elements in a symmetrical filter
00070   double filt_edge2() const { return filt_edge2_;}
00071   //: Filter tap value
00072   // The value of the second element of the 3 tap 1D FIR filter for use at the edge of the window
00073   // Corresponds to the filt1_ elements in a symmetrical filter
00074   double filt_edge1() const { return filt_edge1_;}
00075   //: Filter tap value
00076   // The value of the third element of the 3 tap 1D FIR filter for use at the edge of the window
00077   // Corresponds to the filt0_ element in a symmetrical filter
00078   double filt_edge0() const { return filt_edge0_;}
00079 
00080   //: Filter tap value
00081   // The value of the first element of the 4 tap 1D FIR filter for use 1 pixel away the edge of the window
00082   // Corresponds to the filt2_ elements in a symmetrical filter
00083   double filt_pen_edge2() const { return filt_pen_edge2_;}
00084   //: Filter tap value
00085   // The value of the second element of the 4 tap 1D FIR filter for use 1 pixel away the edge of the window
00086   // Corresponds to the filt1_ elements in a symmetrical filter
00087   double filt_pen_edge1() const { return filt_pen_edge1_;}
00088   //: Filter tap value
00089   // The value of the third element of the 4 tap 1D FIR filter for use 1 pixel away the edge of the window
00090   // Corresponds to the filt0_ elements in a symmetrical filter
00091   double filt_pen_edge0() const { return filt_pen_edge0_;}
00092   //: Filter tap value
00093   // The value of the fourth element of the 4 tap 1D FIR filter for use 1 pixel away the edge of the window
00094   // Corresponds to the filt1_ elements in a symmetrical filter
00095   double filt_pen_edge_n1() const { return filt_pen_edge_n1_;}
00096 };
00097 
00098 //: Smooth and subsample src_im by an arbitrary factor to produce dest_im
00099 // \param worka provide workspace to avoid repetitive memory alloc and free
00100 // \param workb provide workspace to avoid repetitive memory alloc and free
00101 template <class T>
00102 void vil_gauss_reduce_general(const vil_image_view<T>& src_im,
00103                               vil_image_view<T>& dest_im,
00104                               vil_image_view<T>& worka,
00105                               vil_image_view<T>& workb,
00106                               const vil_gauss_reduce_params& params);
00107 
00108 
00109 //: Smooth and subsample src_im by an arbitrary factor to produce dest_im
00110 // \relates vil_image_view
00111 template <class T>
00112 inline void vil_gauss_reduce_general(const vil_image_view<T>& src_im,
00113                                      vil_image_view<T>& dest_im,
00114                                      const vil_gauss_reduce_params& params)
00115 {
00116   vil_image_view<T> tempA, tempB;
00117   vil_gauss_reduce_general(src_im, dest_im, tempA, tempB, params);
00118 }
00119 
00120 
00121 //: Smooth and subsample single plane src_im in x to produce dest_im
00122 //  Applies 1-5-8-5-1 filter in x, then samples
00123 //  every other pixel.  Fills [0,(nx+1)/2-1][0,ny-1] elements of dest
00124 //  Assumes dest_im has sufficient data allocated.
00125 //
00126 //  This is essentially a utility function, used by mil_gauss_pyramid_builder
00127 //
00128 //  By applying twice we can obtain a full gaussian smoothed and
00129 //  sub-sampled 2D image.
00130 template <class T>
00131 void vil_gauss_reduce_1plane(const T* src_im,
00132                              unsigned src_nx, unsigned src_ny,
00133                              vcl_ptrdiff_t s_x_step, vcl_ptrdiff_t s_y_step,
00134                              T* dest_im,
00135                              vcl_ptrdiff_t d_x_step, vcl_ptrdiff_t d_y_step);
00136 
00137 //: Smooth and subsample single plane src_im in x to produce dest_im
00138 //  Applies 1-5-8-5-1 filter in x, then samples
00139 //  every other pixel.  Fills [0,(nx+1)/2-1][0,ny-1] elements of dest
00140 //  Assumes dest_im has sufficient data allocated.
00141 //
00142 //  This is essentially a utility function, used by mil_gauss_pyramid_builder
00143 //
00144 //  By applying twice we can obtain a full gaussian smoothed and
00145 //  sub-sampled 2D image
00146 VCL_DEFINE_SPECIALIZATION
00147 void vil_gauss_reduce_1plane(const vxl_byte* src_im,
00148                              unsigned src_nx, unsigned src_ny,
00149                              vcl_ptrdiff_t s_x_step, vcl_ptrdiff_t s_y_step,
00150                              vxl_byte* dest_im,
00151                              vcl_ptrdiff_t d_x_step, vcl_ptrdiff_t d_y_step);
00152 
00153 
00154 //: Smooth and subsample single plane src_im in x to produce dest_im
00155 //  Applies 1-5-8-5-1 filter in x, then samples
00156 //  every other pixel.  Fills [0,(nx+1)/2-1][0,ny-1] elements of dest
00157 //  Assumes dest_im has sufficient data allocated.
00158 //
00159 //  This is essentially a utility function, used by mil_gauss_pyramid_builder
00160 //
00161 //  By applying twice we can obtain a full gaussian smoothed and
00162 //  sub-sampled 2D image.
00163 VCL_DEFINE_SPECIALIZATION
00164 void vil_gauss_reduce_1plane(const float* src_im,
00165                              unsigned src_nx, unsigned src_ny,
00166                              vcl_ptrdiff_t s_x_step, vcl_ptrdiff_t s_y_step,
00167                              float* dest_im,
00168                              vcl_ptrdiff_t d_x_step, vcl_ptrdiff_t d_y_step);
00169 
00170 
00171 //: Smooth and subsample single plane src_im in x to produce dest_im
00172 //  Applies 1-5-8-5-1 filter in x, then samples
00173 //  every other pixel.  Fills [0,(nx+1)/2-1][0,ny-1] elements of dest
00174 //  Assumes dest_im has sufficient data allocated.
00175 //
00176 //  This is essentially a utility function, used by mil_gauss_pyramid_builder
00177 //
00178 //  By applying twice we can obtain a full gaussian smoothed and
00179 //  sub-sampled 2D image.
00180 VCL_DEFINE_SPECIALIZATION
00181 void vil_gauss_reduce_1plane(const int* src_im,
00182                              unsigned src_nx, unsigned src_ny,
00183                              vcl_ptrdiff_t s_x_step, vcl_ptrdiff_t s_y_step,
00184                              int* dest_im,
00185                              vcl_ptrdiff_t d_x_step, vcl_ptrdiff_t d_y_step);
00186 
00187 VCL_DEFINE_SPECIALIZATION
00188 void vil_gauss_reduce_1plane(const double* src_im,
00189                              unsigned src_nx, unsigned src_ny,
00190                              vcl_ptrdiff_t s_x_step, vcl_ptrdiff_t s_y_step,
00191                              double* dest_im,
00192                              vcl_ptrdiff_t d_x_step, vcl_ptrdiff_t d_y_step);
00193 
00194 
00195 
00196 //: Smooth and subsample single plane src_im in x to produce dest_im
00197 //  Applies 1-5-8-5-1 filter in x, then samples
00198 //  every other pixel.  Fills [0,(nx+1)/2-1][0,ny-1] elements of dest
00199 //  Assumes dest_im has sufficient data allocated.
00200 //
00201 //  This is essentially a utility function, used by mil_gauss_pyramid_builder
00202 //
00203 //  By applying twice we can obtain a full gaussian smoothed and
00204 //  sub-sampled 2D image.
00205 VCL_DEFINE_SPECIALIZATION
00206 void vil_gauss_reduce_1plane(const vxl_int_16* src_im,
00207                              unsigned src_nx, unsigned src_ny,
00208                              vcl_ptrdiff_t s_x_step, vcl_ptrdiff_t s_y_step,
00209                              vxl_int_16* dest_im,
00210                              vcl_ptrdiff_t d_x_step, vcl_ptrdiff_t d_y_step);
00211 
00212 //: Smooth and subsample single plane src_im in x to produce dest_im using 121 filter in x and y
00213 //  Smoothes with a 3x3 filter and subsamples
00214 template <class T>
00215 void vil_gauss_reduce_121_1plane(const T* src_im,
00216                                  unsigned src_nx, unsigned src_ny,
00217                                  vcl_ptrdiff_t s_x_step, vcl_ptrdiff_t s_y_step,
00218                                  T* dest_im,
00219                                  vcl_ptrdiff_t d_x_step, vcl_ptrdiff_t d_y_step);
00220 
00221 //: Smooth and subsample single plane src_im in x to produce dest_im using 121 filter in x and y
00222 //  Smoothes with a 3x3 filter and subsamples
00223 VCL_DEFINE_SPECIALIZATION
00224 void vil_gauss_reduce_121_1plane(const vxl_byte* src_im,
00225                                  unsigned src_nx, unsigned src_ny,
00226                                  vcl_ptrdiff_t s_x_step, vcl_ptrdiff_t s_y_step,
00227                                  vxl_byte* dest_im,
00228                                  vcl_ptrdiff_t d_x_step, vcl_ptrdiff_t d_y_step);
00229 
00230 //: Smooth and subsample single plane src_im in x to produce dest_im using 121 filter in x and y
00231 //  Smoothes with a 3x3 filter and subsamples
00232 VCL_DEFINE_SPECIALIZATION
00233 void vil_gauss_reduce_121_1plane(const float* src_im,
00234                                  unsigned src_nx, unsigned src_ny,
00235                                  vcl_ptrdiff_t s_x_step, vcl_ptrdiff_t s_y_step,
00236                                  float* dest_im,
00237                                  vcl_ptrdiff_t d_x_step, vcl_ptrdiff_t d_y_step);
00238 
00239 //: Smooth and subsample single plane src_im in x to produce dest_im using 121 filter in x and y
00240 //  Smoothes with a 3x3 filter and subsamples
00241 VCL_DEFINE_SPECIALIZATION
00242 void vil_gauss_reduce_121_1plane(const int* src_im,
00243                                  unsigned src_nx, unsigned src_ny,
00244                                  vcl_ptrdiff_t s_x_step, vcl_ptrdiff_t s_y_step,
00245                                  int* dest_im,
00246                                  vcl_ptrdiff_t d_x_step, vcl_ptrdiff_t d_y_step);
00247 VCL_DEFINE_SPECIALIZATION
00248 void vil_gauss_reduce_121_1plane(const double* src_im,
00249                                  unsigned src_nx, unsigned src_ny,
00250                                  vcl_ptrdiff_t s_x_step, vcl_ptrdiff_t s_y_step,
00251                                  double* dest_im,
00252                                  vcl_ptrdiff_t d_x_step, vcl_ptrdiff_t d_y_step);
00253 
00254 
00255 
00256 //: Smooth and subsample single plane src_im in x to produce dest_im using 121 filter in x and y
00257 //  Smoothes with a 3x3 filter and subsamples
00258 VCL_DEFINE_SPECIALIZATION
00259 void vil_gauss_reduce_121_1plane(const vxl_int_16* src_im,
00260                                  unsigned src_nx, unsigned src_ny,
00261                                  vcl_ptrdiff_t s_x_step, vcl_ptrdiff_t s_y_step,
00262                                  vxl_int_16* dest_im,
00263                                  vcl_ptrdiff_t d_x_step, vcl_ptrdiff_t d_y_step);
00264 //: Smooth and subsample single plane src_im in x, result is 2/3rd size
00265 //  Applies alternate 1-3-1, 1-1 filter in x, then samples
00266 //  every other pixel.  Fills [0,(2*ni+1)/3-1][0,nj-1] elements of dest
00267 //
00268 //  Note, 131 filter only an approximation
00269 template <class T>
00270 void vil_gauss_reduce_2_3_1plane(const T* src_im,
00271                                  unsigned src_ni, unsigned src_nj,
00272                                  vcl_ptrdiff_t s_x_step, vcl_ptrdiff_t s_y_step,
00273                                  T* dest_im, vcl_ptrdiff_t d_x_step, vcl_ptrdiff_t d_y_step);
00274 
00275 //: Smooth and subsample single plane src_im in x, result is 2/3rd size
00276 //  Applies alternate 1-3-1, 1-1 filter in x, then samples
00277 //  every other pixel.  Fills [0,(2*ni+1)/3-1][0,nj-1] elements of dest
00278 //
00279 //  Note, 131 filter only an approximation
00280 VCL_DEFINE_SPECIALIZATION
00281 void vil_gauss_reduce_2_3_1plane(const vxl_byte* src_im,
00282                                  unsigned src_ni, unsigned src_nj,
00283                                  vcl_ptrdiff_t s_x_step, vcl_ptrdiff_t s_y_step,
00284                                  vxl_byte* dest_im, vcl_ptrdiff_t d_x_step, vcl_ptrdiff_t d_y_step);
00285 
00286 //: Smooth and subsample single plane src_im in x, result is 2/3rd size
00287 //  Applies alternate 1-3-1, 1-1 filter in x, then samples
00288 //  every other pixel.  Fills [0,(2*ni+1)/3-1][0,nj-1] elements of dest
00289 //
00290 //  Note, 131 filter only an approximation
00291 VCL_DEFINE_SPECIALIZATION
00292 void vil_gauss_reduce_2_3_1plane(const int* src_im,
00293                                  unsigned src_ni, unsigned src_nj,
00294                                  vcl_ptrdiff_t s_x_step, vcl_ptrdiff_t s_y_step,
00295                                  int* dest_im, vcl_ptrdiff_t d_x_step, vcl_ptrdiff_t d_y_step);
00296 
00297 //: Smooth and subsample single plane src_im in x, result is 2/3rd size
00298 //  Applies alternate 1-3-1, 1-1 filter in x, then samples
00299 //  every other pixel.  Fills [0,(2*ni+1)/3-1][0,nj-1] elements of dest
00300 //
00301 //  Note, 131 filter only an approximation
00302 VCL_DEFINE_SPECIALIZATION
00303 void vil_gauss_reduce_2_3_1plane(const vxl_int_16* src_im,
00304                                  unsigned src_ni, unsigned src_nj,
00305                                  vcl_ptrdiff_t s_x_step, vcl_ptrdiff_t s_y_step,
00306                                  vxl_int_16* dest_im, vcl_ptrdiff_t d_x_step, vcl_ptrdiff_t d_y_step);
00307 
00308 //: Smooth and subsample single plane src_im in x, result is 2/3rd size
00309 //  Applies alternate 1-3-1, 1-1 filter in x, then samples
00310 //  every other pixel.  Fills [0,(2*ni+1)/3-1][0,nj-1] elements of dest
00311 //
00312 //  Note, 131 filter only an approximation
00313 VCL_DEFINE_SPECIALIZATION
00314 void vil_gauss_reduce_2_3_1plane(const float* src_im,
00315                                  unsigned src_ni, unsigned src_nj,
00316                                  vcl_ptrdiff_t s_x_step, vcl_ptrdiff_t s_y_step,
00317                                  float* dest_im, vcl_ptrdiff_t d_x_step, vcl_ptrdiff_t d_y_step);
00318 
00319 //: Smooth and subsample single plane src_im in x, result is 2/3rd size
00320 //  Applies alternate 1-3-1, 1-1 filter in x, then samples
00321 //  every other pixel.  Fills [0,(2*ni+1)/3-1][0,nj-1] elements of dest
00322 //
00323 //  Note, 131 filter only an approximation
00324 VCL_DEFINE_SPECIALIZATION
00325 void vil_gauss_reduce_2_3_1plane(const double* src_im,
00326                                  unsigned src_ni, unsigned src_nj,
00327                                  vcl_ptrdiff_t s_x_step, vcl_ptrdiff_t s_y_step,
00328                                  double* dest_im, vcl_ptrdiff_t d_x_step, vcl_ptrdiff_t d_y_step);
00329 
00330 #endif // vil_gauss_reduce_h_

Generated on Thu Jan 10 14:39:59 2008 for core/vil by  doxygen 1.4.4