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

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

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

  1 /**@(#)
  2 **/
  3 /* match_epi.c
  4  * 
  5  * generic stereo functions for identifying matches between epipolar edge
  6  * sub-strings contained in the stereo index
  7  * 
  8  * optimised for general ease of handling and testing of stereo algorithms
  9  * rather than computational/memory efficiency.
 10  * 
 11  * the MLIST property of the epipolar sub-strings is used to store a list
 12  * of potential matches */
 13 
 14 #include <math.h>
 15 #include <tina/sys.h>
 16 #include <tina/sysfuncs.h>
 17 #include <tina/math.h>
 18 #include <tina/mathfuncs.h>
 19 #include <tina/vision.h>
 20 #include <tina/visionfuncs.h>
 21 
 22 /* test if the string of which s is an epipolar sub-string is already
 23  * referenced by the ->to2 field of a member of the list of matches
 24  * mlist
 25  * 
 26  * as strings can cross the same set of epipolar/rasters more than one the
 27  * STRING id label added during the construction of the stereo index is
 28  * used to identify unique sections */
 29 static Bool string_already_matched(Tstring * s, List * mlist)
 30 {
 31     List   *mptr;
 32     int     s_id;
 33 
 34     if (s == NULL || mlist == NULL)
 35         return (false);
 36 
 37     s_id = (int) prop_get(s->props, STRING);
 38 
 39     for (mptr = mlist; mptr != NULL; mptr = mptr->next)
 40     {
 41         Tstring *sptr = (Tstring *) ((Match *) (mptr->to))->to2;
 42 
 43         if (s_id == (int) prop_get(sptr->props, STRING))
 44             return (true);
 45     }
 46 
 47     return (false);
 48 }
 49 
 50 /* compute the stereo matching strength weight between a pair of
 51  * epipolar sub-strings
 52  * 
 53  * the matching strenght increases with: the similarity of edge string
 54  * contrast the actual contrast value the number of edges in the edge
 55  * string */
 56 double  ss_match_weight(Tstring * s1, Tstring * s2)
 57 {
 58     float   mean_count;
 59     double  es_mean_con();
 60     double  con1, con2;
 61 
 62     if (s1 == NULL || s2 == NULL)
 63         return (0.0);
 64 
 65     con1 = es_mean_con(s1);
 66     con2 = es_mean_con(s2);
 67     mean_count = (float)((s1->count + s2->count) / 2.0);
 68     return (mean_count * con1 * (1.0 - fabs(con1 - con2) / (con1 + con2)));
 69 }
 70 
 71 /* add to the list of matches of an edge sub-string additional matches
 72  * with the list of sub-strings from a matching epipolar/raster
 73  * 
 74  * the matches are stored as a lists on the MLIST property of the epipolar
 75  * sub-strings from the left image
 76  * 
 77  * matches are only sought over the range lx to ux which is determined in
 78  * turn from the disparity range
 79  * 
 80  * matches must satisfy match_func (NULL value for all matches) and are
 81  * limited to a single match per uniquely labled meta edge string using
 82  * the string_already_matched function */
 83 void    es_add_new_matches(Tstring * es, List * slist, double lx, double ux, Bool(*match_func) ( /* ??? */ ))
 84 /* string contiguous edges along a raster */
 85 /* list of raster edge strings */
 86 /* matching window */
 87 
 88 /* edge string match test (NULL for all matches) */
 89 {
 90     List   *lptr;
 91     Tstring *sptr;
 92     List   *mlist;
 93 
 94     mlist = (List *) prop_get(es->props, MLIST);
 95 
 96     for (lptr = slist; lptr != NULL; lptr = lptr->next)
 97     {
 98         sptr = (Tstring *) lptr->to;
 99         if ((sptr->type == FORWARD && vec2_x(DD_EDGE_POS(sptr->end)) > lx) ||
100             (sptr->type == BACKWARD && vec2_x(DD_EDGE_POS(sptr->start)) > lx))
101             break;
102     }
103     for (; lptr != NULL; lptr = lptr->next)
104     {
105         sptr = (Tstring *) lptr->to;
106         if ((sptr->type == FORWARD && vec2_x(DD_EDGE_POS(sptr->end)) > ux) ||
107             (sptr->type == BACKWARD && vec2_x(DD_EDGE_POS(sptr->start)) > ux))
108             break;
109         if (string_already_matched(sptr, mlist) == true)
110             continue;
111         if (match_func == NULL || match_func(es, sptr)) /* they can match */
112         {
113             Match  *m = match_make((void *) es, (void *) sptr, STRING);
114 
115             m->weight = (float)ss_match_weight(es, sptr);
116             mlist = ref_addtostart(mlist, (void *) m, MATCH);
117         }
118     }
119     es->props = proplist_addifnp(es->props, (void *) mlist, MLIST, mlist_free, false);
120 }
121 
122 /* find all matches between a pair of epipolar lines uses the function
123  * es_add_new_matches */
124 void    es_match_epi_pair(List * left, List * right, Bool(*match_func) ( /* ??? */ ))
125 /* list of edge strings on left epipolar */
126 /* list of edge strings on right epipolar */
127 
128 /* edge string match test (NULL for all matches) */
129 {
130     double  lowd, upd;          /* range of allowed disparity */
131     List   *ptr;
132 
133     for (ptr = left; ptr != NULL; ptr = ptr->next)
134     {
135         double  lx, ux;
136         Tstring *es = (Tstring *) ptr->to;
137 
138         (void) disp_range_at_pos2(str2_centroid(es), &lowd, &upd);
139 
140         if (es->type == FORWARD)
141         {
142             lx = vec2_x(DD_EDGE_POS(es->start)) + lowd;
143             ux = vec2_x(DD_EDGE_POS(es->end)) + upd;
144         } else
145         {                       /* BACKWARD */
146             lx = vec2_x(DD_EDGE_POS(es->end)) + lowd;
147             ux = vec2_x(DD_EDGE_POS(es->start)) + upd;
148         }
149         es_add_new_matches(es, right, lx, ux, match_func);
150     }
151 }
152 
153 /* find all matches between left and right edgerects search over
154  * vertical raster range of vslop to allow for calibration error and
155  * edge migration
156  * 
157  * the same edge string will not be matched on different rasters only the
158  * first match is maintained, hence matching between corresponding
159  * rasters is performed before those within allowed vertical error */
160 void    er_set_matches(Imrect * er_left, Imrect * er_right, int vslop, Bool(*match_func) ( /* ??? */ ))
161 /* imrects containing left and right edges */
162 /* vertical range for allowable matches */
163 
164 /* edge string match test (NULL for all matches) */
165 {
166     Rindex *sx_left;
167     Rindex *sx_right;
168     List   *left;
169     List   *right;
170     int     ll, lu, rl, ru;
171     int     i, j;
172 
173     if (er_left == NULL || er_right == NULL)
174         return;
175 
176     sx_left = (Rindex *) prop_get(er_left->props, SINDEX);      /* Stereo INDEX */
177     sx_right = (Rindex *) prop_get(er_right->props, SINDEX);
178 
179     if (sx_left == NULL || sx_right == NULL)
180         return;
181 
182     ll = sx_left->region->ly;
183     rl = sx_right->region->ly;
184     lu = sx_left->region->uy;
185     ru = sx_right->region->uy;
186 
187     for (i = ll; i < lu; ++i)
188     {
189         left = (List *) sx_left->index[i];
190         for (j = 0; j <= vslop; ++j)
191         {
192             if (i + j >= rl && i + j < ru)      /* in right image */
193             {
194                 right = (List *) sx_right->index[i + j];
195                 es_match_epi_pair(left, right, match_func);
196             }
197             if (j != 0 && i - j >= rl && i - j < ru)    /* in right image */
198             {
199                 right = (List *) sx_right->index[i - j];
200                 es_match_epi_pair(left, right, match_func);
201             }
202         }
203     }
204 }
205 
206 /* add copy of match list (only links are copied) of current edge
207  * string to global list */
208 void    es_add_to_mlist(Tstring * es, int type, List ** mlist)
209 {
210     if (type != STRING)
211         return;
212     *mlist = list_append(list_copy((List *) prop_get(es->props, MLIST),
213                                    (void *(*) ()) NULL, NULL), *mlist);
214 }
215 
216 /* edge sub-string match format also prints support structure if
217  * available */
218 void    em_format(Match * em, int type)
219 {
220     Support *s;
221 
222     if (em == NULL || type != MATCH)
223         return;
224 
225     format("edge string \n");
226     es_format((Tstring *) em->to1);
227     format("\nis matched to\n");
228     es_format((Tstring *) em->to2);
229     s = (Support *) prop_get(em->props, MATCH_SUPPORT);
230     if (s != NULL)
231     {
232         format("match type   %d\n", s->type);
233         format("local string %f\n", s->local_string);
234         format("total string %f\n", s->total_string);
235         format("local area   %f\n", s->local_area);
236         format("matching     %f\n", s->matching_strength);
237     }
238 }
239 
240 /* format whole list of string of edge sub-string matches */
241 void    em_list_format(List * mlist)
242 {
243     list_apply_func(mlist, em_format, NULL);
244 }
245 

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