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

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

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