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

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

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