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

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

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