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

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

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