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

Linux Cross Reference
Tina5/tina-libs/tina/vision/visMatch_edp.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_edp.c,v $
 23  * Date    :  $Date: 2003/10/06 12:29:47 $
 24  * Version :  $Revision: 1.3 $
 25  * CVS Id  :  $Id: visMatch_edp.c,v 1.3 2003/10/06 12:29:47 neil Exp $
 26  *
 27  * Author  : Legacy TINA
 28  *
 29  * Notes :
 30  * 
 31  * generic stereo routines for dynamic programming
 32  * 
 33  * includes support and choice functionality
 34  * 
 35  * uses dynamic programming at its most abstract through the match list
 36  * interface. 
 37  *
 38  *********
 39 */
 40 
 41 #include "visMatch_edp.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 /* static variable for max DP table size plus get and set functions
 58  * 
 59  * using a fixed DP array improves efficiency as the table is not
 60  * allocated at each iteration */
 61 
 62 static int max_dp_table_size = 100;
 63 
 64 void    stereo_dp_max_size_set(int size)
 65 {
 66     max_dp_table_size = size;
 67 }
 68 
 69 int     stereo_dp_max_size_get(void)
 70 {
 71     return (max_dp_table_size);
 72 }
 73 
 74 /* add DP index to elements in the epipolar edge sub-string list that
 75  * represent ordered matching features along a raster */
 76 static void es_list_add_dpindex_prop(List * es)
 77 {
 78     List   *lptr;
 79     Tstring *str;
 80     int     i;
 81 
 82     for (lptr = es, i = 0; lptr != NULL; lptr = lptr->next, ++i)
 83     {
 84         str = (Tstring *) lptr->to;
 85         str->props = proplist_addifnp(str->props, (void *) i, DP_INDEX,
 86                                       (void (*) ()) NULL, false);
 87     }
 88 }
 89 
 90 /* recover DP index from an epipolar sub-string */
 91 static int es_index_get(Tstring * es)
 92 {
 93     return ((int) prop_get(es->props, DP_INDEX));
 94 }
 95 
 96 /* get mean x position of edge string */
 97 static double es_mean_x(Tstring * es)
 98 {
 99     Vec2    v = {Vec2_id};
100 
101     v = str2_centroid(es);
102 
103     return (vec2_x(v));
104 }
105 
106 /* take an ordered list and remove repeated references */
107 static void thin_ordered_list(List * list)
108 {
109     List   *p1;
110     List   *p2;
111     List   *p3;
112 
113     for (p1 = list; p1 != NULL; p1 = p2)
114     {
115         for (p2 = p1->next; p2 != NULL; p2 = p2->next)
116             if (p2->to != p1->to)
117                 break;
118 
119         if (p1->next == p2)
120             continue;
121 
122         if (p2 == NULL)
123             break;
124 
125         p3 = p1->next;
126         p1->next = p2;
127         while (p3 != p2)
128         {
129             p1 = p3->next;
130             rfree((void *) p3);
131             p3 = p1;
132         }
133     }
134 }
135 
136 /* perform dynamic programming to identify optimal ordered selection of
137  * matches referenced through the list of epipolar edge sub-strings
138  * from the left image
139  * 
140  * the matching strength upon which DP is based is returned by calling the
141  * match_weight_func on the match
142  * 
143  * because of the way in which the stereo index is constructed and because
144  * it is possible to allow vertical miss-match at the match formation
145  * stage the right and side of the matches can not be guaranteed to
146  * come from a single raster of the stereo index. they are though
147  * guaranteed to be unigue with respect to uniquely labled subsections
148  * of global edge contours.
149  * 
150  * the list of all matches associated with the raster left is processed to
151  * recover a list of right hand edges strings these are subsequently
152  * ordered and thined to produce a unique list of edge sub-strings that
153  * constitues a virtual raster of the right image. */
154 List   *match_epi_dprog(List * left, double (*match_weight_func) ( /* ??? */ ))
155 /* epipolar edge list */
156 
157 {
158     List   *mlist = NULL;
159     List   *right;
160     List   *dplist;
161 
162     list_apply_func(left, es_add_to_mlist, (void *) &mlist);
163     right = mlist_to2_list(mlist);
164     right = sort_list(right, es_mean_x, NULL);
165     thin_ordered_list(right);
166 
167     if (right == NULL)
168         return (NULL);
169 
170     es_list_add_dpindex_prop(left);
171     es_list_add_dpindex_prop(right);
172 
173     mlist_set_dp_indices(mlist, es_index_get, NULL);
174 
175     dplist = dp_mlist(mlist, match_weight_func);
176 
177     list_rm_links(right);
178     list_rm_links(mlist);
179 
180     return (dplist);
181 }
182 
183 /* use raster based DP to choose optimal match order for the matching
184  * strength implied by the match_weight_func */
185 void    choose_ordered_matches(Imrect * er, double (*match_weight_func) ( /* ??? */ ))
186 /* left edgerect */
187 
188 {
189     Rindex *sx;
190     int     ly, uy, i;
191 
192     if (er == NULL || (sx = (Rindex *) prop_get(er->props, SINDEX)) == NULL)
193         return;
194 
195     ly = sx->region->ly;
196     uy = sx->region->uy;
197 
198     dp_mlist_build(max_dp_table_size);
199 
200     for (i = ly; i < uy; ++i)
201     {
202         List   *mlist = NULL;
203         List   *best;
204 
205         list_apply_func((List *) sx->index[i], es_add_to_mlist, (void *) &mlist);
206         best = match_epi_dprog((List *) sx->index[i], match_weight_func);
207         mlist_set_supp_type(mlist, BAD_MATCH);
208         mlist_set_supp_type(best, GOOD_MATCH);
209         list_rm_links(mlist);
210         list_rm_links(best);
211     }
212 }
213 
214 /* set matching strength according to DP selection the
215  * matching_strength of the support structure is
216  * 
217  * set to the weight of the match (not the DP sum) for matches on the
218  * optimal path and zero otherwise */
219 void    support_ordered_matches(Imrect * er, double (*match_weight_func) ( /* ??? */ ))
220 /* left edgerect */
221 
222 {
223     Rindex *sx;
224     int     ly, uy, i;
225     double  zero = 0;
226 
227     if (er == NULL || (sx = (Rindex *) prop_get(er->props, SINDEX)) == NULL)
228         return;
229 
230     ly = sx->region->ly;
231     uy = sx->region->uy;
232 
233     dp_mlist_build(max_dp_table_size);
234 
235     for (i = ly; i < uy; ++i)
236     {
237         List   *mlist = NULL;
238         List   *best;
239 
240         list_apply_func((List *) sx->index[i], es_add_to_mlist, (void *) &mlist);
241         best = match_epi_dprog((List *) sx->index[i], match_weight_func);
242         list_apply_func(mlist, match_set_match_strength, (void *) &zero);
243         list_apply_func(best, (void (*) ()) match_set_strength_from_weight,
244                         NULL);
245         list_rm_links(mlist);
246         list_rm_links(best);
247     }
248 }
249 

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