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

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

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