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

Linux Cross Reference
Tina5/tina-libs/tina/vision/visCorr_preproc.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/visCorr_preproc.c,v $
 23  * Date    :  $Date: 2005/01/09 17:49:25 $
 24  * Version :  $Revision: 1.2 $
 25  * CVS Id  :  $Id: visCorr_preproc.c,v 1.2 2005/01/09 17:49:25 paul Exp $
 26  *
 27  * Author : Simon Crossley (see thesis Univ. Sheffield U.K.), NAT.
 28  */
 29 /**
 30  * @file stereo correlation algorithms
 31  * @brief Routines to enforce disparity gradient limit.
 32  *
 33  *********
 34 */
 35 
 36 #include "visCorr_preproc.h"
 37 
 38 #include <math.h>
 39 #include <tina/sys/sysDef.h>
 40 #include <tina/sys/sysPro.h>
 41 #include <tina/math/mathDef.h>
 42 #include <tina/math/mathPro.h>
 43 #include <tina/geometry/geomDef.h>
 44 #include <tina/geometry/geomPro.h>
 45 #include <tina/image/imgDef.h>
 46 #include <tina/image/imgPro.h>
 47 #include <tina/vision/visDef.h>
 48 #include <tina/vision/visPro.h>
 49 
 50 #include "vis_CorrDef.h"
 51 #include "vis_CorrPro.h"
 52 
 53 #define VERT atan2(1.0, 0.0)
 54 
 55 /* add edgel ptr's x y location to its already stored
 56    sub-pixel location */
 57 
 58 void add_edge_loc(Edgel *edge, int type, int prop_type, int i, int j)
 59 {
 60   Point2 *point;
 61 
 62   if (type != EDGE || edge == NULL || prop_present(edge->props, POINT2))
 63     return;
 64   
 65   point = point2_make(vec2((float)j, (float)i), POINT2);
 66   edge->props = proplist_addifnp(edge->props, (void *)point, POINT2,
 67                                  point2_free, true);
 68 }
 69 
 70 void stereo_ee(Imrect *left_im, Imrect *right_im, Imrect *left_edge_im, Imrect *right_edge_im, 
 71                int enhance_type, double sigma, double precision, 
 72                Imrect **left_grey_im, Imrect **right_grey_im)
 73 /* moved out of st_corr_tool.c NAT 7/6/04 */
 74 /* store the location of each edge on the edge structure for use later */
 75 /* pre-process grey level image to facilitate the required match metric */
 76 {
 77   Imrect *im1=NULL, *im2=NULL;
 78 
 79 /*
 80   if (enhance_type != grad)
 81     left_edge_im = im_vedge_detect(left_im, can_sigma, can_precision,
 82                                    can_low_edge_th, can_up_edge_th,
 83                                    can_len_th, vert_error);
 84   else
 85     left_edge_im = im_edge_detect(left_im, can_sigma, can_precision,
 86                                   can_low_edge_th, can_up_edge_th,
 87                                   can_len_th);
 88   left_edges_set(left_edge_im);
 89 
 90   if (enhance_type != grad)
 91     right_edge_im = im_vedge_detect(right_im, can_sigma, can_precision,
 92                                     can_low_edge_th, can_up_edge_th,
 93                                     can_len_th, vert_error);
 94   else
 95     right_edge_im = im_edge_detect(right_im, can_sigma, can_precision,
 96                                    can_low_edge_th, can_up_edge_th,
 97                                    can_len_th);
 98   right_edges_set(right_edge_im);
 99 */
100 
101 
102 
103   er_apply_to_all_edges(left_edge_im, add_edge_loc, (void *)POINT2);
104   er_apply_to_all_edges(right_edge_im, add_edge_loc, (void *)POINT2);
105  
106   *left_grey_im = imf_crop_and_pad(left_im);
107   *right_grey_im = imf_crop_and_pad(right_im);
108  
109   /* grey level image edge enhancement */
110 
111   switch (enhance_type)
112     {
113     case diffx_gauss:
114       im2 = imf_diffx(*left_grey_im);
115       im1 = imf_gauss_rows(im2, sigma, precision);
116       im_free(im2);
117       break;
118     case diffx:
119       im1 = imf_diffx(*left_grey_im);
120       break;
121     case DoG:
122 /*
123       im1 = imf_gauss_rows(*left_grey_im, sigma, precision);
124       im2 = imf_gauss_rows(*left_grey_im, sigma, precision);
125       im3 = imf_times(k1, im1);
126       im_free(im1);
127       im4 = imf_times(k2, im2);
128       im_free(im2);
129       im1 = imf_sum(im3, im4);
130       im_free(im3);
131       im_free(im4);
132 */
133       break;
134     case gauss:
135       im1 = imf_gauss_rows(*left_grey_im, sigma, precision);
136       break;
137     case grad:
138       im2 = imf_gauss_rows(*left_grey_im, sigma, precision);
139       im1 = imf_gauss_cols(im2, sigma, precision);
140       im_free(im2);
141       im2 = imf_sqrgrad(im1);
142       im_free(im1);
143       im1 = imf_sqrt(im2);
144       im_free(im2);
145       break;
146     case none:
147       break;
148     }
149   if (enhance_type != none)
150     {
151       im_free(*left_grey_im);
152       *left_grey_im = im1;
153     }
154 
155   switch (enhance_type)
156     {
157     case diffx_gauss:
158       im2 = imf_diffx(*right_grey_im);
159       im1 = imf_gauss_rows(im2, sigma, precision);
160       im_free(im2);
161       break;
162     case diffx:
163       im1 = imf_diffx(*right_grey_im);
164       break;
165     case DoG:
166 /*
167       im1 = imf_gauss_rows(*right_grey_im, sigma, precision);
168       im2 = imf_gauss_rows(*right_grey_im, sigma, precision);
169       im3 = imf_times(k1, im1);
170       im_free(im1);
171       im4 = imf_times(k2, im2);
172       im_free(im2);
173       im1 = imf_sum(im3, im4);
174       im_free(im3);
175       im_free(im4);
176 */
177       break;
178     case gauss:
179       im1 = imf_gauss_rows(*right_grey_im, sigma, precision);
180       break;
181     case grad:
182       im2 = imf_gauss_rows(*right_grey_im, sigma, precision);
183       im1 = imf_gauss_cols(im2, sigma, precision);
184       im_free(im2);
185       im2 = imf_sqrgrad(im1);
186       im_free(im1);
187       im1 = imf_sqrt(im2);
188       im_free(im2);
189       break;
190     case none:
191       break;
192     }
193   if (enhance_type != none)
194     {
195       im_free(*right_grey_im);
196       *right_grey_im = im1;
197     }
198 }
199 
200 /*
201 static void tstring_smooth(Imrect *er)
202 {
203   void ddstr_apply_func();
204   Ddlist *dptr;
205   List *es_list;
206   List *ptr;
207   double oldx, oldy, oldorient;
208   double newx, newy, neworient;
209   double nextor, lastor;
210 
211   if (er==NULL) return;
212 
213   es_list = (List *) prop_get(er->props, STRING);
214 
215   for (ptr = es_list; ptr != NULL; ptr = ptr->next)
216     {
217       Tstring *es2 = (Tstring *)ptr->to;
218       Edgel *edge, *last_edge, *next_edge;
219       dptr = (Ddlist *)es2->start;
220       last_edge = (Edgel *)dptr->to;
221       if ((void *)dptr == (void *)es2->end) continue;
222       oldx = vec2_x(last_edge->pos);
223       oldy = vec2_y(last_edge->pos);
224       while(1)
225         {
226           vec2_x(last_edge->pos) = oldx;
227           vec2_y(last_edge->pos) = oldy;
228 
229           if ((void *)dptr->next == (void *)es2->end) break;
230 
231           dptr=dptr->next;
232           edge = dptr->to;
233           next_edge = dptr->next->to;
234           newx = 0.5 * vec2_x(edge->pos) + 0.25 * vec2_x(next_edge->pos)
235             + 0.25 * vec2_x(last_edge->pos);
236           newy = 0.5 * vec2_y(edge->pos) + 0.25 * vec2_y(next_edge->pos)
237             + 0.25 * vec2_y(last_edge->pos);
238           
239           oldx = newx;
240           oldy = newy;
241           last_edge = edge;
242         }
243       dptr = (Ddlist *)es2->start;
244       last_edge = (Edgel *)dptr->to;
245       oldorient = last_edge->orient;
246       while(1)
247         {
248           last_edge->orient = oldorient;
249 
250           if ((void *)dptr->next == (void *)es2->end) break;
251 
252           dptr = dptr->next;
253           edge = dptr->to;
254           next_edge = dptr->next->to;
255           lastor = atan2(vec2_y(last_edge->pos) - vec2_y(edge->pos),
256                          vec2_x(edge->pos) - vec2_x(last_edge->pos));
257           nextor = atan2(vec2_y(edge->pos) - vec2_y(next_edge->pos),
258                          vec2_x(next_edge->pos) - vec2_x(edge->pos));
259           if (fabs(lastor - nextor) > PI)
260             {
261               if(lastor - nextor > PI) lastor -= 2.0 * PI;
262               else lastor += 2.0 * PI;
263             }
264           neworient = (lastor + nextor) / 2.0;
265           if (fabs(neworient - edge->orient) > PI / 2.0)
266             {
267               while (neworient - edge->orient > PI / 2.0) neworient -= PI;
268               while (edge->orient - neworient > PI / 2.0) neworient += PI;
269             }
270           oldorient = neworient;
271           last_edge = edge;
272         }
273     }
274 }
275 */
276 
277 /*
278 function retired as a bad idea NAT 7/6/04
279 
280 Imrect *im_vedge_detect(Imrect *im, double sigma, double precision,
281                         double low_edge_th, double up_edge_th, int len_th, 
282                         double vert_err)
283 {
284   Imrect *edge_im;
285   Edgel *edge;
286   double eor;
287   int i, j;
288 
289   if ((edge_im = canny(im, sigma, precision, low_edge_th, up_edge_th, len_th))
290       == NULL)
291     return(NULL);
292 
293   tstring_smooth(edge_im);
294   
295   FOR_IM (edge_im->region, i, j)
296     {
297       if ((edge = IM_PTR(edge_im, i, j)) == NULL)
298         continue;
299 
300       eor = fabs(edge->orient);
301       if ((eor > VERT + vert_err) || (eor < VERT - vert_err))
302         {
303           edge_free(edge);
304           IM_PTR(edge_im, i, j) = NULL;
305         }
306     }
307 
308   er_set_row_index(edge_im);
309   er_find_edge_strings(edge_im);
310 
311   return(edge_im);
312 }
313 
314 Imrect *im_edge_detect(Imrect *im, double sigma, double precision,
315                        double low_edge_th, double up_edge_th, int len_th)
316 {
317   Imrect *edge_im;
318 
319   edge_im = canny(im, sigma, precision, low_edge_th, up_edge_th, len_th);
320 
321   return(edge_im);
322 }
323 */
324 

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