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

Linux Cross Reference
Tina4/src/vision/improc/im_deriv.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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 #include <tina/vision.h>
  9 #include <tina/visionfuncs.h>
 10 
 11 /** applying functions to images, inplace version, and special cases **/
 12 
 13 Imrect *imf_diffx(Imrect * im1)
 14 {
 15     Imrect *im2;
 16     Imregion *roi;
 17     float  *row1, *row2;
 18     int     lx, ux, ly, uy;
 19     int     i, j;
 20 
 21     if (im1 == NULL)
 22         return (NULL);
 23 
 24     roi = im1->region;
 25 
 26     if (roi == NULL)
 27         return (NULL);
 28 
 29     lx = roi->lx;
 30     ux = roi->ux;
 31     ly = roi->ly;
 32     uy = roi->uy;
 33 
 34     if (lx == ux)
 35         return (NULL);
 36 
 37     im2 = im_alloc(im1->height, im1->width, roi, float_v);
 38     row1 = fvector_alloc(lx, ux);
 39     row2 = fvector_alloc(lx, ux);
 40 
 41     for (i = ly; i < uy; ++i)
 42     {
 43         im_get_rowf(row1, im1, i, lx, ux);
 44         row2[lx] = row1[lx + 1] - row1[lx];
 45         for (j = lx + 1; j < ux - 1; ++j)
 46             row2[j] = (float)(0.5 * (row1[j + 1] - row1[j - 1]));
 47         row2[ux - 1] = row1[ux - 1] - row1[ux - 2];
 48         im_put_rowf(row2, im2, i, lx, ux);
 49     }
 50 
 51     fvector_free((void *) row1, lx);
 52     fvector_free((void *) row2, lx);
 53     return (im2);
 54 }
 55 
 56 Imrect *imf_diffy(Imrect * im1)
 57 {
 58     Imrect *im2;
 59     Imregion *roi;
 60     float  *col1, *col2;
 61     int     lx, ux, ly, uy;
 62     int     i, j;
 63 
 64     if (im1 == NULL)
 65         return (NULL);
 66 
 67     roi = im1->region;
 68 
 69     if (roi == NULL)
 70         return (NULL);
 71 
 72     lx = roi->lx;
 73     ux = roi->ux;
 74     ly = roi->ly;
 75     uy = roi->uy;
 76 
 77     if (ly == uy)
 78         return (NULL);
 79 
 80     im2 = im_alloc(im1->height, im1->width, roi, float_v);
 81     col1 = fvector_alloc(ly, uy);
 82     col2 = fvector_alloc(ly, uy);
 83 
 84     for (i = lx; i < ux; ++i)
 85     {
 86         im_get_colf(col1, im1, i, ly, uy);
 87         col2[ly] = col1[ly + 1] - col1[ly];
 88         for (j = ly + 1; j < uy - 1; ++j)
 89             col2[j] = (float)(0.5 * (col1[j + 1] - col1[j - 1]));
 90         col2[uy - 1] = col1[uy - 1] - col1[uy - 2];
 91         im_put_colf(col2, im2, i, ly, uy);
 92     }
 93 
 94     fvector_free((void *) col1, ly);
 95     fvector_free((void *) col2, ly);
 96     return (im2);
 97 }
 98 
 99 /* set both x and y derivatives */
100 void    im_grad(Imrect * im, Imrect ** imx, Imrect ** imy)
101 {
102     *imx = imf_diffx(im);
103     *imy = imf_diffy(im);
104 }
105 
106 /* set both x and y derivatives, and second derivatives (if first
107  * derivs un-needed, pass null pointer) */
108 
109 void    im_hessian(Imrect * im, Imrect ** imx, Imrect ** imy, Imrect ** imxx, Imrect ** imxy, Imrect ** imyy)
110 {
111     Imrect *imx1;
112     Imrect *imy1;
113 
114     imx1 = imf_diffx(im);
115     imy1 = imf_diffy(im);
116     *imxx = imf_diffx(imx1);
117 
118     if (imx == NULL)
119         im_free(imx1);
120     else
121         *imx = imx1;
122 
123     *imxy = imf_diffx(imy1);
124     *imyy = imf_diffy(imy1);
125 
126     if (imy == NULL)
127         im_free(imy1);
128     else
129         *imy = imy1;
130 }
131 
132 /** image differential invariants **/
133 
134 /* Laplacian */
135 
136 Imrect *imf_laplacian(Imrect * im)
137 {
138     Imrect *imx;
139     Imrect *imxx;
140     Imrect *imy;
141     Imrect *imyy;
142 
143     imx = imf_diffx(im);
144     imxx = imf_diffx(imx);
145     im_free(imx);
146     imy = imf_diffy(im);
147     imyy = imf_diffy(imy);
148     im_free(imy);
149     im = imf_sum(imxx, imyy);
150     im_free(imxx);
151     im_free(imyy);
152     return (im);
153 }
154 
155 /* Squared gradient */
156 
157 Imrect *imf_sqrgrad(Imrect * im)
158 {
159     Imrect *imx;
160     Imrect *imxx;
161     Imrect *imy;
162     Imrect *imyy;
163 
164     imx = imf_diffx(im);
165     imxx = imf_sqr(imx);
166     im_free(imx);
167     imy = imf_diffy(im);
168     imyy = imf_sqr(imy);
169     im_free(imy);
170     im = imf_sum(imxx, imyy);
171     im_free(imxx);
172     im_free(imyy);
173     return (im);
174 }
175 
176 /* Matrix op */
177 
178 Imrect *imf_matop(Imrect * ax, Imrect * ay, Imrect * mxx, Imrect * mxy, Imrect * myx, Imrect * myy, Imrect * bx, Imrect * by)
179 {
180     Imrect *im1;
181     Imrect *im2;
182     Imrect *mx;
183     Imrect *my;
184     Imrect *m;
185 
186     im1 = imf_prod(mxx, bx);
187     im2 = imf_prod(mxy, by);
188     mx = imf_sum(im1, im2);
189     im_free(im1);
190     im_free(im2);
191 
192     im1 = imf_prod(myx, bx);
193     im2 = imf_prod(myy, by);
194     my = imf_sum(im1, im2);
195     im_free(im1);
196     im_free(im2);
197 
198     im1 = imf_prod(ax, mx);
199     im2 = imf_prod(ay, my);
200     m = imf_sum(im1, im2);
201     im_free(im1);
202     im_free(im2);
203 
204     im_free(mx);
205     im_free(my);
206 
207     return (m);
208 }
209 
210 /* Second order image invariants */
211 
212 Imrect *imf_ddn(Imrect * im)
213 {
214     Imrect *imx;
215     Imrect *imy;
216     Imrect *imxx;
217     Imrect *imxy;
218     Imrect *imyy;
219 
220     im_hessian(im, &imx, &imy, &imxx, &imxy, &imyy);
221     im = imf_matop(imx, imy, imxx, imxy, imxy, imyy, imx, imy);
222 
223     im_free(imx);
224     im_free(imy);
225     im_free(imxx);
226     im_free(imxy);
227     im_free(imyy);
228 
229     return (im);
230 }
231 
232 Imrect *imf_ddt(Imrect * im)
233 {
234     Imrect *tx;
235     Imrect *ty;
236     Imrect *imx;
237     Imrect *imy;
238     Imrect *imxx;
239     Imrect *imxy;
240     Imrect *imyy;
241 
242     im_hessian(im, &imx, &imy, &imxx, &imxy, &imyy);
243 
244     tx = imf_minus(imy);
245     im_free(imy);
246     ty = imx;
247 
248     im = imf_matop(tx, ty, imxx, imxy, imxy, imyy, tx, ty);
249 
250     im_free(tx);
251     im_free(ty);
252     im_free(imxx);
253     im_free(imxy);
254     im_free(imyy);
255 
256     return (im);
257 }
258 
259 /**
260 curvature of contour lines
261 **/
262 
263 Imrect *imf_curv(Imrect * im, double thresh, double val)
264 {
265     Imrect *num;
266     Imrect *den;
267 
268     num = imf_ddt(im);
269     im = imf_sqrgrad(im);
270     den = imf_power(1.5, im);
271     im_free(im);
272     im = imf_div(num, den, thresh, val);
273     im_free(num);
274     im_free(den);
275     return (im);
276 }
277 

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