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

Linux Cross Reference
Tina5/tina-libs/tina/geometry/geomImg_nonmax.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_nonmax.c,v $
 23  * Date    :  $Date: 2009/03/19 18:36:26 $
 24  * Version :  $Revision: 1.3 $
 25  * CVS Id  :  $Id: geomImg_nonmax.c,v 1.3 2009/03/19 18:36:26 paul Exp $
 26  *
 27  * Author  : Legacy TINA
 28  *
 29  * Notes : nonmax.c
 30  * 
 31  * locate directional peak in gradsq image of type float using non maximal
 32  * suppresion and form appropriate edge rect
 33  * 
 34  * fit is performed to sub pixel acuity using quadratic fit across peak in
 35  * quantised direction
 36  * 
 37  * if sub pix falls outside pixel ignore it
 38  *
 39  *********
 40 */
 41 
 42 #include "geomImg_nonmax.h"
 43 
 44 #if HAVE_CONFIG_H
 45   #include <config.h>
 46 #endif
 47 
 48 #include <math.h>
 49 #include <tina/sys/sysDef.h>
 50 #include <tina/sys/sysPro.h>
 51 #include <tina/math/mathDef.h>
 52 #include <tina/math/mathPro.h>
 53 #include <tina/image/imgDef.h>
 54 #include <tina/image/imgPro.h>
 55 #include <tina/geometry/geom_EdgeDef.h>
 56 #include <tina/geometry/geom_EdgePro.h>
 57 
 58 
 59 Imrect *nonmaxsup(Imrect * gradx, Imrect * grady, Imrect * gradsq, double thres)
 60 {
 61     Imrect *edge_image;
 62     Imregion *region;
 63     int     i, j;
 64     int     lx, ux, ly, uy;
 65     int     uxm1, uym1;
 66     float   sqthres = (float)(thres * thres);
 67     float  *rowx, *rowy;
 68     float  *grad, *grad_m1, *grad_p1;
 69 
 70     if (gradx == NULL || grady == NULL || gradsq == NULL)
 71         return (NULL);
 72 
 73     region = gradsq->region;
 74 
 75     edge_image = im_alloc(gradsq->height, gradsq->width, region, ptr_v);
 76     region = edge_image->region;
 77 
 78     lx = region->lx;
 79     ux = region->ux;
 80     ly = region->ly;
 81     uy = region->uy;
 82 
 83     uxm1 = ux - 1;
 84     uym1 = uy - 1;
 85 
 86     rowx = fvector_alloc(lx, ux);
 87     rowy = fvector_alloc(lx, ux);
 88     grad = fvector_alloc(lx, ux);
 89     grad_m1 = fvector_alloc(lx, ux);
 90     grad_p1 = fvector_alloc(lx, ux);
 91 
 92     for (i = ly + 1; i < uym1; ++i)
 93     {
 94         im_get_rowf(rowy, grady, i, lx, ux);
 95         im_get_rowf(rowx, gradx, i, lx, ux);
 96         im_get_rowf(grad, gradsq, i, lx, ux);
 97         im_get_rowf(grad_p1, gradsq, i + 1, lx, ux);
 98         im_get_rowf(grad_m1, gradsq, i - 1, lx, ux);
 99 
100         for (j = lx + 1; j < uxm1; ++j)
101         {
102             float   a, b;
103             float   st;
104             float   del;
105             float   dr, dc;
106             float   gradratio, fabsgradratio;
107             Edgel  *eptr;
108             Vec2    pos = {Vec2_id};
109 
110             if (grad[j] < sqthres)
111                 continue;
112 
113             st = grad[j];
114             gradratio = rowx[j] / rowy[j];
115             fabsgradratio = (float)fabs(gradratio);
116             if (fabsgradratio < 1.5 && fabsgradratio > 0.67)    /* diagonal */
117             {
118                 if ((st < grad[j - 1] || st <= grad[j + 1]) &&
119                     (st < grad_m1[j] || st <= grad_p1[j]))
120                     continue;
121                 if (gradratio > 0)      /* right diagonal */
122                 {
123                     if (st < grad_m1[j - 1] || st <= grad_p1[j + 1])
124                         continue;
125                     st = (float)sqrt(st);
126                     a = (float)sqrt(grad_m1[j - 1]);
127                     b = (float)sqrt(grad_p1[j + 1]);
128                     del = (a - b) / ((a + b - st * 2) * 2);
129                     dr = (float)(del + 0.5);
130                     dc = (float)(del + 0.5);
131                 } else
132                 {
133                     if (st < grad_p1[j - 1] || st <= grad_m1[j + 1])
134                         continue;
135                     st = (float)sqrt(st);
136                     a = (float)sqrt(grad_p1[j - 1]);
137                     b = (float)sqrt(grad_m1[j + 1]);
138                     del = (a - b) / ((a + b - st * 2) * 2);
139                     dr = (float)(0.5 - del);
140                     dc = (float)(del + 0.5);
141                 }
142             } else if (fabs(rowx[j]) > fabs(rowy[j]))
143             {
144                 if (st < grad[j - 1] || st <= grad[j + 1])
145                     continue;
146                 st = (float)sqrt(st);
147                 a = (float)sqrt(grad[j - 1]);
148                 b = (float)sqrt(grad[j + 1]);
149                 del = (a - b) / ((a + b - st * 2) * 2);
150                 dr = (float)0.5;
151                 dc = (float)(del + 0.5);
152             } else
153             {
154                 if (st < grad_m1[j] || st <= grad_p1[j])
155                     continue;
156                 st = (float)sqrt(st);
157                 a = (float)sqrt(grad_m1[j]);
158                 b = (float)sqrt(grad_p1[j]);
159                 del = (a - b) / ((a + b - st * 2) * 2);
160                 dr = (float)(del + 0.5);
161                 dc = (float)0.5;        /* pixel centre */
162             }
163 
164             {
165                 int     ii, jj; /* actual storage location */
166 
167                 pos = vec2(j + dc, i + dr);
168                 jj = (int)floor(vec2_x(pos));
169                 ii = (int)floor(vec2_y(pos));
170                 if (ii < ly || ii >= uy || jj < lx || jj >= ux ||
171                     IM_PTR(edge_image, ii, jj) != NULL)
172                     continue;
173 
174                 eptr = edge_alloc(EDGE_RAW);
175                 eptr->pos = pos;
176                 eptr->orient = (float)atan2(rowx[j], rowy[j]);
177                 eptr->contrast = st;
178                 IM_PTR(edge_image, ii, jj) = (void *) eptr;
179             }
180         }
181     }
182     fvector_free(rowx, lx);
183     fvector_free(rowy, lx);
184     fvector_free(grad, lx);
185     fvector_free(grad_m1, lx);
186     fvector_free(grad_p1, lx);
187     return (edge_image);
188 }
189 

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