1 /**@(#)
2 **/
3 #include <math.h>
4 #include <tina/sys.h>
5 #include <tina/sysfuncs.h>
6 #include <tina/math.h>
7 #include <tina/mathfuncs.h>
8
9 void morph_spere(double r, Imrect ** el_val)
10 /* radius about origin */
11 {
12 int lx, ly, ux, uy;
13 int i, j;
14 double rsq;
15 Imregion *roi;
16
17 lx = ly = (int) -r;
18 ux = uy = (int) (r + 1);
19 roi = roi_alloc(lx, ly, ux, uy);
20
21 *el_val = im_alloc(uy, ux, roi, float_v);
22 rfree((void *) roi);
23
24 rsq = r * r;
25
26 for (i = ly; i < uy; ++i)
27 for (j = lx; j < ux; ++j)
28 {
29 int d = i * i + j * j;
30
31 if (d > rsq)
32 {
33 IM_FLOAT(*el_val, i, j) = (float) 0.0;
34 continue;
35 }
36 IM_FLOAT(*el_val, i, j) = (float) sqrt(rsq - d);
37 }
38 }
39
40 Imrect *imf_dilate(Imrect * im1, Imrect * el_val)
41 /* image to be dilated */
42 /* value of dilation mask zero value external to the mask */
43 {
44 Imrect *im2;
45 Vartype vtype;
46 Imregion *roi;
47 double val;
48 int lx, ux, ly, uy;
49 int m_lx, m_ux, m_ly, m_uy;
50 int i, j;
51
52 if (im1 == NULL || el_val == NULL)
53 return (NULL);
54
55 roi = el_val->region;
56 if (roi == NULL)
57 return (NULL);
58 m_lx = roi->lx;
59 m_ux = roi->ux;
60 m_ly = roi->ly;
61 m_uy = roi->uy;
62
63 roi = im1->region;
64 if (roi == NULL)
65 return (NULL);
66 lx = roi->lx;
67 ux = roi->ux;
68 ly = roi->ly;
69 uy = roi->uy;
70
71 vtype = (el_val == NULL) ? im1->vtype : (Vartype) MAX((int) im1->vtype, (int) el_val->vtype);
72 im2 = im_alloc(im1->height, im1->width, roi, vtype);
73
74 for (i = ly; i < uy; ++i)
75 for (j = lx; j < ux; ++j)
76 {
77 double gl, max_gl = 0;
78 int ii, jj;
79 int not_set = 1;
80
81 for (ii = m_ly; ii < m_uy; ++ii)
82 for (jj = m_lx; jj < m_ux; ++jj)
83 {
84 int x = j + jj, y = i + ii;
85
86 if (x >= lx && x < ux && y >= ly && y < uy) /* in image */
87 {
88 IM_PIX_GET(el_val, ii, jj, val);
89 if (val==0.0) continue;
90 IM_PIX_GET(im1, y, x, gl);
91
92 gl += val;
93 if (not_set || gl > max_gl)
94 {
95 max_gl = gl;
96 not_set = 0;
97 }
98 }
99 }
100
101 IM_PIX_SET(im2, i, j, max_gl);
102 }
103
104 return (im2);
105 }
106
107 Imrect *imf_erode(Imrect * im1, Imrect * el_val)
108 /* image to be eroded */
109 /* value of dilation mask non-zero for active region */
110 {
111 Imrect *im2;
112 Vartype vtype;
113 Imregion *roi;
114 double val;
115 int lx, ux, ly, uy;
116 int m_lx, m_ux, m_ly, m_uy;
117 int i, j;
118
119 if (im1 == NULL || el_val==NULL)
120 return (NULL);
121
122 roi = el_val->region;
123 if (roi == NULL)
124 return (NULL);
125 m_lx = roi->lx;
126 m_ux = roi->ux;
127 m_ly = roi->ly;
128 m_uy = roi->uy;
129
130 roi = im1->region;
131 if (roi == NULL)
132 return (NULL);
133 lx = roi->lx;
134 ux = roi->ux;
135 ly = roi->ly;
136 uy = roi->uy;
137
138 vtype = (el_val == NULL) ? im1->vtype : (Vartype) MAX((int) im1->vtype, (int) el_val->vtype);
139 im2 = im_alloc(im1->height, im1->width, roi, vtype);
140
141 for (i = ly; i < uy; ++i)
142 for (j = lx; j < ux; ++j)
143 {
144 double gl, min_gl = 0;
145 int ii, jj;
146 int not_set = 1;
147
148 for (ii = m_ly; ii < m_uy; ++ii)
149 for (jj = m_lx; jj < m_ux; ++jj)
150 {
151 int x = j + jj, y = i + ii;
152
153 if (x >= lx && x < ux && y >= ly && y < uy) /* in image */
154 {
155 IM_PIX_GET(el_val, ii, jj, val);
156 if (val==0.0) continue;
157 IM_PIX_GET(im1, y, x, gl);
158 gl -= val;
159 if (not_set || gl < min_gl)
160 {
161 min_gl = gl;
162 not_set = 0;
163 }
164 }
165 }
166
167 IM_PIX_SET(im2, i, j, min_gl);
168 }
169
170 return (im2);
171 }
172
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.