core/vil/algo/vil_greyscale_erode.h
Go to the documentation of this file.
00001 #ifndef vil_greyscale_erode_h_
00002 #define vil_greyscale_erode_h_
00003 //:
00004 // \file
00005 // \brief Perform greyscale erosion on images
00006 // \author Tim Cootes
00007 
00008 #include <vil/algo/vil_structuring_element.h>
00009 #include <vil/vil_image_view.h>
00010 
00011 //: Return minimum value of im[offset[k]]
00012 template <class T>
00013 inline T vil_greyscale_erode(const T* im, const vcl_ptrdiff_t* offset, unsigned n)
00014 {
00015   T min_v = im[offset[0]];
00016   for (unsigned i=1;i<n;++i)
00017     if (im[offset[i]]<min_v) min_v=im[offset[i]];
00018   return min_v;
00019 }
00020 
00021 //: Return max of pixels under structuring element centred at (i0,j0)
00022 //  Checks boundary overlap
00023 // \relatesalso vil_image_view
00024 // \relatesalso vil_structuring_element
00025 template <class T>
00026 inline T vil_greyscale_erode(const vil_image_view<T>& image, unsigned plane,
00027                              const vil_structuring_element& element,
00028                              int i0, int j0)
00029 {
00030   T min_v = T(0); // dummy initialisation - otherwise, compiler complains
00031   bool first=true;
00032   unsigned n = element.p_i().size();
00033   for (unsigned int k=0;k<n;++k)
00034   {
00035     unsigned int i = i0+element.p_i()[k];
00036     unsigned int j = j0+element.p_j()[k];
00037     if (i<image.ni() && j<image.nj())
00038     {
00039       if (first || image(i,j,plane) < min_v) {
00040         min_v=image(i,j,plane); first=false; }
00041     }
00042   }
00043   return min_v;
00044 }
00045 
00046 //: Erodes src_image to produce dest_image (assumed single plane).
00047 // dest_image(i0,j0) is the minimum value of the pixels under the
00048 // structuring element when it is centred on src_image(i0,j0)
00049 // \relatesalso vil_image_view
00050 // \relatesalso vil_structuring_element
00051 template <class T>
00052 void vil_greyscale_erode(const vil_image_view<T>& src_image,
00053                          vil_image_view<T>& dest_image,
00054                          const vil_structuring_element& element);
00055 
00056 #endif // vil_greyscale_erode_h_