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

Linux Cross Reference
Tina6/tina-libs/tina/geometry/geomImg_max.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_max.c,v $
 27  * Date    :  $Date: 2009/03/19 18:36:26 $
 28  * Version :  $Revision: 1.2 $
 29  * CVS Id  :  $Id: geomImg_max.c,v 1.2 2009/03/19 18:36:26 paul Exp $
 30  *
 31  * Author  : Legacy TINA
 32  *
 33  * Notes :
 34  *
 35  *********
 36 */
 37 
 38 #include "geomImg_max.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/geom_EdgePro.h>
 53 
 54 
 55 float       array_max(float **in, int i, int j, int num, float thresh)
 56 {
 57         int        nmax=0;
 58         float     *row, *above, *below, pix;
 59 
 60         if (in==NULL) return((float)0.0);
 61 
 62         row   = in[i];
 63         above = in[i-1];
 64         below = in[i+1];
 65 
 66         if ((pix = (float)fabs(row[j])) > thresh)
 67         {
 68                 if      (pix < fabs(above[j-1]) && ++nmax > num) ;
 69                 else if (pix < fabs(above[j])   && ++nmax > num) ;
 70                 else if (pix < fabs(above[j+1]) && ++nmax > num) ;
 71                 else if (pix < fabs(row  [j-1]) && ++nmax > num) ;
 72                 else if (pix < fabs(row  [j+1]) && ++nmax > num) ;
 73                 else if (pix < fabs(below[j-1]) && ++nmax > num) ;
 74                 else if (pix < fabs(below[j])   && ++nmax > num) ;
 75                 else if (pix < fabs(below[j+1]) && ++nmax > num) ;
 76         }
 77         else
 78         {
 79                 return((float)0.0);
 80         }
 81 
 82         if (nmax > num) return((float)0.0);
 83         else            return(pix);
 84 }
 85 
 86 float       imf_pixmax(Imrect *im, int i, int j, int num, float thresh)
 87 {
 88         float     **array;
 89         Imregion   *roi;
 90 
 91         if (im==NULL)
 92                 return((float)0.0);
 93         if ((roi = im->region) == NULL)
 94                 return((float)0.0);
 95         if (i<roi->ly+1 || i>roi->uy-2 || j<roi->lx+1 || j>roi->ux-2)
 96                 return((float)0.0);
 97 
 98         array = (float **)im->data;
 99         return(array_max(array, i, j, num, thresh));
100 }
101 
102 Imrect *imf_nmax(Imrect *im,float thres,int num)
103 {
104      Imrect *maxim;
105      Imregion *region;
106      float *max,*max_m1,*max_p1;
107      float pix;
108      Vec2    pos = {Vec2_id};
109      int i,j,nmax;
110      int lx,ux,ly,uy;
111      int uxm1,uym1;
112 
113      if (im==NULL) return(NULL);
114 
115      maxim = im_alloc(im->height,im->width,im->region,ptr_v);
116      region = maxim->region;
117      lx = region->lx;
118      ux = region->ux;
119      ly = region->ly;
120      uy = region->uy;
121 
122      max = fvector_alloc(lx, ux);
123      max_m1 = fvector_alloc(lx, ux);
124      max_p1 = fvector_alloc(lx, ux);
125 
126      uxm1 = ux-1;
127      uym1 = uy-1;
128 
129      for (i=ly+1;i<uym1;++i)
130      {
131          im_get_rowf(max,im,i,lx,ux);
132          im_get_rowf(max_m1,im,i-1,lx,ux);
133          im_get_rowf(max_p1,im,i+1,lx,ux);
134 
135          for (j=lx+1;j<uxm1;++j)
136          {
137               Edgel *eptr;
138 
139               if ((pix = (float)max[j])<thres) continue;
140 
141               nmax = 0;
142 
143               if (pix<max_m1[j-1] && ++nmax > num) continue;
144               if (pix<max_m1[j]   && ++nmax > num) continue;
145               if (pix<max_m1[j+1] && ++nmax > num) continue;
146               if (pix<max[j-1]    && ++nmax > num) continue;
147               if (pix<max[j+1]    && ++nmax > num) continue;
148               if (pix<max_p1[j-1] && ++nmax > num) continue;
149               if (pix<max_p1[j]   && ++nmax > num) continue;
150               if (pix<max_p1[j+1] && ++nmax > num) continue;
151 
152               eptr=edge_alloc(EDGE_RAW);
153               pos = vec2(j + 0.5, i + 0.5);
154               eptr->pos = pos;
155               eptr->orient = 0.0;
156               eptr->contrast = pix;
157               IM_PTR(maxim, i, j) = (void *)eptr;
158          }
159      }
160      fvector_free(max, lx);
161      fvector_free(max_m1, lx);
162      fvector_free(max_p1, lx);
163      return(maxim);
164 }
165 

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