~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/vision/stereo/supp_fig.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)
  2 **/
  3 /* supp_fig.c
  4  * 
  5  * generic stereo functions for computing total figural support for each
  6  * match along an extended edge contour string support flows between
  7  * close neighbours of similar disparity
  8  * 
  9  * computationally more expensive than alternative strategy of computing
 10  * closely related same string match support */
 11 
 12 #include <math.h>
 13 #include <tina/sys.h>
 14 #include <tina/sysfuncs.h>
 15 #include <tina/math.h>
 16 #include <tina/mathfuncs.h>
 17 #include <tina/vision.h>
 18 #include <tina/visionfuncs.h>
 19 
 20 #define SUPPORT_WINDOW   5      /* rasters difference for allowable
 21                                  * support */
 22 #define DISPARITY_WINDOW 3      /* disparity difference for allowable
 23                                  * support */
 24 #define GRADIENT_LIMIT 0.25     /* sq of gradient limit for allowable
 25                                  * support */
 26 
 27 /* test whether a pair of matches are compatible (figural connectivity
 28  * of one or other edge string is assumed) the test is thus a diparity
 29  * and dipsarity gradient test.
 30  * 
 31  * first identify closest ends of strings referenced through the pair of
 32  * matches and find their image coordinates
 33  * 
 34  * check the dispairt difference and gradients are within local threshold
 35  * values */
 36 static int figuraly_compatible(Match * m1, Match * m2)
 37 {
 38     List *d11;
 39     List *d12;
 40     List *d21;
 41     List *d22;
 42     Vec2    v11 = {Vec2_id};
 43     Vec2    v12 = {Vec2_id};
 44     Vec2    v21 = {Vec2_id};
 45     Vec2    v22 = {Vec2_id};
 46     double  disp, sep;          /* disparity, separation */
 47 
 48     if (es_closest_ends((Tstring *) m1->to1, (Tstring *) m2->to1, &d11, &d21) == false)
 49         return (0);
 50     if (es_closest_ends((Tstring *) m1->to2, (Tstring *) m2->to2, &d12, &d22) == false)
 51         return (0);
 52 
 53     DD_GET_POS2(d11, v11);
 54     DD_GET_POS2(d12, v12);
 55     DD_GET_POS2(d21, v21);
 56     DD_GET_POS2(d22, v22);
 57 
 58     disp = fabs((vec2_x(v12) - vec2_x(v11)) - (vec2_x(v22) - vec2_x(v21)));
 59     if (disp < 1.0)
 60         return (1);
 61     if (disp > DISPARITY_WINDOW)
 62         return (0);
 63 
 64     sep = vec2_sqrmod(vec2_diff(v11, v21));
 65     if (((disp * disp) / sep) < GRADIENT_LIMIT)
 66         return (1);
 67     return (0);
 68 }
 69 
 70 /* look back over the figural support window for the match that gives
 71  * most (if any) figural support for the current match figural support
 72  * is stored in the local string field of the support structure
 73  * associated with a match
 74  * 
 75  * support is always taken from the absolute strongest supporting match in
 76  * the support window, but the strength of that support is
 77  * 
 78  * scaled invesely with the gap in the data (no of rasters) */
 79 static double supp_figural_last(Match * m, List * sptr, List * start)
 80 {
 81     int     i;
 82 
 83     if (sptr == start)
 84         return (0.0);
 85 
 86     for (i = 0, sptr = sptr->last; i < SUPPORT_WINDOW; i++, sptr = sptr->last)
 87     {
 88         Tstring *sub;
 89         List   *mlist;
 90         List   *mptr;
 91         Bool    supp_exists = false;
 92         double  supp, max_supp = 0.0;
 93 
 94         sub = (Tstring *) sptr->to;
 95         mlist = (List *) prop_get(sub->props, MLIST);
 96 
 97         for (mptr = mlist; mptr != NULL; mptr = mptr->next)
 98         {
 99             Match  *m_new;
100 
101             m_new = (Match *) mptr->to;
102             if (figuraly_compatible(m, m_new))
103             {
104                 supp_exists = true;
105                 supp = match_local_string_strength(m_new);
106                 if (supp > max_supp)
107                     max_supp = supp;
108             }
109         }
110 
111         if (supp_exists == true)
112             return (max_supp / (i + 1));
113 
114         if (sptr == start)
115             break;
116     }
117     return (0.0);
118 }
119 
120 /* look forward over the figural support window for the match that
121  * gives most (if any) figural support for the current match figural
122  * support is stored in the local string field of the support structure
123  * associated with a match
124  * 
125  * support is always taken from the absolute strongest supporting match in
126  * the support window, but the strength of that support is
127  * 
128  * scaled invesely with the gap in the data (no of rasters) */
129 static double supp_figural_next(Match * m, List * sptr, List * end)
130 {
131     int     i;
132 
133     if (sptr == end)
134         return (0.0);
135 
136     for (i = 0, sptr = sptr->next; i < SUPPORT_WINDOW; i++, sptr = sptr->next)
137     {
138         Tstring *sub;
139         List   *mlist;
140         List   *mptr;
141         Bool    supp_exists = false;
142         double  supp, max_supp = 0.0;
143 
144         sub = (Tstring *) sptr->to;
145         mlist = (List *) prop_get(sub->props, MLIST);
146 
147         for (mptr = mlist; mptr != NULL; mptr = mptr->next)
148         {
149             Match  *m_new;
150 
151             m_new = (Match *) mptr->to;
152             if (figuraly_compatible(m, m_new))
153             {
154                 supp_exists = true;
155                 supp = match_local_string_strength(m_new);
156                 if (supp > max_supp)
157                     max_supp = supp;
158             }
159         }
160 
161         if (supp_exists == true)
162             return (max_supp / (i + 1));
163 
164         if (sptr == end)
165             break;
166     }
167     return (0.0);
168 }
169 
170 /* walk along an string of sub strings accumulating figural support
171  * into the local_string field of the support structure using
172  * supp_fugural_last and the local cost funtion
173  * 
174  * now walk back accumulating support in the opposite direction in the
175  * same way using supp_fugural_next and the local cost funtion also
176  * store the combined sum in the total_string field of the support
177  * structure ARGSUSED quieten lint */
178 static void supp_figural(Tstring * str, int type, double (*cost_func) ( /* ??? */ ))
179 /* string of stereo index substrings */
180 /* not used */
181 
182 {
183     List *start;
184     List *end;
185     List *sptr;
186 
187     if (str == NULL || str->type != SINDEX)
188         return;
189 
190     start = str->start;
191     end = str->end;
192 
193     for (sptr = start;; sptr = sptr->next)
194     {
195         Tstring *sub;
196         List   *mlist;
197         List   *mptr;
198 
199         sub = (Tstring *) sptr->to;
200         mlist = (List *) prop_get(sub->props, MLIST);
201 
202         for (mptr = mlist; mptr != NULL; mptr = mptr->next)
203         {
204             Match  *m;
205             Support *s;
206 
207             m = (Match *) mptr->to;
208             s = (Support *) prop_get(m->props, MATCH_SUPPORT);
209             if (s->type <= BAD_MATCH)
210                 continue;
211             s->local_string = (float)((cost_func == NULL) ? m->weight : cost_func(m));
212             s->local_string += (float)(supp_figural_last(m, sptr, start));
213         }
214 
215         if (sptr == end)
216             break;
217     }
218 
219     for (sptr = end;; sptr = sptr->last)
220     {
221         Tstring *sub;
222         List   *mlist;
223         List   *mptr;
224 
225         sub = (Tstring *) sptr->to;
226         mlist = (List *) prop_get(sub->props, MLIST);
227 
228         for (mptr = mlist; mptr != NULL; mptr = mptr->next)
229         {
230             Match  *m;
231             Support *s;
232 
233             m = (Match *) mptr->to;
234             s = (Support *) prop_get(m->props, MATCH_SUPPORT);
235             if (s->type <= BAD_MATCH)
236                 continue;
237             s->total_string = s->local_string;
238             s->local_string = (float)supp_figural_next(m, sptr, end);
239             s->total_string += s->local_string;
240             s->local_string += (float)((cost_func == NULL) ? m->weight : cost_func(m));
241         }
242 
243         if (sptr == start)
244             break;
245     }
246 }
247 
248 /* applies figural support funtion to an edge string
249  * 
250  * first the pure edge string is converted to an equivelent string of
251  * epipolar sub-strings that were identified at during the construction
252  * of the stereo index. Matches are defined at this level.
253  * 
254  * the funtion cost_func determins the weight that is accumulated
255  * figurally */
256 void    es_figural_supp(Tstring * es, int type, double (*cost_func) ( /* ??? */ ))
257 
258 /* not used */
259 
260 {
261     es = string_of_sindex_strings(es);
262     supp_figural(es, type, cost_func);
263     str_rm_links(es);
264 }
265 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.