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

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

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