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
8 float array_max(float **in, int i, int j, int num, float thresh)
9 {
10 int nmax=0;
11 float *row, *above, *below, pix;
12
13 if (in==NULL) return((float)0.0);
14
15 row = in[i];
16 above = in[i-1];
17 below = in[i+1];
18
19 if ((pix = (float)fabs(row[j])) > thresh)
20 {
21 if (pix < fabs(above[j-1]) && ++nmax > num) ;
22 else if (pix < fabs(above[j]) && ++nmax > num) ;
23 else if (pix < fabs(above[j+1]) && ++nmax > num) ;
24 else if (pix < fabs(row [j-1]) && ++nmax > num) ;
25 else if (pix < fabs(row [j+1]) && ++nmax > num) ;
26 else if (pix < fabs(below[j-1]) && ++nmax > num) ;
27 else if (pix < fabs(below[j]) && ++nmax > num) ;
28 else if (pix < fabs(below[j+1]) && ++nmax > num) ;
29 }
30 else
31 {
32 return((float)0.0);
33 }
34
35 if (nmax > num) return((float)0.0);
36 else return(pix);
37 }
38
39 float imf_pixmax(Imrect *im, int i, int j, int num, float thresh)
40 {
41 float **array;
42 Imregion *roi;
43
44 if (im==NULL)
45 return((float)0.0);
46 if ((roi = im->region) == NULL)
47 return((float)0.0);
48 if (i<roi->ly+1 || i>roi->uy-2 || j<roi->lx+1 || j>roi->ux-2)
49 return((float)0.0);
50
51 array = (float **)im->data;
52 return(array_max(array, i, j, num, thresh));
53 }
54
55 Imrect *imf_nmax(Imrect *im,float thres,int num)
56 {
57 Imrect *maxim;
58 Imregion *region;
59 float *max,*max_m1,*max_p1;
60 float pix;
61 Vec2 pos = {Vec2_id};
62 int i,j,nmax;
63 int lx,ux,ly,uy;
64 int uxm1,uym1;
65
66 if (im==NULL) return(NULL);
67
68 maxim = im_alloc(im->height,im->width,im->region,ptr_v);
69 region = maxim->region;
70 lx = region->lx;
71 ux = region->ux;
72 ly = region->ly;
73 uy = region->uy;
74
75 max = fvector_alloc(lx, ux);
76 max_m1 = fvector_alloc(lx, ux);
77 max_p1 = fvector_alloc(lx, ux);
78
79 uxm1 = ux-1;
80 uym1 = uy-1;
81
82 for (i=ly+1;i<uym1;++i)
83 {
84 im_get_rowf(max,im,i,lx,ux);
85 im_get_rowf(max_m1,im,i-1,lx,ux);
86 im_get_rowf(max_p1,im,i+1,lx,ux);
87
88 for (j=lx+1;j<uxm1;++j)
89 {
90 Edgel *eptr, *edge_alloc();
91
92 if ((pix = (float)max[j])<thres) continue;
93
94 nmax = 0;
95
96 if (pix<max_m1[j-1] && ++nmax > num) continue;
97 if (pix<max_m1[j] && ++nmax > num) continue;
98 if (pix<max_m1[j+1] && ++nmax > num) continue;
99 if (pix<max[j-1] && ++nmax > num) continue;
100 if (pix<max[j+1] && ++nmax > num) continue;
101 if (pix<max_p1[j-1] && ++nmax > num) continue;
102 if (pix<max_p1[j] && ++nmax > num) continue;
103 if (pix<max_p1[j+1] && ++nmax > num) continue;
104
105 eptr=edge_alloc(EDGE_RAW);
106 pos = vec2(j + 0.5, i + 0.5);
107 eptr->pos = pos;
108 eptr->orient = 0.0;
109 eptr->contrast = pix;
110 IM_PTR(maxim, i, j) = (void *)eptr;
111 }
112 }
113 fvector_free(max, lx);
114 fvector_free(max_m1, lx);
115 fvector_free(max_p1, lx);
116 return(maxim);
117 }
118
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.