vil_binary_erode.h
Go to the documentation of this file.
1 #ifndef vil_binary_erode_h_
2 #define vil_binary_erode_h_
3 //:
4 // \file
5 // \brief Perform binary erosion on images
6 // \author Tim Cootes
7 
9 #include <vil/vil_image_view.h>
10 #include <vil/vil_border.h>
11 
12 //: Return false if any im[offset[k]] is zero
13 inline bool vil_binary_erode(const bool* im, const std::ptrdiff_t* offset, unsigned n)
14 {
15  for (unsigned i=0;i<n;++i) if (!im[offset[i]]) return false;
16  return true;
17 }
18 
19 //: Return false if any image pixel under element centred at (i0,j0) is zero
20 // Checks boundary overlap
21 // \relatesalso vil_structuring_element
22 template <class imAccessorT>
23 inline bool vil_binary_erode(const imAccessorT& image, unsigned plane,
24  const vil_structuring_element& element, int i0, int j0)
25 {
26  unsigned n = element.p_i().size();
27  for (unsigned int k=0;k<n;++k)
28  {
29  unsigned int i = i0+element.p_i()[k];
30  unsigned int j = j0+element.p_j()[k];
31  if (!image(i,j,plane))
32  return false;
33  }
34  return true;
35 }
36 
37 //: Erodes src_image to produce dest_image (assumed single plane)
38 // \relatesalso vil_image_view
39 // \relatesalso vil_structuring_element
40 void vil_binary_erode(const vil_image_view<bool>& src_image,
41  vil_image_view<bool>& dest_image,
42  const vil_structuring_element& element);
43 
44 //: Erodes src_image to produce dest_image (assumed single plane)
45 // \relatesalso vil_image_view
46 // \relatesalso vil_structuring_element
47 // \relatesalso vil_border
48 void vil_binary_erode(const vil_image_view<bool>& src_image,
49  vil_image_view<bool>& dest_image,
50  const vil_structuring_element& element,
51  const vil_border<vil_image_view<bool> >& border);
52 
53 #endif // vil_binary_erode_h_
Structuring element for morphology represented as a list of non-zero pixels.
const std::vector< int > & p_j() const
j position of elements (i,j).
Structuring element for morphology represented as a list of non-zero pixels.
Border handling for images.
Border class. Makes pixel access outside image range transparent and configurable.
Definition: vil_border.h:37
bool vil_binary_erode(const imAccessorT &image, unsigned plane, const vil_structuring_element &element, int i0, int j0)
Return false if any image pixel under element centred at (i0,j0) is zero.
A base class reference-counting view of some image data.
const std::vector< int > & p_i() const
i position of elements (i,j).