vil_suppress_non_plateau.h
Go to the documentation of this file.
1 // This is core/vil/algo/vil_suppress_non_plateau.h
2 #ifndef vil_suppress_non_plateau_h_
3 #define vil_suppress_non_plateau_h_
4 //:
5 // \file
6 // \brief Suppress all non-plateau points in image
7 // \author Tim Cootes, Kevin de Souza
8 
9 #include <vil/vil_image_view.h>
11 #include <vil/vil_fill.h>
12 #include <cassert>
13 #ifdef _MSC_VER
14 # include <vcl_msvc_warnings.h>
15 #endif
16 
17 //: Suppress all non-plateau pixels in the image.
18 // If image(i,j) is greater than or equal to all neighbouring pixels,
19 // and is above the threshold, then it is retained. All other
20 // pixels are set to non_max_value.
21 //
22 // non_max_value must be below the threshold (so the default value of
23 // zero is inappropriate if the image contains plateaus of interest with
24 // negative values)
25 //
26 // \sa vil_suppress_non_max_3x3()
27 // \relatesalso vil_image_view
28 template <class T>
30  vil_image_view<T>& dest_im,
31  T threshold=0, T non_max_value=0)
32 {
33  unsigned ni=src_im.ni(),nj=src_im.nj();
34  assert(src_im.nplanes()==1);
35 
36  dest_im.set_size(ni,nj,1);
37 
38  std::ptrdiff_t istep = src_im.istep(),jstep=src_im.jstep();
39  std::ptrdiff_t distep = dest_im.istep(),djstep=dest_im.jstep();
40  const T* row = src_im.top_left_ptr()+istep+jstep;
41  T* drow = dest_im.top_left_ptr()+distep+djstep;
42  for (unsigned j=1;j<nj-1;++j,row+=jstep,drow+=djstep)
43  {
44  const T* pixel = row;
45  T* dpixel = drow;
46  for (unsigned i=1;i<ni-1;++i,pixel+=istep,dpixel+=distep)
47  {
48  if (*pixel<threshold || !vil_is_plateau_3x3(pixel,istep,jstep))
49  *dpixel = non_max_value;
50  else
51  *dpixel = *pixel;
52  }
53  }
54 
55  // Border pixels assumed not to be local plateaus
56  vil_fill_row(dest_im,0,non_max_value);
57  vil_fill_row(dest_im,nj-1,non_max_value);
58  vil_fill_col(dest_im,0,non_max_value);
59  vil_fill_col(dest_im,ni-1,non_max_value);
60 }
61 
62 #endif // vil_suppress_non_plateau_h_
Various functions for manipulating image views.
Concrete view of image data of type T held in memory.
Definition: vil_fwd.h:13
void set_size(unsigned ni, unsigned nj) override
resize current planes to ni x nj.
Find plateau points in image.
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.
void vil_fill_col(vil_image_view< T > &view, unsigned i, T value)
Fill column i in view with given value.
Definition: vil_fill.h:148
unsigned ni() const
Width.
unsigned nj() const
Height.
A base class reference-counting view of some image data.
T * top_left_ptr()
Pointer to the first (top left in plane 0) pixel.
unsigned nplanes() const
Number of planes.
void vil_suppress_non_plateau_3x3(const vil_image_view< T > &src_im, vil_image_view< T > &dest_im, T threshold=0, T non_max_value=0)
Suppress all non-plateau pixels in the image.
std::ptrdiff_t istep() const
Add this to your pixel pointer to get next i pixel.
void vil_fill_row(vil_image_view< T > &view, unsigned j, T value)
Fill row j in view with given value.
Definition: vil_fill.h:133