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

Linux Cross Reference
Tina6/tina-libs/tina/vision/visCorr_dgrad.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_dgrad.c,v $
 27  * Date    :  $Date: 2008/10/30 09:43:59 $
 28  * Version :  $Revision: 1.2 $
 29  * CVS Id  :  $Id: visCorr_dgrad.c,v 1.2 2008/10/30 09:43:59 neil 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_dgrad.h"
 41 
 42 
 43 #include <math.h>
 44 #include <float.h>
 45 #include <limits.h>
 46 #include <tina/sys/sysDef.h>
 47 #include <tina/sys/sysPro.h>
 48 #include <tina/math/mathDef.h>
 49 #include <tina/math/mathPro.h>
 50 #include <tina/geometry/geomDef.h>
 51 #include <tina/geometry/geomPro.h>
 52 #include <tina/image/imgDef.h>
 53 #include <tina/image/imgPro.h>
 54 #include <tina/vision/visDef.h>
 55 #include <tina/vision/visPro.h>
 56 
 57 #include <tina/vision/vis_CorrDef.h>
 58 
 59 /* made global for speed */
 60 
 61 static int i, j, k, l;
 62 static int im_lx, im_ly, im_ux, im_uy;
 63 static float tot_less, tot_found;
 64 static Vec3 p1, p2;
 65 
 66 /* calculate disparity gradient between two disparities */
 67 
 68 static float disp_grad(Vec3 *p1, Vec3 *p2)
 69 {
 70   float X, Xdash, Y, S;
 71 
 72   X = vec3_x(*p1) - vec3_x(*p2);
 73   Xdash = vec3_x(*p1) + vec3_z(*p1) - (vec3_x(*p2) + vec3_z(*p2));
 74   Y = fabs(vec3_y(*p1) - vec3_y(*p2));
 75   S = sqrt(0.25 * sqr(X + Xdash) + sqr(Y));
 76 
 77   if (S == 0.0)
 78     return FLT_MAX;
 79   else
 80     return fabs(X - Xdash) / S;
 81 }
 82 
 83 
 84 static void DG_check(Imrect *in_disp_im, float limit)
 85 {
 86   if (k>=im_ly && k<im_uy && l>=im_lx && l<im_ux)
 87     {
 88       vec3_z(p2) = IM_FLOAT(in_disp_im, k, l);
 89 
 90       if (vec3_z(p2) != NO_DISP)
 91         {
 92           tot_found++;
 93           vec3_x(p1)=(float)j; vec3_y(p1)=(float)i;
 94           vec3_x(p2)=(float)l; vec3_y(p2)=(float)k;
 95           if (disp_grad(&p1, &p2) <= limit) tot_less++;
 96         }
 97     }
 98 }       
 99 
100 /* function to enforce disp-grad limit on a float disparity image */
101 
102 Imrect *imf_dispgrad(Imrect *in_disp_im, Imrect *im_edges, float limit, float thresh,
103                      int range, Bool *complete_ptr)
104 {
105   Imrect *out_disp_im;
106   int radius;
107   float tot_processed = 0, tot_rejected = 0;
108   char str[256];
109   int lx, ly, ux, uy;
110   Edgel *edge;
111 
112   #define complete (*complete_ptr)
113 
114   if (in_disp_im == NULL)
115     {
116       complete = true;
117       return (NULL);
118     }
119 
120   out_disp_im = im_copy(in_disp_im);
121   im_lx = in_disp_im->region->lx;
122   im_ly = in_disp_im->region->ly;
123   im_ux = in_disp_im->region->ux;
124   im_uy = in_disp_im->region->uy;
125 
126   FOR_IM (in_disp_im->region, i, j)
127     {
128       vec3_z(p1) = IM_FLOAT(in_disp_im, i, j);
129 
130       if (vec3_z(p1) == NO_DISP)
131         continue;
132 
133       tot_processed++;
134       radius = 1;
135       tot_less = 0.0;
136       tot_found = 0.0;
137       while (radius<=range)
138         {
139           lx = j - radius;
140           ux = j + radius;
141           ly = i - radius;
142           uy = i + radius;
143           
144           for(k=ly, l=lx; l<=ux; ++l)
145             DG_check(in_disp_im, limit);
146           for(k=uy, l=lx; l<=ux; ++l)
147             DG_check(in_disp_im, limit);
148           for(l=lx, k=ly+1; k<uy; ++k)
149             DG_check(in_disp_im, limit);
150           for(l=ux, k=ly+1; k<uy; ++k)
151             DG_check(in_disp_im, limit);
152           
153           radius++;
154         }
155 
156       if (tot_found==0.0 || 100.0*(tot_less/tot_found) < thresh)
157         {
158           IM_FLOAT(out_disp_im, i, j) = NO_DISP;
159           if ((edge = IM_PTR(im_edges, i, j))!=NULL)
160              edge->props = proplist_rm(edge->props, MATCH);
161           else
162              format("inconsistent edges in disarity filter \n");
163           tot_rejected++;
164         }
165     }
166   
167   sprintf(str, "Processed %d Rejected %d (%5.2f percent)\n", (int)tot_processed,
168           (int)tot_rejected, 100.0 * (tot_rejected/tot_processed));
169   format(str);
170   if (tot_rejected/tot_processed < 0.01) complete = true;
171 
172   im_free(in_disp_im);
173   return(out_disp_im);
174 
175   #undef complete
176 }
177 
178 

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