vil_greyscale_dilate.h
Go to the documentation of this file.
1 #ifndef vil_greyscale_dilate_h_
2 #define vil_greyscale_dilate_h_
3 //:
4 // \file
5 // \brief Perform greyscale dilation on images
6 // \author Tim Cootes
7 
9 #include <vil/vil_image_view.h>
10 
11 //: Return maximum value of im[offset[k]]
12 template <class T>
13 inline T vil_greyscale_dilate(const T* im, const std::ptrdiff_t* offset, unsigned n)
14 {
15  T max_v = im[offset[0]];
16  for (unsigned i=1;i<n;++i)
17  if (im[offset[i]]>max_v) max_v=im[offset[i]];
18  return max_v;
19 }
20 
21 //: Return max of pixels under structuring element centred at (i0,j0)
22 // Checks boundary overlap. Returns 0 if structuring element is empty.
23 // \relatesalso vil_image_view
24 // \relatesalso vil_structuring_element
25 template <class T>
26 inline T vil_greyscale_dilate(const vil_image_view<T>& image, unsigned plane,
27  const vil_structuring_element& element,
28  int i0, int j0)
29 {
30  T max_v = T();
31  bool first=true;
32  unsigned n = element.p_i().size();
33  for (unsigned int k=0;k<n;++k)
34  {
35  unsigned int i = i0+element.p_i()[k];
36  unsigned int j = j0+element.p_j()[k];
37  if (i<image.ni() && j<image.nj())
38  {
39  if (first || image(i,j,plane) > max_v) {
40  max_v=image(i,j,plane); first=false; }
41  }
42  }
43  return max_v;
44 }
45 
46 //: Dilates src_image to produce dest_image (assumed single plane).
47 // dest_image(i0,j0) is the maximum value of the pixels under the
48 // structuring element when it is centred on src_image(i0,j0)
49 // \relatesalso vil_image_view
50 // \relatesalso vil_structuring_element
51 template <class T>
52 void vil_greyscale_dilate(const vil_image_view<T>& src_image,
53  vil_image_view<T>& dest_image,
54  const vil_structuring_element& element);
55 
56 #endif // vil_greyscale_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.
Concrete view of image data of type T held in memory.
Definition: vil_fwd.h:13
unsigned ni() const
Width.
unsigned nj() const
Height.
T vil_greyscale_dilate(const vil_image_view< T > &image, unsigned plane, const vil_structuring_element &element, int i0, int j0)
Return max of pixels under structuring element centred at (i0,j0).
A base class reference-counting view of some image data.
const std::vector< int > & p_i() const
i position of elements (i,j).