vil_structuring_element.h
Go to the documentation of this file.
1 #ifndef vil_structuring_element_h_
2 #define vil_structuring_element_h_
3 //:
4 // \file
5 // \brief Structuring element for morphology represented as a list of non-zero pixels
6 // \author Tim Cootes
7 
8 #include <vector>
9 #include <iosfwd>
10 #include <cstddef>
11 #ifdef _MSC_VER
12 # include <vcl_msvc_warnings.h>
13 #endif
14 
15 //: Structuring element for morphology represented as a list of non-zero pixels
16 // Elements in box bounded by [min_i(),max_i()][min_j(),max_j()]
17 // Non-zero pixels are given by (p_i[k],p_j[k])
19 {
20  //: i position of elements (i,j)
21  std::vector<int> p_i_;
22  //: j position of elements (i,j)
23  std::vector<int> p_j_;
24  //: Elements in box bounded by [min_i_,max_i_][min_j_,max_j]
25  int min_i_;
26  //: Elements in box bounded by [min_i_,max_i_][min_j_,max_j]
27  int max_i_;
28  //: Elements in box bounded by [min_i_,max_i_][min_j_,max_j]
29  int min_j_;
30  //: Elements in box bounded by [min_i_,max_i_][min_j_,max_j]
31  int max_j_;
32 
33  public:
35 
36  //: Define elements { (p_i[k],p_j[k]) }
37  vil_structuring_element(const std::vector<int>& v_p_i,const std::vector<int>& v_p_j)
38  { set(v_p_i,v_p_j); }
39 
40  //: Define elements { (p_i[k],p_j[k]) }
41  void set(const std::vector<int>& v_p_i,const std::vector<int>& v_p_j);
42 
43  //: Set to disk of radius r
44  // Select pixels in disk s.t. x^x+y^y<r^r
45  void set_to_disk(double r);
46 
47  //: Set to line along i (ilo,0)..(ihi,0)
48  void set_to_line_i(int ilo, int ihi);
49 
50  //: Set to line along j (jlo,0)..(jhi,0)
51  void set_to_line_j(int jlo, int jhi);
52 
53  //: i position of elements (i,j)
54  const std::vector<int>& p_i() const { return p_i_; }
55  //: j position of elements (i,j)
56  const std::vector<int>& p_j() const { return p_j_; }
57 
58  //: Elements in box bounded by [min_i(),max_i()][min_j(),max_j()]
59  int min_i() const { return min_i_; }
60  //: Elements in box bounded by [min_i(),max_i()][min_j(),max_j()]
61  int max_i() const { return max_i_; }
62  //: Elements in box bounded by [min_i(),max_i()][min_j(),max_j()]
63  int min_j() const { return min_j_; }
64  //: Elements in box bounded by [min_i(),max_i()][min_j(),max_j()]
65  int max_j() const { return max_j_; }
66 };
67 
68 //: Write details to stream
69 std::ostream& operator<<(std::ostream&, const vil_structuring_element& element);
70 
71 //: Generate a list of offsets for use on image with istep,jstep
72 // On exit offset[k] = element.p_i()[k]*istep + element.p_j()[k]*jstep
73 // Gives an efficient way of looping through all the pixels in the structuring element
74 void vil_compute_offsets(std::vector<std::ptrdiff_t>& offset,
75  const vil_structuring_element& element,
76  std::ptrdiff_t istep, std::ptrdiff_t jstep);
77 
78 #endif // vil_structuring_element_h_
int max_i() const
Elements in box bounded by [min_i(),max_i()][min_j(),max_j()].
const std::vector< int > & p_j() const
j position of elements (i,j).
std::vector< int > p_i_
i position of elements (i,j).
Structuring element for morphology represented as a list of non-zero pixels.
int max_j() const
Elements in box bounded by [min_i(),max_i()][min_j(),max_j()].
vil_structuring_element(const std::vector< int > &v_p_i, const std::vector< int > &v_p_j)
Define elements { (p_i[k],p_j[k]) }.
int min_i_
Elements in box bounded by [min_i_,max_i_][min_j_,max_j].
void set_to_disk(double r)
Set to disk of radius r.
int min_j_
Elements in box bounded by [min_i_,max_i_][min_j_,max_j].
int max_j_
Elements in box bounded by [min_i_,max_i_][min_j_,max_j].
void set(const std::vector< int > &v_p_i, const std::vector< int > &v_p_j)
Define elements { (p_i[k],p_j[k]) }.
void set_to_line_i(int ilo, int ihi)
Set to line along i (ilo,0)..(ihi,0).
int min_j() const
Elements in box bounded by [min_i(),max_i()][min_j(),max_j()].
std::vector< int > p_j_
j position of elements (i,j).
std::ostream & operator<<(std::ostream &, const vil_structuring_element &element)
Write details to stream.
const std::vector< int > & p_i() const
i position of elements (i,j).
int min_i() const
Elements in box bounded by [min_i(),max_i()][min_j(),max_j()].
void vil_compute_offsets(std::vector< std::ptrdiff_t > &offset, const vil_structuring_element &element, std::ptrdiff_t istep, std::ptrdiff_t jstep)
Generate a list of offsets for use on image with istep,jstep.
void set_to_line_j(int jlo, int jhi)
Set to line along j (jlo,0)..(jhi,0).
int max_i_
Elements in box bounded by [min_i_,max_i_][min_j_,max_j].