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

Linux Cross Reference
Tina6/tina-libs/tina/vision/visMatch_edge.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_edge.c,v $
 27  * Date    :  $Date: 2003/10/06 12:29:47 $
 28  * Version :  $Revision: 1.3 $
 29  * CVS Id  :  $Id: visMatch_edge.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 determining matchability of edge
 36  * sub-strings based upon local properties
 37  * 
 38  * provides an initial prune on ambiguity
 39  * 
 40  * 2 aspects are considered orientation and contrast
 41  * 
 42  * edge orientation varies between -PI and +PI but this depends upon the
 43  * sign of intensity contrast across the edge
 44  * 
 45  * hence 3 factors are dealt with
 46  * 
 47  * similar orientation, same contrast sign, similar contrast value
 48  * 
 49  * for the case where only the orientation is important (ie the sign of
 50  * contrast is allowed to change to allow for accidental viewpoint
 51  * alignments) absolute orientation values which do not include the
 52  * contrast component are computed.
 53  * 
 54  * absolute orientation varies between -PI/2 to PI/2 
 55  *
 56  *********
 57 */
 58 
 59 #include "visMatch_edge.h"
 60 
 61 #if HAVE_CONFIG_H
 62   #include <config.h>
 63 #endif
 64 
 65 #include <math.h>
 66 #include <tina/sys/sysDef.h>
 67 #include <tina/sys/sysPro.h>
 68 #include <tina/math/mathDef.h>
 69 #include <tina/math/mathPro.h>
 70 #include <tina/geometry/geomDef.h>
 71 #include <tina/geometry/geomPro.h>
 72 #include <tina/vision/vis_MatchDef.h>
 73 #include <tina/vision/vis_MatchPro.h>
 74 
 75 /* stereo module static parameter values and set functions
 76  * 
 77  * provides data hiding and limits number of external variables */
 78 
 79 static float low_orient_thres = (float)0.3;
 80 static float hi_orient_thres = (float)1.0;
 81 static float disparity_gradient = (float)0.5;
 82 static float low_con_ratio = (float)0.2;
 83 static float hi_con_ratio = (float)5.0;
 84 
 85 void    es_match_set_low_or_thres(double thres)
 86 {
 87     low_orient_thres = (float)thres;
 88 }
 89 
 90 void    es_match_set_hi_or_thres(double thres)
 91 {
 92     hi_orient_thres = (float)thres;
 93 }
 94 
 95 void    es_match_set_grad_thres(double thres)
 96 {
 97     disparity_gradient = (float)thres;
 98 }
 99 
100 void    es_match_set_con_ratio(double ratio)
101 {
102     low_con_ratio = (float)ratio;
103     hi_con_ratio = (float)(1.0 / ratio);
104     ORDER(float, low_con_ratio, hi_con_ratio);
105 }
106 
107 /* calculate the average orientation value of the egels that constitute
108  * this edge string contour
109  * 
110  * the contor will usually be one of the sub strings from the stereo index */
111 double  es_mean_or(Tstring * es)
112 {
113     List *dptr;
114     List *end;
115     double  or;
116 
117     if (es == NULL)
118         return (0);
119 
120     dptr = es->start;
121     end = es->end;
122     or = DD_EDGE(dptr)->orient;
123     for (; dptr != end;)
124     {
125         dptr = dptr->next;
126         or += DD_EDGE(dptr)->orient;
127     }
128     return (or / es->count);
129 }
130 
131 /* calculate the average contrast value of the egels that constitute
132  * this edge string contour
133  * 
134  * the contor will usually be one of the sub strings from the stereo index */
135 double  es_mean_con(Tstring * es)
136 {
137     List *dptr;
138     List *end;
139     double  con;
140 
141     if (es == NULL)
142         return (0);
143 
144     dptr = es->start;
145     end = es->end;
146     con = DD_EDGE(dptr)->contrast;
147     for (; dptr != end;)
148     {
149         dptr = dptr->next;
150         con += DD_EDGE(dptr)->contrast;
151     }
152     return (con / es->count);
153 }
154 
155 /* test whether the orientation is winthin threshold
156  * 
157  * takes into acount the cyclic nature of orientation using the range
158  * argument
159  * 
160  * in radians 2 choices of range exist: PI    orientation independent of
161  * edge contrast 2PI   orientation dependent upon edge contrast */
162 Bool    orient_less_than_thres(double or, double thres, double range)
163 {
164     return ((or < thres || range - or < thres) ? true : false);
165 }
166 
167 /* test whether orientaions agree within the disparity gradient limit */
168 Bool    orients_within_gradient_limit(double or1, double or2, double dgl)
169 
170 /* disparity gradient limit */
171 {
172     double  cot1, cot2;
173 
174     cot1 = 1.0 / tan(or1);
175     cot2 = 1.0 / tan(or2);
176 
177     if (4 * sqr(cot1 - cot2) <= dgl * (sqr(cot1 + cot2) + 4))
178         return (true);
179     return (false);
180 }
181 
182 /* test whether edge strings orientation values match
183  * 
184  * 
185  * orientation is dependent upon contrast and has range 2PI (-PI to PI) */
186 Bool    es_match_orient(Tstring * es1, Tstring * es2)
187 {
188     double  or1, or2, ordiff;
189 
190     if (es1 == NULL || es2 == NULL)
191         return (false);
192 
193     or1 = es_mean_or(es1);
194     or2 = es_mean_or(es2);
195 
196     ordiff = fabs(or1 - or2);
197     if (orient_less_than_thres(ordiff, low_orient_thres, TWOPI) == true)
198         return (true);
199     if (orient_less_than_thres(ordiff, hi_orient_thres, TWOPI) == false)
200         return (false);
201     return (orients_within_gradient_limit(or1, or2, disparity_gradient));
202 }
203 
204 /* compute absolute orientation
205  * 
206  * this orientation is independent of contrast and has range -PI/2 to PI/2 */
207 double  orient_abs(double or)
208 {
209     int     n;
210 
211     if (or > PIBY2)
212     {
213         n = (int)(or / PI + 1);
214         return (or - n * PI);
215     }
216     if (or < -PIBY2)
217     {
218         n = (int)((-or) / PI + 1);
219         return (or + n * PI);
220     }
221     return (or);
222 }
223 
224 /* test whether edge strings absolute orientation values match
225  * 
226  * this allows contrast reversal to occur between images
227  * 
228  * 
229  * absolute orientation has a range of PI (-PI/2 to PI/2) */
230 Bool    es_match_abs_orient(Tstring * es1, Tstring * es2)
231 {
232     double  or1, or2, ordiff;
233 
234     if (es1 == NULL || es2 == NULL)
235         return (false);
236 
237     or1 = orient_abs(es_mean_or(es1));
238     or2 = orient_abs(es_mean_or(es2));
239 
240     ordiff = fabs(or1 - or2);
241     if (orient_less_than_thres(ordiff, low_orient_thres, PI) == true)
242         return (true);
243     if (orient_less_than_thres(ordiff, hi_orient_thres, PI) == false)
244         return (false);
245     return (orients_within_gradient_limit(or1, or2, disparity_gradient));
246 }
247 
248 /* test whether edge strings contrast values match */
249 Bool    es_match_contrast(Tstring * es1, Tstring * es2)
250 {
251     double  con1, con2;
252     double  con_ratio;
253 
254     if (es1 == NULL || es2 == NULL)
255         return (false);
256 
257     con1 = es_mean_con(es1);
258     con2 = es_mean_con(es2);
259 
260     con_ratio = con1 / con2;
261 
262     return (con_ratio > low_con_ratio && con_ratio < hi_con_ratio) ? true : false;
263 }
264 
265 /* test whether edge strings orientation and contrast values match */
266 Bool    es_match_orandcon(Tstring * es1, Tstring * es2)
267 {
268     if (es_match_contrast(es1, es2) == false)
269         return (false);
270     return (es_match_orient(es1, es2));
271 }
272 

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