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

Linux Cross Reference
Tina6/tina-libs/tina/vision/visMatch_efig.c

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

  1 /**********
  2  *
  3  * This file is part of the TINA Open Source Image Analysis Environment
  4  * henceforth known as TINA
  5  *
  6  * TINA is free software; you can redistribute it and/or modify
  7  * it under the terms of the GNU General Public License as
  8  * published by the Free Software Foundation.
  9  *
 10  * TINA is distributed in the hope that it will be useful,
 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  * GNU General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU General Public License
 16  * along with TINA; if not, write to the Free Software Foundation, Inc.,
 17  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  *
 19  * ANY users of TINA who require exemption from the existing licence must
 20  * negotiate a new licence with Dr. Neil.A.Thacker, the sole agent for
 21  * the University of Manchester.
 22  *
 23  **********
 24  *
 25  * Program :    TINA
 26  * File    :  $Source: /home/tina/cvs/tina-libs/tina/vision/visMatch_efig.c,v $
 27  * Date    :  $Date: 2003/10/06 12:29:47 $
 28  * Version :  $Revision: 1.3 $
 29  * CVS Id  :  $Id: visMatch_efig.c,v 1.3 2003/10/06 12:29:47 neil Exp $
 30  *
 31  * Author  : Legacy TINA
 32  *
 33  * Notes :
 34  * 
 35  * generic stereo functions for computing total figural support for each
 36  * match along an extended edge contour string support flows between
 37  * close neighbours of similar disparity
 38  * 
 39  * computationally more expensive than alternative strategy of computing
 40  * closely related same string match support
 41  *
 42  *********
 43 */
 44 
 45 #include "visMatch_efig.h"
 46 
 47 #if HAVE_CONFIG_H
 48   #include <config.h>
 49 #endif
 50 
 51 #include <math.h>
 52 #include <tina/sys/sysDef.h>
 53 #include <tina/sys/sysPro.h>
 54 #include <tina/math/mathDef.h>
 55 #include <tina/math/mathPro.h>
 56 #include <tina/geometry/geomDef.h>
 57 #include <tina/geometry/geomPro.h>
 58 #include <tina/vision/vis_MatchDef.h>
 59 #include <tina/vision/vis_MatchPro.h>
 60 
 61 #define SUPPORT_WINDOW   5      /* rasters difference for allowable
 62                                  * support */
 63 #define DISPARITY_WINDOW 3      /* disparity difference for allowable
 64                                  * support */
 65 #define GRADIENT_LIMIT 0.25     /* sq of gradient limit for allowable
 66                                  * support */
 67 
 68 /* test whether a pair of matches are compatible (figural connectivity
 69  * of one or other edge string is assumed) the test is thus a diparity
 70  * and dipsarity gradient test.
 71  * 
 72  * first identify closest ends of strings referenced through the pair of
 73  * matches and find their image coordinates
 74  * 
 75  * check the dispairt difference and gradients are within local threshold
 76  * values */
 77 static int figuraly_compatible(Match * m1, Match * m2)
 78 {
 79     List *d11;
 80     List *d12;
 81     List *d21;
 82     List *d22;
 83     Vec2    v11 = {Vec2_id};
 84     Vec2    v12 = {Vec2_id};
 85     Vec2    v21 = {Vec2_id};
 86     Vec2    v22 = {Vec2_id};
 87     double  disp, sep;          /* disparity, separation */
 88 
 89     if (es_closest_ends((Tstring *) m1->to1, (Tstring *) m2->to1, &d11, &d21) == false)
 90         return (0);
 91     if (es_closest_ends((Tstring *) m1->to2, (Tstring *) m2->to2, &d12, &d22) == false)
 92         return (0);
 93 
 94     DD_GET_POS2(d11, v11);
 95     DD_GET_POS2(d12, v12);
 96     DD_GET_POS2(d21, v21);
 97     DD_GET_POS2(d22, v22);
 98 
 99     disp = fabs((vec2_x(v12) - vec2_x(v11)) - (vec2_x(v22) - vec2_x(v21)));
100     if (disp < 1.0)
101         return (1);
102     if (disp > DISPARITY_WINDOW)
103         return (0);
104 
105     sep = vec2_sqrmod(vec2_diff(v11, v21));
106     if (((disp * disp) / sep) < GRADIENT_LIMIT)
107         return (1);
108     return (0);
109 }
110 
111 /* look back over the figural support window for the match that gives
112  * most (if any) figural support for the current match figural support
113  * is stored in the local string field of the support structure
114  * associated with a match
115  * 
116  * support is always taken from the absolute strongest supporting match in
117  * the support window, but the strength of that support is
118  * 
119  * scaled invesely with the gap in the data (no of rasters) */
120 static double supp_figural_last(Match * m, List * sptr, List * start)
121 {
122     int     i;
123 
124     if (sptr == start)
125         return (0.0);
126 
127     for (i = 0, sptr = sptr->last; i < SUPPORT_WINDOW; i++, sptr = sptr->last)
128     {
129         Tstring *sub;
130         List   *mlist;
131         List   *mptr;
132         Bool    supp_exists = false;
133         double  supp, max_supp = 0.0;
134 
135         sub = (Tstring *) sptr->to;
136         mlist = (List *) prop_get(sub->props, MLIST);
137 
138         for (mptr = mlist; mptr != NULL; mptr = mptr->next)
139         {
140             Match  *m_new;
141 
142             m_new = (Match *) mptr->to;
143             if (figuraly_compatible(m, m_new))
144             {
145                 supp_exists = true;
146                 supp = match_local_string_strength(m_new);
147                 if (supp > max_supp)
148                     max_supp = supp;
149             }
150         }
151 
152         if (supp_exists == true)
153             return (max_supp / (i + 1));
154 
155         if (sptr == start)
156             break;
157     }
158     return (0.0);
159 }
160 
161 /* look forward over the figural support window for the match that
162  * gives most (if any) figural support for the current match figural
163  * support is stored in the local string field of the support structure
164  * associated with a match
165  * 
166  * support is always taken from the absolute strongest supporting match in
167  * the support window, but the strength of that support is
168  * 
169  * scaled invesely with the gap in the data (no of rasters) */
170 static double supp_figural_next(Match * m, List * sptr, List * end)
171 {
172     int     i;
173 
174     if (sptr == end)
175         return (0.0);
176 
177     for (i = 0, sptr = sptr->next; i < SUPPORT_WINDOW; i++, sptr = sptr->next)
178     {
179         Tstring *sub;
180         List   *mlist;
181         List   *mptr;
182         Bool    supp_exists = false;
183         double  supp, max_supp = 0.0;
184 
185         sub = (Tstring *) sptr->to;
186         mlist = (List *) prop_get(sub->props, MLIST);
187 
188         for (mptr = mlist; mptr != NULL; mptr = mptr->next)
189         {
190             Match  *m_new;
191 
192             m_new = (Match *) mptr->to;
193             if (figuraly_compatible(m, m_new))
194             {
195                 supp_exists = true;
196                 supp = match_local_string_strength(m_new);
197                 if (supp > max_supp)
198                     max_supp = supp;
199             }
200         }
201 
202         if (supp_exists == true)
203             return (max_supp / (i + 1));
204 
205         if (sptr == end)
206             break;
207     }
208     return (0.0);
209 }
210 
211 /* walk along an string of sub strings accumulating figural support
212  * into the local_string field of the support structure using
213  * supp_fugural_last and the local cost funtion
214  * 
215  * now walk back accumulating support in the opposite direction in the
216  * same way using supp_fugural_next and the local cost funtion also
217  * store the combined sum in the total_string field of the support
218  * structure ARGSUSED quieten lint */
219 static void supp_figural(Tstring * str, int type, double (*cost_func) ( /* ??? */ ))
220 /* string of stereo index substrings */
221 /* not used */
222 
223 {
224     List *start;
225     List *end;
226     List *sptr;
227 
228     if (str == NULL || str->type != SINDEX)
229         return;
230 
231     start = str->start;
232     end = str->end;
233 
234     for (sptr = start;; sptr = sptr->next)
235     {
236         Tstring *sub;
237         List   *mlist;
238         List   *mptr;
239 
240         sub = (Tstring *) sptr->to;
241         mlist = (List *) prop_get(sub->props, MLIST);
242 
243         for (mptr = mlist; mptr != NULL; mptr = mptr->next)
244         {
245             Match  *m;
246             Support *s;
247 
248             m = (Match *) mptr->to;
249             s = (Support *) prop_get(m->props, MATCH_SUPPORT);
250             if (s->type <= BAD_MATCH)
251                 continue;
252             s->local_string = (float)((cost_func == NULL) ? m->weight : cost_func(m));
253             s->local_string += (float)(supp_figural_last(m, sptr, start));
254         }
255 
256         if (sptr == end)
257             break;
258     }
259 
260     for (sptr = end;; sptr = sptr->last)
261     {
262         Tstring *sub;
263         List   *mlist;
264         List   *mptr;
265 
266         sub = (Tstring *) sptr->to;
267         mlist = (List *) prop_get(sub->props, MLIST);
268 
269         for (mptr = mlist; mptr != NULL; mptr = mptr->next)
270         {
271             Match  *m;
272             Support *s;
273 
274             m = (Match *) mptr->to;
275             s = (Support *) prop_get(m->props, MATCH_SUPPORT);
276             if (s->type <= BAD_MATCH)
277                 continue;
278             s->total_string = s->local_string;
279             s->local_string = (float)supp_figural_next(m, sptr, end);
280             s->total_string += s->local_string;
281             s->local_string += (float)((cost_func == NULL) ? m->weight : cost_func(m));
282         }
283 
284         if (sptr == start)
285             break;
286     }
287 }
288 
289 /* applies figural support funtion to an edge string
290  * 
291  * first the pure edge string is converted to an equivelent string of
292  * epipolar sub-strings that were identified at during the construction
293  * of the stereo index. Matches are defined at this level.
294  * 
295  * the funtion cost_func determins the weight that is accumulated
296  * figurally */
297 void    es_figural_supp(Tstring * es, int type, double (*cost_func) ( /* ??? */ ))
298 
299 /* not used */
300 
301 {
302     es = string_of_sindex_strings(es);
303     supp_figural(es, type, cost_func);
304     str_rm_links(es);
305 }
306 

~ [ 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.