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

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

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