segmentation
All Data Structures Namespaces Files Functions Variables Modules Pages
BgEdgeDetect.h
1 // Name: BgEdgeDetect.h
3 // Purpose: BgEdgeDetect class
4 // Author: Bogdan Georgescu
5 // Modified by:
6 // Created: 06/22/2000
7 // Copyright: (c) Bogdan Georgescu
8 // Version: v0.1
10 
11 #define PI 3.1415926535
12 #define ZERO_TRESH 0.0000000001
13 
14 // default values for edge detection
15 #define CONF_NMX 0.5
16 #define RANK_NMX 0.5
17 #define CONF_H 0.96
18 #define RANK_H 0.93
19 #define CONF_L 0.91
20 #define RANK_L 0.99
21 #define NMIN 5
22 #define KERNEL_SIZE 2
23 
24 #define HYST_LOW_CUT 0.0
25 #define MAX_CUSTT 30
26 #define MAX_FILTS 31
27 #define NO_ANGLES 361
28 
29 #define ALF_TRESH PI/4
30 
31 static const int gNb[8][2]=
32 {
33  1, 0,
34  1, 1,
35  1,-1,
36  0, 1,
37  0,-1,
38  -1, 0,
39  -1, 1,
40  -1,-1
41 };
42 
43 static const double gAlpha[8][2]=
44 {
45  PI/2, PI/2,
46  PI/4, PI/4,
47  3*PI/4, 3*PI/4,
48  0, PI,
49  0, PI,
50  PI/2, PI/2,
51  3*PI/4, 3*PI/4,
52  PI/4, PI/4
53 };
54 
55 // main class, edge detection
56 class BgEdgeDetect
57 {
58 public:
59 
60  // main function for edge detection
61  // cim input image
62  // cel edge list (will be filled with pixels on edges)
63  // nmxr, nmxc threshold for non-maxima-suppresion rank, confidence
64  // rh, ch, threshold for hyst. high; rank, confidence
65  // rl, cl, threshold for hyst. low; rank, confidence
66  // nMin, min number of pixels on an edge
67  // nmxType, hystTypeHigh, hystTypeLow, type of nmx curve, hyst. high curve, hyst low curve
68  // in (FC_ELLIPSE, FC_VERT_LINE, FC_HORIZ_LINE, FC_LINE, FC_SQUARE_BOX, FC_CUSTOM)
69 
70  void DoEdgeDetect(BgImage* cim, BgEdgeList* cel, double nmxr, double nmxc,
71  double rh, double ch, double rl, double cl,
72  int nMin, int nmxType, int hystTypeHigh, int hystTypeLow);
73 
74  // computes confidence map and rank information of sepcified image
75  void ComputeEdgeInfo(BgImage*, float*, float*);
76 // void ComputeConfidenceMap1(BgImage*, float*);
77  // if have permanent data, call this function (compute only last two steps is same kernel size)
78  void DoRecompute(BgEdgeList*, double, double, double, double, double, double, int, int, int, int);
79 
80  BgEdgeDetect(int filtDim);
81  ~BgEdgeDetect();
82 
83  void SaveNmxValues();
84 
85  float EllipseEval(float, float);
86  float EllipseComp(float, float, float, float);
87  float LineEval(float, float);
88  float LineComp(float, float, float, float);
89  float VerticalLineEval(float, float);
90  float VerticalLineComp(float, float, float, float);
91  float HorizontalLineEval(float, float);
92  float HorizontalLineComp(float, float, float, float);
93  float SquareEval(float, float);
94  float SquareComp(float, float, float, float);
95  float CustomRegionEval(float, float);
96  float CustomRegionComp(float, float, float, float);
97 
98  void SetCustomHigh(int*, int*, int, int, int);
99  void SetCustomLow(int*, int*, int, int, int);
100  void SetCustomHigh(double*, double*, int);
101  void SetCustomLow(double*, double*, int);
102 
103  void IsGood(void);
104  void GetPixels(int*, int*, int*, double, double, double, double);
105  void GetNmxPixels(int*, int*, int*, double, double, double, double);
106 
107  double smofil_[MAX_FILTS];
108  double diffil_[MAX_FILTS];
109  double wdx_[MAX_FILTS*MAX_FILTS];
110  double wdy_[MAX_FILTS*MAX_FILTS];
111  double mN_[MAX_FILTS][MAX_FILTS];
112  double mQ_[MAX_FILTS][MAX_FILTS];
113  double* lookTable_[NO_ANGLES];
114 
115  int WW_;
116  int WL_;
117  float confTr_;
118  float rankTr_;
119 
120  float* custx_;
121  float* custy_;
122  float* tcustx_;
123  float* tcusty_;
124  int ncust_;
125 
126  float* hcustx_;
127  float* hcusty_;
128  int nhcust_;
129  float* lcustx_;
130  float* lcusty_;
131  int nlcust_;
132 
133  int x_;
134  int y_;
135  float* permConf_;
136  float* permRank_;
137  float* permNmxRank_;
138  float* permNmxConf_;
139  bool havePerm_;
140 
141 protected:
142 
143  void GenerateMaskAngle(double*, double);
144  void CreateFilters(void);
145  void CreateLookTable(void);
146  void DeleteLookTable(void);
147  void GaussFilter(BgImage*, float*, double, int);
148  void GaussDiffFilter(BgImage*, float*, float*, float*);
149  void Strength(float*, float*, float*);
150  void NewNonMaxSupress(float*, float*, float*, float*, float*, float* ,
151  float (BgEdgeDetect::*compf)(float, float, float, float));
152  void StrConfEstim(float*, float*, float*, float (BgEdgeDetect::*evalf)(float, float));
153  void CompRanks(float*, float*);
154  void NewHysteresisTr(float*, float*, BgEdgeList*, int, float*, float*);
155  void NewEdgeFollow(int, int);
156  void SubspaceEstim(float*, float*, float*, float*);
157 
158  float* te_;
159  float* tm_;
160  double low_;
161  float* tc_;
162  float* tl_;
163  int npt_;
164 
165  float* grx_;
166  float* gry_;
167  float* permGx_;
168  float* permGy_;
169 };