Go to the documentation of this file.00001
00002 #ifndef sdet_edgel_regions_h_
00003 #define sdet_edgel_regions_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #include <vcl_vector.h>
00052 #include <vcl_map.h>
00053 #include <vbl/vbl_array_2d.h>
00054 #include <vil1/vil1_image.h>
00055 #include <vil/vil_image_resource.h>
00056 #include <vtol/vtol_edge_2d_sptr.h>
00057 #include <gevd/gevd_bufferxy.h>
00058 #include <vtol/vtol_intensity_face_sptr.h>
00059 #include <sdet/sdet_region_edge_sptr.h>
00060
00061 class sdet_edgel_regions
00062 {
00063 public:
00064 enum RegionLabel {UNLABELED=0, EDGE, LABEL};
00065
00066 sdet_edgel_regions(int array_scale=2, bool verbose = false,
00067 bool debug = false);
00068 ~sdet_edgel_regions();
00069
00070 bool compute_edgel_regions(vil1_image const& image,
00071 vcl_vector<vtol_edge_2d_sptr>& sgrp,
00072 vcl_vector<vtol_intensity_face_sptr>& faces);
00073
00074 bool compute_edgel_regions(vil_image_resource_sptr const& image,
00075 vcl_vector<vtol_edge_2d_sptr>& sgrp,
00076 vcl_vector<vtol_intensity_face_sptr>& faces);
00077
00078
00079 bool compute_edgel_regions(gevd_bufferxy* buf,
00080 vcl_vector<vtol_edge_2d_sptr>& sgrp,
00081 vcl_vector<vtol_intensity_face_sptr>& faces);
00082
00083 void SetVerbose() { verbose_ = true; }
00084 void ClearVerbose() { verbose_ = false; }
00085 void SetDebug() { debug_ = true; }
00086 void ClearDebug() { debug_ = false; }
00087 #if 0
00088 void set_magnification(float magnification) { magnification_=magnification; }
00089 #endif // 0
00090 unsigned int BaseLabel(unsigned int label);
00091 unsigned int GetMaxRegionLabel() const { return max_region_label_; }
00092 void SetMaxRegionLabel(unsigned int label) { max_region_label_ = label; }
00093 vbl_array_2d<unsigned int> const& GetRegionArray() const { return region_label_array_; }
00094 int GetXSize() const { return xend_ - xo_ + 1; }
00095 int GetYSize() const { return yend_ - yo_ + 1; }
00096
00097 vil1_image GetEdgeImage(vcl_vector<vtol_edge_2d_sptr>& edgels);
00098 #ifdef DEBUG
00099 topo_debug_data_ref get_topo_debug_data() { return debug_data_; }
00100 #endif
00101
00102 bool InsertRegionEquivalence(unsigned int label_b, unsigned int label_a);
00103 void GrowEquivalenceClasses();
00104 void PropagateEquivalence();
00105 unsigned int GetLabel(vtol_edge_2d_sptr e, unsigned int nr) const;
00106
00107 void print_region_array();
00108 void print_region_equivalence();
00109 void print_reverse_region_equivalence();
00110 void print_base_equivalence();
00111 void print_intensity_data();
00112 protected:
00113
00114 bool GroupContainsEdges(vcl_vector<vtol_edge_2d_sptr>& sg);
00115 bool InitRegionArray(vcl_vector<vtol_edge_2d_sptr>& sg);
00116 unsigned char label_code(unsigned int label);
00117 bool add_to_forward(unsigned int key, unsigned int value);
00118 bool add_to_reverse(unsigned int key, unsigned int value);
00119 unsigned char EncodeNeighborhood(unsigned int ul, unsigned int ur,
00120 unsigned int ll, unsigned int lr);
00121 void UpdateConnectedNeighborhood(unsigned int x, unsigned int y);
00122 void AssignEdgeLabels(unsigned int x, unsigned int y);
00123 void ApplyRegionEquivalence();
00124 bool out_of_bounds(unsigned int x, unsigned int y);
00125 void insert_adjacency(unsigned int region, vtol_edge_2d_sptr e);
00126 void CollectEdges();
00127 void CollectFaceEdges();
00128 void ConstructFaces();
00129 void AccumulateMeans();
00130 void AccumulateRegionData();
00131 void InsertFaceData();
00132 unsigned int X(unsigned int x);
00133 unsigned int Y(unsigned int y);
00134 float Xf(float x);
00135 float Yf(float y);
00136 bool insert_edgel(float pre_x, float pre_y, float x, float y,
00137 sdet_region_edge_sptr const& e);
00138 void insert_equivalence(unsigned int ll, unsigned int ur, unsigned int& lr);
00139 bool merge_equivalence(vcl_map<unsigned int, vcl_vector<unsigned int>* >& tab,
00140 unsigned int cur_label,
00141 unsigned int label);
00142 bool get_next_label(vcl_vector<unsigned int>* labels,
00143 unsigned int& label);
00144 void print_edge_colis(unsigned int x, unsigned int y,
00145 sdet_region_edge_sptr const & r1,
00146 sdet_region_edge_sptr const & r2);
00147
00148 bool remove_hairs(vcl_vector<vtol_edge_2d_sptr>& edges);
00149
00150 void get_buffer_row(unsigned int row);
00151 void get_image_row(unsigned int row);
00152 unsigned short get_intensity(unsigned int x);
00153 int bytes_per_pix();
00154
00155
00156 bool compute_edgel_regions(vcl_vector<vtol_edge_2d_sptr>& sgrp,
00157 vcl_vector<vtol_intensity_face_sptr>& faces);
00158
00159
00160 bool verbose_;
00161 bool debug_;
00162 bool image_source_;
00163 bool buf_source_;
00164 int s_;
00165 vil1_image image_;
00166 gevd_bufferxy* buf_;
00167 vbl_array_2d<sdet_region_edge_sptr> edge_boundary_array_;
00168 vbl_array_2d<unsigned int> region_label_array_;
00169 unsigned int min_region_label_;
00170 unsigned int max_region_label_;
00171 float Xob_;
00172 float Yob_;
00173 unsigned int xo_;
00174 unsigned int yo_;
00175 unsigned int xend_;
00176 unsigned int yend_;
00177 unsigned int xs_;
00178 unsigned int ys_;
00179
00180 vcl_map<unsigned int, vcl_vector<unsigned int>* > region_pairs_forward_;
00181 vcl_map<unsigned int, vcl_vector<unsigned int>* > region_pairs_reverse_;
00182 vcl_map<unsigned int, vcl_vector<unsigned int>* > equivalence_set_;
00183 vcl_map<unsigned int, unsigned int > label_map_;
00184
00185 vcl_map<int, sdet_region_edge_sptr> region_edges_;
00186 vcl_map<unsigned int, vcl_vector<vtol_edge_2d_sptr>* > region_edge_adjacency_;
00187
00188 vcl_vector<vtol_intensity_face_sptr>* faces_;
00189 vtol_intensity_face_sptr* intensity_face_index_;
00190 vcl_vector<vtol_edge_2d_sptr>** face_edge_index_;
00191 vcl_vector<vtol_edge_2d_sptr>* failed_insertions_;
00192 #ifdef DEBUG
00193 topo_debug_data_ref debug_data_;
00194 #endif
00195 unsigned char* ubuf_;
00196 unsigned short* sbuf_;
00197 };
00198
00199 #endif // sdet_edgel_regions_h_