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

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

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