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

Linux Cross Reference
Tina4/src/vision/improc/corner.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #include <math.h>
  2 #include <tina/sys.h>
  3 #include <tina/sysfuncs.h>
  4 #include <tina/math.h>
  5 #include <tina/mathfuncs.h>
  6 #include <tina/vision.h>
  7 #include <tina/visionfuncs.h>
  8 
  9 Imrect *corner2(Imrect *im,double sigma,double precision,double lowthres)
 10 {
 11     Imrect *gim,*corn_im;
 12     Imrect *maxim;
 13     Imrect *gradx, *grady;
 14 
 15     gradx = imf_grad_h(im);
 16     grady = imf_grad_v(im);
 17 
 18     gim = imf_gauss(im,sigma,precision);
 19     corn_im = cornim(gim,sigma,precision,0.0);
 20     maxim = imf_nmax(corn_im,(float)(1024.0*lowthres),0);
 21     corner_locate(maxim,corn_im,gradx,grady);
 22     im_free(corn_im);
 23     im_free(gim);
 24     im_free(gradx);
 25     im_free(grady);
 26  
 27     return(maxim);
 28 }
 29  
 30 Imrect *corner(Imrect *im,double sigma,double precision,double lowthres)
 31 {
 32     Imrect *gim,*corn_im;
 33     Imrect *maxim;
 34     Imrect *gradx, *grady;
 35 
 36     gradx = imf_grad_h(im);
 37     grady = imf_grad_v(im);
 38 
 39     corn_im = cornim(im,sigma,precision,0.05);
 40     gim = imf_gauss(corn_im,sigma,precision);
 41     im_free(corn_im);
 42     maxim = imf_nmax(gim,(float)(1024.0*lowthres),0);
 43     corner_locate(maxim,gim,gradx,grady);
 44     im_free(gim);
 45     im_free(gradx);
 46     im_free(grady);
 47 
 48     return(maxim);
 49 }
 50 
 51 Imrect *cornim(Imrect *im,double sigma,double precision,double edge_sup)
 52 {
 53     Imrect *gimx,*gimy,*gimxy,*gimedge;
 54     Imrect *gradx;
 55     Imrect *grady;
 56     Imrect *gradsqx,*gradsqy,*gradsqxy;
 57     Imrect *gradsqxsqy;
 58     Imrect *corn_im;
 59  
 60     if (im==NULL)
 61         return(NULL);
 62  
 63     gradx = imf_grad_h(im);
 64     grady = imf_grad_v(im);
 65     gradsqx = imf_prod(gradx,gradx);
 66     gradsqy = imf_prod(grady,grady);
 67     gradsqxy = imf_prod(gradx,grady);
 68     im_free(gradx);
 69     im_free(grady);
 70     gradsqxsqy = imf_sum(gradsqx,gradsqy);
 71  
 72     gimx = imf_gauss(gradsqx,sigma,precision);
 73     im_free(gradsqx);
 74     gimy = imf_gauss(gradsqy,sigma,precision);
 75     im_free(gradsqy);
 76     gimxy = imf_gauss(gradsqxy,sigma,precision);
 77     im_free(gradsqxy);
 78     gimedge = imf_gauss(gradsqxsqy,1.1*sigma,precision);
 79     im_free(gradsqxsqy);
 80  
 81     corn_im = cornim2(gimx,gimy,gimxy,gimedge,edge_sup);
 82     im_free(gimx);
 83     im_free(gimy);
 84     im_free(gimxy);
 85     im_free(gimedge);
 86  
 87     return(corn_im);
 88 }
 89  
 90 Imrect *cornim2(Imrect *im1,Imrect *im2,Imrect *im3,Imrect *im4,
 91                                 double edge_sup)
 92 
 93 {
 94     Imrect *cornim;
 95     Imregion *roi;
 96     float *line1,*line2,*line3,*line4;
 97     int lx, ux, ly, uy;
 98     int i,j;
 99  
100     if (im1==NULL || im2==NULL || im3==NULL)
101         return(NULL);
102  
103     roi = im1->region;
104  
105     if  (roi==NULL)
106         return(NULL);
107  
108     cornim = im_alloc(im1->height,im1->width,roi,float_v);
109  
110     lx = roi->lx;
111     ux = roi->ux;
112     ly = roi->ly;
113     uy = roi->uy;
114  
115     line1 = fvector_alloc(lx, ux);
116     line2 = fvector_alloc(lx, ux);
117     line3 = fvector_alloc(lx, ux);
118     line4 = fvector_alloc(lx, ux);
119  
120     for (i=ly;i<uy;++i)
121     {
122         im_get_rowf(line1,im1,i,lx,ux);
123         im_get_rowf(line2,im2,i,lx,ux);
124         im_get_rowf(line3,im3,i,lx,ux);
125         im_get_rowf(line4,im4,i,lx,ux);
126 
127                 /* this next line previously used IM_FLOAT_INDEX (sam) */
128         for (j=lx;j<ux;++j)
129                         IM_FLOAT( cornim, i,j) = (float)(line1[j]*line2[j]-line3[j]*line3[j] - 
130                                                  edge_sup*line4[j]*line4[j]);
131     }
132  
133     fvector_free(line1, lx);
134     fvector_free(line2, lx);
135     fvector_free(line3, lx);
136     fvector_free(line4, lx);
137     return(cornim);
138 }
139  
140 void    corner_locate(Imrect * im, Imrect * corner_im, Imrect *gradx , Imrect *grady)
141 {
142      Imregion *region;
143      float x,y;
144      int i,j;
145      int lx,ux,ly,uy; 
146  
147      if (im==NULL ||  corner_im==NULL) return;
148  
149      region = im->region;
150  
151      lx = region->lx+1;
152      ux = region->ux-1;
153      ly = region->ly+1;
154      uy = region->uy-1;
155  
156      for (i=ly;i<uy;++i)
157      {
158          for (j=lx;j<ux;++j)
159          {
160               Edgel *eptr;
161  
162                           if ((eptr=IM_PTR(im, i,j)) == NULL) continue;
163  
164               eptr->contrast =(float)im_get_quadmaxf(corner_im,(float)j,(float)i,&x,&y);
165               eptr->pos = vec2(x,y);
166               eptr->type &= EDGE_GET_CONN_MASK;
167               eptr->type |= EDGE_ISOLATED;
168                           eptr->orient = (float)cor_orient( eptr->pos, 10.0, gradx,grady);
169 
170          }
171      }
172 }
173 
174 double cor_orient(Vec2 pos,double range,Imrect *gradx,Imrect *grady)
175 /* see nat */
176 {
177     int lx,ux,ly,uy;
178     int i,j;
179     double meanx=0.0,meany=0.0;
180     double dx,dy, delx,dely;
181     double twosigma2 = range*range/2.0; /* set the scale of radial weighting */
182     double orient;
183     double weight;
184     double thresh=0.0;
185     float **grad;
186     float pix;
187 
188     lx = tina_int(pos.el[0]-range)-1;
189     ux = tina_int(pos.el[0]+range+1)+1;
190     ly = tina_int(pos.el[1]-range)-1;
191     uy = tina_int(pos.el[1]+range+1)+1;
192     grad = farray_alloc(ly,lx,uy,ux);
193 
194 /* calculate a robust mean with which to threshold the likely edge pixels */
195     for (i=ly;i<uy;++i)
196     {
197         for (j=lx;j<ux;++j)
198         {
199             dx = im_get_pixf(gradx,i,j);
200             dy = im_get_pixf(grady,i,j);
201             grad[i][j] = dx*dx + dy*dy;
202             thresh += grad[i][j];
203         }
204     }
205 
206     thresh /= ((ux-lx)*(uy-ly));
207 
208 /* calculate the orientation from the moments of the thresholded gradient image */
209     for (i=ly+1;i<uy-1;++i)
210     {
211         for (j=lx+1;j<ux-1;++j)
212         {
213             if ((pix=grad[i][j]) > thresh)
214             {
215 /*
216                 int num = 2;
217                 int nmax = 0;
218                 if (pix<grad[i-1][j-1] && ++nmax > num) continue;
219                 if (pix<grad[i-1][j]   && ++nmax > num) continue;
220                 if (pix<grad[i-1][j+1] && ++nmax > num) continue;
221                 if (pix<grad[i][j-1]   && ++nmax > num) continue;
222                 if (pix<grad[i][j+1]   && ++nmax > num) continue;
223                 if (pix<grad[i+1][j-1] && ++nmax > num) continue;
224                 if (pix<grad[i+1][j]   && ++nmax > num) continue;
225                 if (pix<grad[i+1][j+1] && ++nmax > num) continue;
226 */
227 
228                 delx = j + 0.5 - pos.el[0];
229                 dely = i + 0.5 - pos.el[1];
230 /*                weight = exp((-delx*delx - dely*dely)/twosigma2);
231 */
232                 if (delx*delx + dely*dely < twosigma2*2.0) weight = 1.0;
233                 else weight = 0.0;
234                 meanx += delx*weight;
235                 meany += dely*weight;
236             }
237         }
238     }
239 
240 
241     if (meanx ==0) orient = 0; /* ### should be undefined */
242     else
243         orient = atan2(meany,meanx);
244 
245     farray_free(grad,ly,lx,uy,ux);
246     return(orient);
247 }
248 

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