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

Linux Cross Reference
Tina6/tina-libs/tina/geometry/geomImg_corner.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/geometry/geomImg_corner.c,v $
 27  * Date    :  $Date: 2002/12/09 11:51:23 $
 28  * Version :  $Revision: 1.1.1.1 $
 29  * CVS Id  :  $Id: geomImg_corner.c,v 1.1.1.1 2002/12/09 11:51:23 cvstina Exp $
 30  *
 31  * Author  : Legacy TINA
 32  *
 33  * Notes :
 34  *
 35  *********
 36 */
 37 
 38 #include "geomImg_corner.h"
 39 
 40 #if HAVE_CONFIG_H
 41   #include <config.h>
 42 #endif
 43 
 44 #include <math.h>
 45 #include <tina/sys/sysDef.h>
 46 #include <tina/sys/sysPro.h>
 47 #include <tina/math/mathDef.h>
 48 #include <tina/math/mathPro.h>
 49 #include <tina/image/imgDef.h>
 50 #include <tina/image/imgPro.h>
 51 #include <tina/geometry/geom_EdgeDef.h>
 52 #include <tina/geometry/geomImg_max.h>
 53 
 54 Imrect *corner2(Imrect *im,double sigma,double precision,double lowthres)
 55 {
 56     Imrect *gim,*corn_im;
 57     Imrect *maxim;
 58     Imrect *gradx, *grady;
 59 
 60     gradx = imf_grad_h(im);
 61     grady = imf_grad_v(im);
 62 
 63     gim = imf_gauss(im,sigma,precision);
 64     corn_im = cornim(gim,sigma,precision,0.0);
 65     maxim = imf_nmax(corn_im,(float)(1024.0*lowthres),0);
 66     corner_locate(maxim,corn_im,gradx,grady);
 67     im_free(corn_im);
 68     im_free(gim);
 69     im_free(gradx);
 70     im_free(grady);
 71  
 72     return(maxim);
 73 }
 74  
 75 Imrect *corner(Imrect *im,double sigma,double precision,double lowthres)
 76 {
 77     Imrect *gim,*corn_im;
 78     Imrect *maxim;
 79     Imrect *gradx, *grady;
 80 
 81     gradx = imf_grad_h(im);
 82     grady = imf_grad_v(im);
 83 
 84     corn_im = cornim(im,sigma,precision,0.05);
 85     gim = imf_gauss(corn_im,sigma,precision);
 86     im_free(corn_im);
 87     maxim = imf_nmax(gim,(float)(1024.0*lowthres),0);
 88     corner_locate(maxim,gim,gradx,grady);
 89     im_free(gim);
 90     im_free(gradx);
 91     im_free(grady);
 92 
 93     return(maxim);
 94 }
 95 
 96 Imrect *cornim(Imrect *im,double sigma,double precision,double edge_sup)
 97 {
 98     Imrect *gimx,*gimy,*gimxy,*gimedge;
 99     Imrect *gradx;
100     Imrect *grady;
101     Imrect *gradsqx,*gradsqy,*gradsqxy;
102     Imrect *gradsqxsqy;
103     Imrect *corn_im;
104  
105     if (im==NULL)
106         return(NULL);
107  
108     gradx = imf_grad_h(im);
109     grady = imf_grad_v(im);
110     gradsqx = imf_prod(gradx,gradx);
111     gradsqy = imf_prod(grady,grady);
112     gradsqxy = imf_prod(gradx,grady);
113     im_free(gradx);
114     im_free(grady);
115     gradsqxsqy = imf_sum(gradsqx,gradsqy);
116  
117     gimx = imf_gauss(gradsqx,sigma,precision);
118     im_free(gradsqx);
119     gimy = imf_gauss(gradsqy,sigma,precision);
120     im_free(gradsqy);
121     gimxy = imf_gauss(gradsqxy,sigma,precision);
122     im_free(gradsqxy);
123     gimedge = imf_gauss(gradsqxsqy,1.1*sigma,precision);
124     im_free(gradsqxsqy);
125  
126     corn_im = cornim2(gimx,gimy,gimxy,gimedge,edge_sup);
127     im_free(gimx);
128     im_free(gimy);
129     im_free(gimxy);
130     im_free(gimedge);
131  
132     return(corn_im);
133 }
134  
135 Imrect *cornim2(Imrect *im1,Imrect *im2,Imrect *im3,Imrect *im4,
136                                 double edge_sup)
137 
138 {
139     Imrect *cornim;
140     Imregion *roi;
141     float *line1,*line2,*line3,*line4;
142     int lx, ux, ly, uy;
143     int i,j;
144  
145     if (im1==NULL || im2==NULL || im3==NULL)
146         return(NULL);
147  
148     roi = im1->region;
149  
150     if  (roi==NULL)
151         return(NULL);
152  
153     cornim = im_alloc(im1->height,im1->width,roi,float_v);
154  
155     lx = roi->lx;
156     ux = roi->ux;
157     ly = roi->ly;
158     uy = roi->uy;
159  
160     line1 = fvector_alloc(lx, ux);
161     line2 = fvector_alloc(lx, ux);
162     line3 = fvector_alloc(lx, ux);
163     line4 = fvector_alloc(lx, ux);
164  
165     for (i=ly;i<uy;++i)
166     {
167         im_get_rowf(line1,im1,i,lx,ux);
168         im_get_rowf(line2,im2,i,lx,ux);
169         im_get_rowf(line3,im3,i,lx,ux);
170         im_get_rowf(line4,im4,i,lx,ux);
171 
172                 /* this next line previously used IM_FLOAT_INDEX (sam) */
173         for (j=lx;j<ux;++j)
174                         IM_FLOAT( cornim, i,j) = (float)(line1[j]*line2[j]-line3[j]*line3[j] - 
175                                                  edge_sup*line4[j]*line4[j]);
176     }
177  
178     fvector_free(line1, lx);
179     fvector_free(line2, lx);
180     fvector_free(line3, lx);
181     fvector_free(line4, lx);
182     return(cornim);
183 }
184  
185 void    corner_locate(Imrect * im, Imrect * corner_im, Imrect *gradx , Imrect *grady)
186 {
187      Imregion *region;
188      float x,y;
189      int i,j;
190      int lx,ux,ly,uy; 
191  
192      if (im==NULL ||  corner_im==NULL) return;
193  
194      region = im->region;
195  
196      lx = region->lx+1;
197      ux = region->ux-1;
198      ly = region->ly+1;
199      uy = region->uy-1;
200  
201      for (i=ly;i<uy;++i)
202      {
203          for (j=lx;j<ux;++j)
204          {
205               Edgel *eptr;
206  
207                           if ((eptr=IM_PTR(im, i,j)) == NULL) continue;
208  
209               eptr->contrast =(float)im_get_quadmaxf(corner_im,(float)j,(float)i,&x,&y);
210               eptr->pos = vec2(x,y);
211               eptr->type &= EDGE_GET_CONN_MASK;
212               eptr->type |= EDGE_ISOLATED;
213                           eptr->orient = (float)cor_orient( eptr->pos, 10.0, gradx,grady);
214 
215          }
216      }
217 }
218 
219 double cor_orient(Vec2 pos,double range,Imrect *gradx,Imrect *grady)
220 /* see nat */
221 {
222     int lx,ux,ly,uy;
223     int i,j;
224     double meanx=0.0,meany=0.0;
225     double dx,dy, delx,dely;
226     double twosigma2 = range*range/2.0; /* set the scale of radial weighting */
227     double orient;
228     double weight;
229     double thresh=0.0;
230     float **grad;
231     float pix;
232 
233     lx = tina_int(pos.el[0]-range)-1;
234     ux = tina_int(pos.el[0]+range+1)+1;
235     ly = tina_int(pos.el[1]-range)-1;
236     uy = tina_int(pos.el[1]+range+1)+1;
237     grad = farray_alloc(ly,lx,uy,ux);
238 
239 /* calculate a robust mean with which to threshold the likely edge pixels */
240     for (i=ly;i<uy;++i)
241     {
242         for (j=lx;j<ux;++j)
243         {
244             dx = im_get_pixf(gradx,i,j);
245             dy = im_get_pixf(grady,i,j);
246             grad[i][j] = dx*dx + dy*dy;
247             thresh += grad[i][j];
248         }
249     }
250 
251     thresh /= ((ux-lx)*(uy-ly));
252 
253 /* calculate the orientation from the moments of the thresholded gradient image */
254     for (i=ly+1;i<uy-1;++i)
255     {
256         for (j=lx+1;j<ux-1;++j)
257         {
258             if ((pix=grad[i][j]) > thresh)
259             {
260 /*
261                 int num = 2;
262                 int nmax = 0;
263                 if (pix<grad[i-1][j-1] && ++nmax > num) continue;
264                 if (pix<grad[i-1][j]   && ++nmax > num) continue;
265                 if (pix<grad[i-1][j+1] && ++nmax > num) continue;
266                 if (pix<grad[i][j-1]   && ++nmax > num) continue;
267                 if (pix<grad[i][j+1]   && ++nmax > num) continue;
268                 if (pix<grad[i+1][j-1] && ++nmax > num) continue;
269                 if (pix<grad[i+1][j]   && ++nmax > num) continue;
270                 if (pix<grad[i+1][j+1] && ++nmax > num) continue;
271 */
272 
273                 delx = j + 0.5 - pos.el[0];
274                 dely = i + 0.5 - pos.el[1];
275 /*                weight = exp((-delx*delx - dely*dely)/twosigma2);
276 */
277                 if (delx*delx + dely*dely < twosigma2*2.0) weight = 1.0;
278                 else weight = 0.0;
279                 meanx += delx*weight;
280                 meany += dely*weight;
281             }
282         }
283     }
284 
285 
286     if (meanx ==0) orient = 0; /* ### should be undefined */
287     else
288         orient = atan2(meany,meanx);
289 
290     farray_free(grad,ly,lx,uy,ux);
291     return(orient);
292 }
293 

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