core/vil/algo/vil_structuring_element.h
Go to the documentation of this file.
00001 #ifndef vil_structuring_element_h_
00002 #define vil_structuring_element_h_
00003 //:
00004 // \file
00005 // \brief Structuring element for morphology represented as a list of non-zero pixels
00006 // \author Tim Cootes
00007 
00008 #include <vcl_vector.h>
00009 #include <vcl_iosfwd.h>
00010 #include <vcl_cstddef.h>
00011 
00012 //: Structuring element for morphology represented as a list of non-zero pixels
00013 // Elements in box bounded by [min_i(),max_i()][min_j(),max_j()]
00014 // Non-zero pixels are given by (p_i[k],p_j[k])
00015 class vil_structuring_element
00016 {
00017   //: i position of elements (i,j)
00018   vcl_vector<int> p_i_;
00019   //: j position of elements (i,j)
00020   vcl_vector<int> p_j_;
00021   //: Elements in box bounded by [min_i_,max_i_][min_j_,max_j]
00022   int min_i_;
00023   //: Elements in box bounded by [min_i_,max_i_][min_j_,max_j]
00024   int max_i_;
00025   //: Elements in box bounded by [min_i_,max_i_][min_j_,max_j]
00026   int min_j_;
00027   //: Elements in box bounded by [min_i_,max_i_][min_j_,max_j]
00028   int max_j_;
00029 
00030  public:
00031   vil_structuring_element() : min_i_(0),max_i_(-1),min_j_(0),max_j_(-1) {}
00032 
00033   //: Define elements { (p_i[k],p_j[k]) }
00034   vil_structuring_element(const vcl_vector<int>& v_p_i,const vcl_vector<int>& v_p_j)
00035   { set(v_p_i,v_p_j); }
00036 
00037   //: Define elements { (p_i[k],p_j[k]) }
00038   void set(const vcl_vector<int>& v_p_i,const vcl_vector<int>& v_p_j);
00039 
00040   //: Set to disk of radius r
00041   //  Select pixels in disk s.t. x^x+y^y<r^r
00042   void set_to_disk(double r);
00043 
00044   //: Set to line along i (ilo,0)..(ihi,0)
00045   void set_to_line_i(int ilo, int ihi);
00046 
00047   //: Set to line along j (jlo,0)..(jhi,0)
00048   void set_to_line_j(int jlo, int jhi);
00049 
00050   //: i position of elements (i,j)
00051   const vcl_vector<int>& p_i() const { return p_i_; }
00052   //: j position of elements (i,j)
00053   const vcl_vector<int>& p_j() const { return p_j_; }
00054 
00055   //: Elements in box bounded by [min_i(),max_i()][min_j(),max_j()]
00056   int min_i() const { return min_i_; }
00057   //: Elements in box bounded by [min_i(),max_i()][min_j(),max_j()]
00058   int max_i() const { return max_i_; }
00059   //: Elements in box bounded by [min_i(),max_i()][min_j(),max_j()]
00060   int min_j() const { return min_j_; }
00061   //: Elements in box bounded by [min_i(),max_i()][min_j(),max_j()]
00062   int max_j() const { return max_j_; }
00063 };
00064 
00065 //: Write details to stream
00066 vcl_ostream& operator<<(vcl_ostream&, const vil_structuring_element& element);
00067 
00068 //: Generate a list of offsets for use on image with istep,jstep
00069 //  On exit offset[k] = element.p_i()[k]*istep +  element.p_j()[k]*jstep
00070 //  Gives an efficient way of looping through all the pixels in the structuring element
00071 void vil_compute_offsets(vcl_vector<vcl_ptrdiff_t>& offset,
00072                          const vil_structuring_element& element,
00073                          vcl_ptrdiff_t istep, vcl_ptrdiff_t jstep);
00074 
00075 #endif // vil_structuring_element_h_