vil_binary_dilate.h
Go to the documentation of this file.
1 #ifndef vil_binary_dilate_h_
2 #define vil_binary_dilate_h_
3 //:
4 // \file
5 // \brief Perform binary dilation on images
6 // \author Tim Cootes
7 
9 #include <vil/vil_image_view.h>
10 #include <vil/vil_border.h>
11 
12 //: Return true if any im[offset[k]] is non-zero
13 inline bool vil_binary_dilate(const bool* im, const std::ptrdiff_t* offset, unsigned n)
14 {
15  for (unsigned i=0;i<n;++i) if (im[offset[i]]) return true;
16  return false;
17 }
18 
19 //: Return true if any image pixel under element centred at (i0,j0) is non-zero
20 // Checks boundary overlap
21 // \relatesalso vil_structuring_element
22 template <class imAccessorT>
23 inline bool vil_binary_dilate(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 true;
33  }
34  return false;
35 }
36 
37 //: Dilates src_image to produce dest_image (assumed single plane)
38 // \relatesalso vil_image_view
39 // \relatesalso vil_structuring_element
40 void vil_binary_dilate(const vil_image_view<bool>& src_image,
41  vil_image_view<bool>& dest_image,
42  const vil_structuring_element& element);
43 
44 //: Dilates 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_dilate(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_dilate_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_dilate(const imAccessorT &image, unsigned plane, const vil_structuring_element &element, int i0, int j0)
Return true if any image pixel under element centred at (i0,j0) is non-zero.
A base class reference-counting view of some image data.
const std::vector< int > & p_i() const
i position of elements (i,j).