core/vil/algo/vil_binary_erode.h
Go to the documentation of this file.
00001 #ifndef vil_binary_erode_h_
00002 #define vil_binary_erode_h_
00003 //:
00004 // \file
00005 // \brief Perform binary erosion on images
00006 // \author Tim Cootes
00007 
00008 #include <vil/algo/vil_structuring_element.h>
00009 #include <vil/vil_image_view.h>
00010 #include <vil/vil_border.h>
00011 
00012 //: Return false if any im[offset[k]] is zero
00013 inline bool vil_binary_erode(const bool* im, const vcl_ptrdiff_t* offset, unsigned n)
00014 {
00015   for (unsigned i=0;i<n;++i) if (!im[offset[i]]) return false;
00016   return true;
00017 }
00018 
00019 //: Return false if any image pixel under element centred at (i0,j0) is zero
00020 //  Checks boundary overlap
00021 // \relatesalso vil_structuring_element
00022 template <class imAccessorT>
00023 inline bool vil_binary_erode(const imAccessorT& image, unsigned plane,
00024                              const vil_structuring_element& element, int i0, int j0)
00025 {
00026   unsigned n = element.p_i().size();
00027   for (unsigned int k=0;k<n;++k)
00028   {
00029     unsigned int i = i0+element.p_i()[k];
00030     unsigned int j = j0+element.p_j()[k];
00031     if (!image(i,j,plane))
00032       return false;
00033   }
00034   return true;
00035 }
00036 
00037 //: Erodes src_image to produce dest_image (assumed single plane)
00038 // \relatesalso vil_image_view
00039 // \relatesalso vil_structuring_element
00040 void vil_binary_erode(const vil_image_view<bool>& src_image,
00041                       vil_image_view<bool>& dest_image,
00042                       const vil_structuring_element& element);
00043 
00044 //: Erodes src_image to produce dest_image (assumed single plane)
00045 // \relatesalso vil_image_view
00046 // \relatesalso vil_structuring_element
00047 // \relatesalso vil_border
00048 void vil_binary_erode(const vil_image_view<bool>& src_image,
00049                       vil_image_view<bool>& dest_image,
00050                       const vil_structuring_element& element,
00051                       const vil_border<vil_image_view<bool> >& border);
00052 
00053 #endif // vil_binary_erode_h_