vil_find_plateaus.h
Go to the documentation of this file.
1 // This is core/vil/algo/vil_find_plateaus.h
2 #ifndef vil_find_plateaus_h_
3 #define vil_find_plateaus_h_
4 //:
5 // \file
6 // \brief Find plateau points in image. Based on vil_find_peaks.h
7 // \author Tim Cootes, Kevin de Souza
8 
9 #include <vector>
10 #include <vil/vil_image_view.h>
11 #ifdef _MSC_VER
12 # include <vcl_msvc_warnings.h>
13 #endif
14 
15 //: True if pixel at *im is greater than or equal to all 8 neighbours.
16 // \sa vil_is_peak_3x3()
17 template <class T>
18 inline bool vil_is_plateau_3x3(const T* im, std::ptrdiff_t i_step, std::ptrdiff_t j_step)
19 {
20  T v = *im;
21  return v >= im[i_step]
22  && v >= im[-i_step]
23  && v >= im[j_step]
24  && v >= im[-j_step]
25  && v >= im[i_step+j_step]
26  && v >= im[i_step-j_step]
27  && v >= im[j_step-i_step]
28  && v >= im[-i_step-j_step];
29 }
30 
31 //: Return (pi,pj) for all points in image greater than or equal to all 8 neighbours.
32 // Compute position of all local plateau points (pi[k],pj[k]) above given threshold value.
33 // \param clear_list If true (the default) then empty lists before adding new examples
34 // \sa vil_find_peaks_3x3()
35 // \relatesalso vil_image_view
36 template <class T>
37 inline void vil_find_plateaus_3x3(std::vector<unsigned>& pi,
38  std::vector<unsigned>& pj,
39  const vil_image_view<T>& image,
40  const T& min_thresh,
41  bool clear_list=true)
42 {
43  if (clear_list) {
44  pi.resize(0);
45  pj.resize(0);
46  }
47  const unsigned ni1=image.ni()-1,nj1=image.nj()-1;
48  const std::ptrdiff_t istep = image.istep(),jstep=image.jstep();
49  const T* row = image.top_left_ptr()+istep+jstep;
50  for (unsigned j=1;j<nj1;++j,row+=jstep)
51  {
52  const T* pixel = row;
53  for (unsigned i=1;i<ni1;++i,pixel+=istep)
54  if (*pixel>=min_thresh && vil_is_plateau_3x3(pixel,istep,jstep))
55  {
56  pi.push_back(i);
57  pj.push_back(j);
58  }
59  }
60 }
61 
62 #endif // vil_find_plateaus_h_
Concrete view of image data of type T held in memory.
Definition: vil_fwd.h:13
void vil_find_plateaus_3x3(std::vector< unsigned > &pi, std::vector< unsigned > &pj, const vil_image_view< T > &image, const T &min_thresh, bool clear_list=true)
Return (pi,pj) for all points in image greater than or equal to all 8 neighbours.
bool vil_is_plateau_3x3(const T *im, std::ptrdiff_t i_step, std::ptrdiff_t j_step)
True if pixel at *im is greater than or equal to all 8 neighbours.
std::ptrdiff_t jstep() const
Add this to your pixel pointer to get next j pixel.
unsigned ni() const
Width.
unsigned nj() const
Height.
#define v
A base class reference-counting view of some image data.
T * top_left_ptr()
Pointer to the first (top left in plane 0) pixel.
std::ptrdiff_t istep() const
Add this to your pixel pointer to get next i pixel.