core/vil/algo/vil_greyscale_dilate.h
Go to the documentation of this file.
00001 #ifndef vil_greyscale_dilate_h_
00002 #define vil_greyscale_dilate_h_
00003 //:
00004 // \file
00005 // \brief Perform greyscale dilation 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 maximum value of im[offset[k]]
00012 template <class T>
00013 inline T vil_greyscale_dilate(const T* im, const vcl_ptrdiff_t* offset, unsigned n)
00014 {
00015   T max_v = im[offset[0]];
00016   for (unsigned i=1;i<n;++i)
00017     if (im[offset[i]]>max_v) max_v=im[offset[i]];
00018   return max_v;
00019 }
00020 
00021 //: Return max of pixels under structuring element centred at (i0,j0)
00022 //  Checks boundary overlap.  Returns 0 if structuring element is empty.
00023 // \relatesalso vil_image_view
00024 // \relatesalso vil_structuring_element
00025 template <class T>
00026 inline T vil_greyscale_dilate(const vil_image_view<T>& image, unsigned plane,
00027                               const vil_structuring_element& element,
00028                               int i0, int j0)
00029 {
00030   T max_v = T();
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) > max_v) {
00040         max_v=image(i,j,plane); first=false; }
00041     }
00042   }
00043   return max_v;
00044 }
00045 
00046 //: Dilates src_image to produce dest_image (assumed single plane).
00047 // dest_image(i0,j0) is the maximum 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_dilate(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_dilate_h_