Go to the documentation of this file.00001
00002 #ifndef gevd_edgel_regions_h_
00003 #define gevd_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 #include <vcl_vector.h>
00048 #include <vcl_map.h>
00049
00050 #include <vtol/vtol_vertex_sptr.h>
00051 #include <vtol/vtol_edge_2d_sptr.h>
00052 #include <gevd/gevd_region_edge.h>
00053 #include <gevd/gevd_bufferxy.h>
00054 #include <vtol/vtol_intensity_face_sptr.h>
00055 #include <vil1/vil1_image.h>
00056
00057
00058 class gevd_edgel_regions
00059 {
00060 public:
00061 enum RegionLabel {UNLABELED=0, EDGE, LABEL};
00062
00063 gevd_edgel_regions(bool debug = false);
00064 ~gevd_edgel_regions();
00065
00066 bool compute_edgel_regions(vil1_image* image,
00067 vcl_vector<vtol_edge_2d_sptr>& sgrp,
00068 vcl_vector<vtol_intensity_face_sptr>& faces);
00069
00070 bool compute_edgel_regions(gevd_bufferxy* buf,
00071 vcl_vector<vtol_edge_2d_sptr>& sgrp,
00072 vcl_vector<vtol_intensity_face_sptr>& faces);
00073
00074 void SetVerbose() {verbose_ = true;}
00075 void ClearVerbose() {verbose_ = false;}
00076 void SetDebug() {debug_ = true;}
00077 void ClearDebug() {debug_ = false;}
00078 void set_magnification(float magnification){magnification_=magnification;}
00079 unsigned int BaseLabel(unsigned int label);
00080 unsigned int GetMaxRegionLabel() const {return max_region_label_;}
00081 void SetMaxRegionLabel(unsigned int label){max_region_label_ = label;}
00082 unsigned int** GetRegionArray(){return region_label_array_;}
00083 int GetXSize() const {return xend_ - xo_ + 1;}
00084 int GetYSize() const {return yend_ - yo_ + 1;}
00085 vil1_image* GetEdgeImage(vcl_vector<vtol_edge_2d_sptr>& edgels);
00086 #if 0
00087 topo_debug_data_ref get_topo_debug_data() {return debug_data_;}
00088 #endif
00089
00090 bool InsertRegionEquivalence(unsigned int label_b, unsigned int label_a);
00091 void GrowEquivalenceClasses();
00092 void PropagateEquivalence();
00093 unsigned int GetLabel(vtol_edge_2d_sptr e, unsigned int nr);
00094
00095 void print_region_array();
00096 void print_region_equivalence();
00097 void print_reverse_region_equivalence();
00098 void print_base_equivalence();
00099 void print_intensity_data();
00100 protected:
00101
00102 bool GroupContainsEdges(vcl_vector<vtol_edge_2d_sptr>& sg);
00103 bool InitRegionArray(vcl_vector<vtol_edge_2d_sptr>& sg);
00104 unsigned char label_code(unsigned int label);
00105 bool add_to_forward(unsigned int key, unsigned int value);
00106 bool add_to_reverse(unsigned int key, unsigned int value);
00107 unsigned char EncodeNeighborhood(unsigned int ul, unsigned int ur,
00108 unsigned int ll, unsigned int lr);
00109 void UpdateConnectedNeighborhood(unsigned int x, unsigned int y);
00110 void AssignEdgeLabels(unsigned int x, unsigned int y);
00111 void ApplyRegionEquivalence();
00112 bool out_of_bounds(unsigned int x, unsigned int y);
00113 void insert_adjacency(unsigned int region, vtol_edge_2d_sptr e);
00114 void CollectEdges();
00115 void CollectFaceEdges();
00116 void ConstructFaces();
00117 void AccumulateMeans();
00118 void AccumulateRegionData();
00119 void InsertFaceData();
00120 unsigned int X(unsigned int x);
00121 unsigned int Y(unsigned int y);
00122 unsigned int Xf(float x);
00123 unsigned int Yf(float y);
00124 bool insert_edgel(float pre_x, float pre_y, float x, float y,
00125 gevd_region_edge* e);
00126 void insert_equivalence(unsigned int ll, unsigned int ur, unsigned int& lr);
00127 bool merge_equivalence(vcl_map<unsigned int, vcl_vector<unsigned int>* >& tab,
00128 unsigned int cur_label,
00129 unsigned int label);
00130 bool get_next_label(vcl_vector<unsigned int>* labels,
00131 unsigned int& label);
00132 void print_edge_colis(unsigned int x, unsigned int y,
00133 gevd_region_edge* r1, gevd_region_edge* r2);
00134 bool corrupt_boundary(vcl_vector<vtol_edge_2d_sptr>& edges,
00135 vcl_vector<vtol_vertex_sptr>& bad_verts);
00136 bool remove_hairs(vcl_vector<vtol_edge_2d_sptr>& edges);
00137 bool connect_ends(vcl_vector<vtol_edge_2d_sptr>& edges,
00138 vcl_vector<vtol_vertex_sptr>& bad_verts);
00139 void repair_failed_insertions(vcl_vector<vtol_edge_2d_sptr>& edges,
00140 vcl_vector<vtol_vertex_sptr>& bad_verts);
00141 void get_buffer_row(unsigned int row);
00142 void get_image_row(unsigned int row);
00143 unsigned short get_intensity(unsigned int x);
00144 int bytes_per_pix();
00145
00146
00147 bool compute_edgel_regions(vcl_vector<vtol_edge_2d_sptr>& sgrp,
00148 vcl_vector<vtol_intensity_face_sptr>& faces);
00149
00150 bool verbose_;
00151 bool debug_;
00152 bool image_source_;
00153 bool buf_source_;
00154 float magnification_;
00155 vil1_image* image_;
00156 gevd_bufferxy* buf_;
00157 gevd_region_edge*** edge_boundary_array_;
00158 unsigned int** region_label_array_;
00159 unsigned int min_region_label_;
00160 unsigned int max_region_label_;
00161 float Xob_;
00162 float Yob_;
00163 unsigned int xo_;
00164 unsigned int yo_;
00165 unsigned int xend_;
00166 unsigned int yend_;
00167
00168 vcl_map<unsigned int, vcl_vector<unsigned int>* > region_pairs_forward_;
00169 vcl_map<unsigned int, vcl_vector<unsigned int>* > region_pairs_reverse_;
00170 vcl_map<unsigned int, vcl_vector<unsigned int>* > equivalence_set_;
00171 vcl_map<unsigned int, unsigned int > label_map_;
00172
00173 vcl_map<int, gevd_region_edge*> region_edges_;
00174 vcl_map<unsigned int, vcl_vector<vtol_edge_2d_sptr>* > region_edge_adjacency_;
00175
00176 vcl_vector<vtol_intensity_face_sptr>* faces_;
00177 vtol_intensity_face_sptr* intensity_face_index_;
00178 vcl_vector<vtol_edge_2d_sptr>** face_edge_index_;
00179 vcl_vector<vtol_edge_2d_sptr>* failed_insertions_;
00180 #if 0
00181 topo_debug_data_ref debug_data_;
00182 #endif
00183 unsigned char* ubuf_;
00184 unsigned short* sbuf_;
00185 };
00186
00187 #endif // gevd_edgel_regions_h_