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

Linux Cross Reference
Tina5/tina-libs/tina/vision/visMatch_estr.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_estr.c,v $
 23  * Date    :  $Date: 2003/10/06 12:29:48 $
 24  * Version :  $Revision: 1.3 $
 25  * CVS Id  :  $Id: visMatch_estr.c,v 1.3 2003/10/06 12:29:48 neil Exp $
 26  *
 27  * Author  : Legacy TINA
 28  *
 29  * Notes :
 30  * 
 31  * generic stereo functions for computing support between complete edge
 32  * strings
 33  * 
 34  * the strings must already be referenced through the property list of
 35  * each edge using the key STRING
 36  * 
 37  * this approach is used to compute the strict figural continuity support.
 38  * That is, the sum of support from valid matches that exist between a
 39  * pair of uniquely labled sub-strings.
 40  *
 41  *********
 42 */
 43 
 44 #include "visMatch_estr.h"
 45 
 46 #if HAVE_CONFIG_H
 47   #include <config.h>
 48 #endif
 49 
 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 /* make an example of a string match */
 62 String_match *sm_make(Tstring * s1, Tstring * s2, int s1_id, int s2_id)
 63 {
 64     String_match *sm = ts_ralloc(String_match);
 65 
 66     sm->s1 = s1;
 67     sm->s2 = s2;
 68     sm->s1_id = s1_id;
 69     sm->s2_id = s2_id;
 70     sm->support = 0;
 71     sm->r_low = sm->r_up = 0;
 72 
 73     return (sm);
 74 }
 75 
 76 /* free a list of string matches */
 77 void    sm_list_rm(List * sm_list)
 78 {
 79     list_rm(sm_list, rfree);
 80 }
 81 
 82 /* initialise values in a string match */
 83 static void sm_init_sup(String_match * sm)
 84 {
 85     if (sm == NULL)
 86         return;
 87 
 88     sm->support = 0;
 89 }
 90 
 91 
 92 /* search list of string matches for one with given pair of edge
 93  * sub-string identifiers
 94  * 
 95  * if no such string match exists return NULL */
 96 String_match *str_mat_from_list(List * mlist, int s1_id, int s2_id)
 97 {
 98     List   *ptr;
 99 
100     for (ptr = mlist; ptr != NULL; ptr = ptr->next)
101         if (s1_id == ptr->type && s2_id == ((String_match *) ptr->to)->s2_id)
102             return ((String_match *) ptr->to);
103     return (NULL);
104 }
105 
106 /* initialise edge string match string lists */
107 void    es_match_string_init(Tstring * es)
108 {
109     if (es == NULL)
110         return;
111     es->props = proplist_addifnp(es->props, NULL, MLIST,
112                                  (void (*) ()) NULL, true);
113 }
114 
115 /* accumulate matches and support for an individual edge contour string
116  * into list of string matches of uniquely labled sub-parts add it to
117  * the property list of the global string
118  * 
119  * uniquely labled sub-strings correspond to those string parts that cross
120  * a set of epipolars/rasters only once (eg strings are implicitly
121  * broken at turning points in the y direction). These labels are
122  * indexed through the property luists of the epipolar sub-strings
123  * using the key STRING.
124  * 
125  * examines the matches of the component epipolar sub-strings */
126 /* ARGSUSED quieten lint */
127 void    es_match_string(Tstring * es, int type, double (*cost_func) ( /* ??? */ ))
128 
129 /* unused */
130 
131 {
132     List   *matches;            /* list of string matches */
133     Tstring *ses;               /* string of sub strings */
134     List *sptr;
135     List *start;
136     List *end;
137     int     s1_id, s2_id;
138 
139     ses = string_of_sindex_strings(es);
140 
141     if (ses == NULL)
142         return;
143 
144     start = ses->start;
145     end = ses->end;
146 
147     matches = (List *) prop_get(es->props, MLIST);
148     list_apply_func(matches, sm_init_sup, NULL);
149 
150     for (sptr = start; sptr != end; sptr = sptr->next)
151     {
152         Tstring *s1;
153         List   *mlist;
154         List   *mptr;
155         int     r;
156         Vec2    v = {Vec2_id};
157 
158 
159         s1 = (Tstring *) sptr->to;
160         mlist = (List *) prop_get(s1->props, MLIST);
161         s1_id = (int) prop_get(s1->props, STRING);
162 
163         v = str2_centroid(s1);
164         r = (int)floor(vec2_y(v));
165 
166         for (mptr = mlist; mptr != NULL; mptr = mptr->next)
167         {
168             Match  *m = (Match *) mptr->to;
169             Tstring *s2;
170             String_match *sm;
171 
172             s2 = (Tstring *) m->to2;
173             s2_id = (int) prop_get(s2->props, STRING);
174             if ((sm = str_mat_from_list(matches, s1_id, s2_id)) == NULL)
175             {
176                 Edgel  *edge = (Edgel *) s2->start->to;
177 
178                 sm = sm_make(es, (Tstring *) prop_get(edge->props, STRING), s1_id, s2_id);
179                 matches = ref_addtostart((List *) matches, (void *) sm, s1_id);
180                 sm->r_low = sm->r_up = r;
181             }
182             if (r < sm->r_low)
183                 sm->r_low = r;
184             if (r > sm->r_up)
185                 sm->r_up = r;
186 
187             if (cost_func == NULL)
188             {
189                 Support *s = (Support *) prop_get(m->props, MATCH_SUPPORT);
190 
191                 if (s == NULL || s->type <= BAD_MATCH)
192                     continue;
193                 sm->support += ((Match *) mptr->to)->weight;
194             } else
195                 sm->support += cost_func(m);
196         }
197         if (sptr == end)
198             break;
199     }
200     es->props = proplist_addifnp(es->props, (void *) matches, MLIST, sm_list_rm, false);
201     str_rm_links(ses);
202 }
203 
204 /* set the total string support for matches associated with epipolar
205  * sub-strings of an edge contour from the string matches of the edge
206  * string as a whole */
207 void    es_mlist_set_total_string_sup(Tstring * es)
208 {
209     List   *matches;            /* list of string matches */
210     Tstring *ses;               /* string of sub strings */
211     List *sptr;
212     List *start;
213     List *end;
214     int     s1_id, s2_id;
215 
216     ses = string_of_sindex_strings(es);
217 
218     if (ses == NULL)
219         return;
220 
221     start = ses->start;
222     end = ses->end;
223 
224     matches = (List *) prop_get(es->props, MLIST);
225 
226     for (sptr = start; sptr != end; sptr = sptr->next)
227     {
228         Tstring *s1;
229         List   *mlist;
230         List   *mptr;
231 
232         s1 = (Tstring *) sptr->to;
233         mlist = (List *) prop_get(s1->props, MLIST);
234         s1_id = (int) prop_get(s1->props, STRING);
235 
236         for (mptr = mlist; mptr != NULL; mptr = mptr->next)
237         {
238             Match  *m = (Match *) mptr->to;
239             Support *sup;
240             Tstring *s2;
241             String_match *sm;
242 
243             s2 = (Tstring *) m->to2;
244             sup = (Support *) prop_get(m->props, MATCH_SUPPORT);
245             s2_id = (int) prop_get(s2->props, STRING);
246             sm = str_mat_from_list(matches, s1_id, s2_id);
247 
248             if (sm == NULL)
249                 continue;
250 
251             sup->total_string = (float)sm->support;
252         }
253         if (sptr == end)
254             break;
255     }
256     str_rm_links(ses);
257 }
258 
259 /* match string support value */
260 static double sm_support_neg(String_match * sm)
261 {
262     return (sm == NULL) ? 0.0 : -sm->support;
263 }
264 
265 /* choose matches that are consitent with the given string match */
266 static void sm_choose_matches(Tstring * ses, String_match * sm)
267 {
268     List *sptr;
269     List *start;
270     List *end;
271 
272     if (ses == NULL || sm == NULL)
273         return;
274 
275     start = ses->start;
276     end = ses->end;
277 
278     for (sptr = start; sptr != end; sptr = sptr->next)
279     {
280         Tstring *s1, *s2;
281         int     s1_id, s2_id;
282         List   *mlist;
283         List   *mptr;
284         Match  *match;
285         Support *msup = NULL;
286 
287         s1 = (Tstring *) sptr->to;
288         s1_id = (int) prop_get(s1->props, STRING);
289 
290         if (s1_id != sm->s1_id)
291             continue;
292 
293         mlist = (List *) prop_get(s1->props, MLIST);
294 
295         for (mptr = mlist; mptr != NULL; mptr = mptr->next)
296         {
297             match = (Match *) mptr->to;
298 
299             s2 = (Tstring *) ((Match *) mptr->to)->to2;
300             s2_id = (int) prop_get(s2->props, STRING);
301 
302             if (s2_id != sm->s2_id)
303                 continue;
304 
305             msup = (Support *) prop_get(match->props, MATCH_SUPPORT);
306             if (msup->type <= BAD_MATCH)        /* already rejected */
307                 mptr = NULL;
308 
309             break;
310         }
311 
312         if (mptr == NULL)
313             continue;           /* no appropriate match */
314 
315         mlist_set_supp_type(mlist, BAD_MATCH);
316         msup->type = GOOD_MATCH;
317     }
318 }
319 
320 /* choose matches at the string level */
321 void    es_choose_string_matches(Tstring * es, int type, double (*cost_func) ( /* ??? */ ))
322 
323 /* not used */
324 
325 {
326     List   *matches;
327     List   *mptr;
328     Tstring *ses;               /* string of sub-strings */
329 
330     ses = string_of_sindex_strings(es);
331 
332     es_match_string(es, type, cost_func);       /* first call to string
333                                                  * matcher */
334     matches = (List *) prop_get(es->props, MLIST);
335     matches = sort_list(matches, sm_support_neg, NULL);
336     for (mptr = matches; mptr != NULL; mptr = mptr->next)
337     {
338         String_match *sm = (String_match *) mptr->to;
339 
340         if (sm->support == 0.0)
341             break;
342 
343         sm_choose_matches(ses, sm);
344         /* es_match_string does not effect order of matches */
345         es_match_string(es, type, cost_func);
346         mptr->next = sort_list(mptr->next, sm_support_neg, NULL);
347     }
348     str_rm_links(ses);
349 }
350 

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