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

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

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

  1 /**@(#) handling images of vec2's and mat2's
  2 Some image apply and combine functions are also defined here
  3 **/
  4 
  5 #include <math.h>
  6 #include <tina/sys.h>
  7 #include <tina/sysfuncs.h>
  8 #include <tina/math.h>
  9 #include <tina/mathfuncs.h>
 10 #include <tina/vision.h>
 11 #include <tina/visionfuncs.h>
 12 
 13 /**
 14 applying function to image
 15 ptr -> void
 16 **/
 17 
 18 void    im_ptr_apply(Imrect * im, void (*func) (), void *data)
 19 {
 20     int    *row;
 21     int     lx, ux, ly, uy;
 22     int     i, j;
 23 
 24     if (im == NULL)
 25         return;
 26 
 27     lx = im->region->lx;
 28     ux = im->region->ux;
 29     ly = im->region->ly;
 30     uy = im->region->uy;
 31     row = tvector_alloc(lx, ux, int);
 32 
 33     for (i = ly; i < uy; ++i)
 34     {
 35         im_get_row(row, im, i, lx, ux);
 36         for (j = lx; j < ux; ++j)
 37             (*func) ((void *) row[j], data);
 38     }
 39 
 40     tvector_free(row, lx, int);
 41 }
 42 
 43 /**
 44 applying function to image
 45 ptr -> ptr
 46 **/
 47 
 48 Imrect *im_pp_apply(Imrect * im1, void *(*func) (), void *data)
 49 {
 50     Imrect *im2;
 51     int    *row1, *row2;
 52     int     lx, ux, ly, uy;
 53     int     i, j;
 54 
 55     if (im1 == NULL)
 56         return (NULL);
 57 
 58     lx = im1->region->lx;
 59     ux = im1->region->ux;
 60     ly = im1->region->ly;
 61     uy = im1->region->uy;
 62     im2 = im_alloc(im1->height, im1->width, im1->region, ptr_v);
 63     row1 = tvector_alloc(lx, ux, int);
 64     row2 = tvector_alloc(lx, ux, int);
 65 
 66     for (i = ly; i < uy; ++i)
 67     {
 68         im_get_row(row1, im1, i, lx, ux);
 69         for (j = lx; j < ux; ++j)
 70             row2[j] = (int) (*func) ((void *) row1[j], data);
 71         im_put_row(row2, im2, i, lx, ux);
 72     }
 73 
 74     tvector_free(row1, lx, int);
 75     tvector_free(row2, lx, int);
 76 
 77     return (im2);
 78 }
 79 
 80 /**
 81 applying function to image
 82 ptr -> float
 83 **/
 84 
 85 Imrect *im_pf_apply(Imrect * im1, double (*func) (), void *data)
 86 {
 87     Imrect *im2;
 88     int    *row1;
 89     float  *row2;
 90     int     lx, ux, ly, uy;
 91     int     i, j;
 92 
 93     if (im1 == NULL)
 94         return (NULL);
 95 
 96     lx = im1->region->lx;
 97     ux = im1->region->ux;
 98     ly = im1->region->ly;
 99     uy = im1->region->uy;
100     im2 = im_alloc(im1->height, im1->width, im1->region, float_v);
101     row1 = tvector_alloc(lx, ux, int);
102     row2 = tvector_alloc(lx, ux, float);
103 
104     for (i = ly; i < uy; ++i)
105     {
106         im_get_row(row1, im1, i, lx, ux);
107         for (j = lx; j < ux; ++j)
108             row2[j] = (float)((*func) ((void *) row1[j], data));
109         im_put_rowf(row2, im2, i, lx, ux);
110     }
111 
112     tvector_free(row1, lx, int);
113     tvector_free(row2, lx, float);
114 
115     return (im2);
116 }
117 
118 /**
119 combining two images
120 ptr ptr -> ptr
121 **/
122 
123 Imrect *im_ppp_combine(Imrect * im1, Imrect * im2, void *(*func) (), void *data)
124 {
125     Imrect *im3;
126     Imregion *roi;
127     int    *row1, *row2, *row3;
128     int     lx, ux, ly, uy;
129     int     width, height;
130     int     i, j;
131 
132     if (im1 == NULL || im2 == NULL)
133         return (NULL);
134 
135     roi = roi_inter(im1->region, im2->region);
136     if (roi == NULL)
137         return (NULL);
138     lx = roi->lx;
139     ux = roi->ux;
140     ly = roi->ly;
141     uy = roi->uy;
142 
143     width = MIN(im1->width, im2->width);
144     height = MIN(im1->height, im2->height);
145 
146     im3 = im_alloc(height, width, roi, ptr_v);
147     row1 = tvector_alloc(lx, ux, int);
148     row2 = tvector_alloc(lx, ux, int);
149     row3 = tvector_alloc(lx, ux, int);
150 
151     for (i = ly; i < uy; ++i)
152     {
153         im_get_row(row1, im1, i, lx, ux);
154         im_get_row(row2, im2, i, lx, ux);
155         for (j = lx; j < ux; ++j)
156             row3[j] = (int) (*func) ((void *) row1[j], (void *) row2[j], data);
157         im_put_row(row3, im3, i, lx, ux);
158     }
159 
160     tvector_free(row1, lx, int);
161     tvector_free(row2, lx, int);
162     tvector_free(row3, lx, int);
163     rfree((void *) roi);
164     return (im3);
165 }
166 
167 /**
168 combining two images
169 float float -> ptr
170 **/
171 
172 Imrect *im_ffp_combine(Imrect * im1, Imrect * im2, void *(*func) (), void *data)
173 {
174     Imrect *im3;
175     Imregion *roi;
176     float  *row1, *row2;
177     int    *row3;
178     int     lx, ux, ly, uy;
179     int     width, height;
180     int     i, j;
181 
182     if (im1 == NULL || im2 == NULL)
183         return (NULL);
184 
185     roi = roi_inter(im1->region, im2->region);
186     if (roi == NULL)
187         return (NULL);
188     lx = roi->lx;
189     ux = roi->ux;
190     ly = roi->ly;
191     uy = roi->uy;
192 
193     width = MIN(im1->width, im2->width);
194     height = MIN(im1->height, im2->height);
195 
196     im3 = im_alloc(height, width, roi, ptr_v);
197     row1 = tvector_alloc(lx, ux, float);
198     row2 = tvector_alloc(lx, ux, float);
199     row3 = tvector_alloc(lx, ux, int);
200 
201     for (i = ly; i < uy; ++i)
202     {
203         im_get_rowf(row1, im1, i, lx, ux);
204         im_get_rowf(row2, im2, i, lx, ux);
205         for (j = lx; j < ux; ++j)
206             row3[j] = (int) (*func) (row1[j], row2[j], data);
207         im_put_row(row3, im3, i, lx, ux);
208     }
209 
210     tvector_free(row1, lx, float);
211     tvector_free(row2, lx, float);
212     tvector_free(row3, lx, int);
213     rfree((void *) roi);
214     return (im3);
215 }
216 
217 Imrect *im_fffp_combine(Imrect * im1, Imrect * im2, Imrect * im3, void *(*func) (), void *data)
218 {
219     Imrect *im4;
220     Imregion *roi;
221     float  *row1, *row2, *row3;
222     int     *row4;
223     int     lx, ux, ly, uy;
224     int     width, height;
225     int     i, j;
226  
227     if (im1 == NULL || im2 == NULL)
228         return (NULL);
229  
230     roi = roi_inter(im1->region, im2->region);
231     if (roi == NULL)
232         return (NULL);
233     lx = roi->lx;
234     ux = roi->ux;
235     ly = roi->ly;
236     uy = roi->uy;
237  
238     width = MIN(im1->width, im2->width);
239     height = MIN(im1->height, im2->height);
240  
241     im3 = im_alloc(height, width, roi, ptr_v);
242     row1 = tvector_alloc(lx, ux, float);
243     row2 = tvector_alloc(lx, ux, float);
244     row3 = tvector_alloc(lx, ux, float);
245     row4 = tvector_alloc(lx, ux, int);
246  
247     for (i = ly; i < uy; ++i)
248     {
249         im_get_rowf(row1, im1, i, lx, ux);
250         im_get_rowf(row2, im2, i, lx, ux);
251         im_get_rowf(row3, im3, i, lx, ux);
252         for (j = lx; j < ux; ++j)
253             row4[j] = (int) (*func) (row1[j], row2[j], row3[j], data);
254         im_put_row(row4, im4, i, lx, ux);
255     }
256  
257     tvector_free(row1, lx, float);
258     tvector_free(row2, lx, float);
259     tvector_free(row3, lx, float);
260     tvector_free(row4, lx, int);
261     rfree((void *) roi);
262     return (im4);
263 }
264 
265 
266 /**
267 combining two images
268 float ptr -> ptr
269 **/
270 
271 Imrect *im_fpp_combine(Imrect * im1, Imrect * im2, void *(*func) (), void *data)
272 {
273     Imrect *im3;
274     Imregion *roi;
275     float  *row1;
276     int    *row2, *row3;
277     int     lx, ux, ly, uy;
278     int     width, height;
279     int     i, j;
280 
281     if (im1 == NULL || im2 == NULL)
282         return (NULL);
283 
284     roi = roi_inter(im1->region, im2->region);
285     if (roi == NULL)
286         return (NULL);
287     lx = roi->lx;
288     ux = roi->ux;
289     ly = roi->ly;
290     uy = roi->uy;
291 
292     width = MIN(im1->width, im2->width);
293     height = MIN(im1->height, im2->height);
294 
295     im3 = im_alloc(height, width, roi, ptr_v);
296     row1 = tvector_alloc(lx, ux, float);
297     row2 = tvector_alloc(lx, ux, int);
298     row3 = tvector_alloc(lx, ux, int);
299 
300     for (i = ly; i < uy; ++i)
301     {
302         im_get_rowf(row1, im1, i, lx, ux);
303         im_get_row(row2, im2, i, lx, ux);
304         for (j = lx; j < ux; ++j)
305             row3[j] = (int) (*func) (row1[j], (void *) row2[j], data);
306         im_put_row(row3, im3, i, lx, ux);
307     }
308 
309     tvector_free(row1, lx, float);
310     tvector_free(row2, lx, int);
311     tvector_free(row3, lx, int);
312     rfree((void *) roi);
313     return (im3);
314 }
315 
316 /**
317 combining two images
318 ptr ptr -> float
319 **/
320 
321 Imrect *im_ppf_combine(Imrect * im1, Imrect * im2, double (*func) (), void *data)
322 {
323     Imrect *im3;
324     Imregion *roi;
325     int    *row1, *row2;
326     float  *row3;
327     int     lx, ux, ly, uy;
328     int     width, height;
329     int     i, j;
330 
331     if (im1 == NULL || im2 == NULL)
332         return (NULL);
333 
334     roi = roi_inter(im1->region, im2->region);
335     if (roi == NULL)
336         return (NULL);
337     lx = roi->lx;
338     ux = roi->ux;
339     ly = roi->ly;
340     uy = roi->uy;
341 
342     width = MIN(im1->width, im2->width);
343     height = MIN(im1->height, im2->height);
344 
345     im3 = im_alloc(height, width, roi, ptr_v);
346     row1 = tvector_alloc(lx, ux, int);
347     row2 = tvector_alloc(lx, ux, int);
348     row3 = tvector_alloc(lx, ux, float);
349 
350     for (i = ly; i < uy; ++i)
351     {
352         im_get_row(row1, im1, i, lx, ux);
353         im_get_row(row2, im2, i, lx, ux);
354         for (j = lx; j < ux; ++j)
355             row3[j] = (float)((*func) ((void *) row1[j], (void *) row2[j], data));
356         im_put_rowf(row3, im3, i, lx, ux);
357     }
358 
359     tvector_free(row1, lx, int);
360     tvector_free(row2, lx, int);
361     tvector_free(row3, lx, float);
362     rfree((void *) roi);
363     return (im3);
364 }
365 
366 /* free image of vec2's or mat2's */
367 
368 void    im_vec2_free(Imrect * im)
369 {
370     im_ptr_apply(im, rfree, NULL);
371     im_free(im);
372 }
373 
374 void    im_vec3_free(Imrect * im)
375 {
376     im_ptr_apply(im, rfree, NULL);
377     im_free(im);
378 }
379 
380 void    im_mat2_free(Imrect * im)
381 {
382     im_ptr_apply(im, rfree, NULL);
383     im_free(im);
384 }
385 
386 /* make image of ptr's to vec2's x-coord from im1 y-coord from im2 */
387 
388 static void *pvec2_make(double x, double y)
389 {
390     return (vec2_make(vec2(x, y)));
391 }
392 
393 Imrect *im_vec2(Imrect * im1, Imrect * im2)
394 {
395     return (im_ffp_combine(im1, im2, pvec2_make, NULL));
396 }
397 
398 /* add two vec2 images */
399 
400 static void *pvec2_sum(Vec2 * u, Vec2 * v)
401 {
402     return (vec2_make(vec2_sum(*u, *v)));
403 }
404 
405 Imrect *im_vec2_sum(Imrect * u, Imrect * v)
406 {
407     return (im_ppp_combine(u, v, pvec2_sum, NULL));
408 }
409 
410 /* subtract  two vec2 images */
411 
412 static void *pvec2_diff(Vec2 * u, Vec2 * v)
413 {
414     return (vec2_make(vec2_diff(*u, *v)));
415 }
416 
417 Imrect *im_vec2_diff(Imrect * u, Imrect * v)
418 {
419     return (im_ppp_combine(u, v, pvec2_diff, NULL));
420 }
421 
422 /* dot product of two vec2 images */
423 
424 static double pvec2_dot(Vec2 * u, Vec2 * v)
425 {
426     return (vec2_dot(*u, *v));
427 }
428 
429 Imrect *im_vec2_dot(Imrect * u, Imrect * v)
430 {
431     return (im_ppf_combine(u, v, pvec2_dot, NULL));
432 }
433 
434 /* cross product of two vec2 images */
435 
436 static double pvec2_cross(Vec2 * u, Vec2 * v)
437 {
438     return (vec2_cross(*u, *v));
439 }
440 
441 Imrect *im_vec2_cross(Imrect * u, Imrect * v)
442 {
443     return (im_ppf_combine(u, v, pvec2_cross, NULL));
444 }
445 
446 /* product of mat2 image and vec2 image */
447 
448 static void *pmat2_vprod(Mat2 * m, Vec2 * v)
449 {
450     return (vec2_make(mat2_vprod(*m, *v)));
451 }
452 
453 Imrect *im_mat2_vprod(Imrect * m, Imrect * v)
454 {
455     return (im_ppp_combine(m, v, pmat2_vprod, NULL));
456 }
457 
458 /* scalar product of vec2 image, mat2 image and vec2 image */
459 
460 Imrect *im_mat2_sprod(Imrect * u, Imrect * m, Imrect * v)
461 {
462     Imrect *mv = im_mat2_vprod(m, v);
463     Imrect *umv;
464 
465     umv = im_vec2_dot(u, mv);
466     im_ptr_apply(mv, rfree, NULL);
467     return (umv);
468 }
469 
470 /* invert mat2 image */
471 
472 static void *pmat2_inverse(Mat2 * m)
473 {
474     return (mat2_make(mat2_inverse(*m)));
475 }
476 
477 Imrect *im_mat2_inverse(Imrect * m)
478 {
479     return (im_pp_apply(m, pmat2_inverse, NULL));
480 }
481 
482 /* make image of mat2's from images of column vectors */
483 
484 static void *pmat2_of_cols(Vec2 * cx, Vec2 * cy)
485 {
486     return (mat2_make(mat2_of_cols(*cx, *cy)));
487 }
488 
489 Imrect *im_mat2_of_cols(Imrect * cx, Imrect * cy)
490 {
491     return (im_ppp_combine(cx, cy, pmat2_of_cols, NULL));
492 }
493 
494 /* make image of mat2's from images of row vectors */
495 
496 static void *pmat2_of_rows(Vec2 * rx, Vec2 * ry)
497 {
498     return (mat2_make(mat2_of_rows(*rx, *ry)));
499 }
500 
501 Imrect *im_mat2_of_rows(Imrect * rx, Imrect * ry)
502 {
503     return (im_ppp_combine(rx, ry, pmat2_of_rows, NULL));
504 }
505 
506 /* image of gradients */
507 
508 Imrect *im_vec2_grad(Imrect * im)
509 {
510     Imrect *imx = imf_diffx(im);
511     Imrect *imy = imf_diffy(im);
512     Imrect *g;
513 
514     g = im_vec2(imx, imy);
515     im_free(imx);
516     im_free(imy);
517     return (g);
518 }
519 
520 /* setup images of gradients and hessians */
521 
522 void    im_mat2_grad_hessian(Imrect * im, Imrect ** g, Imrect ** h)
523 {
524     Imrect *imx = imf_diffx(im);
525     Imrect *imy = imf_diffy(im);
526     Imrect *gx;
527     Imrect *gy;
528 
529     gx = im_vec2_grad(imx);
530     gy = im_vec2_grad(imy);
531     *g = im_vec2(imx, imy);
532     im_free(imx);
533     im_free(imy);
534     *h = im_mat2_of_cols(gx, gy);
535     im_vec2_free(gx);
536     im_vec2_free(gy);
537 }
538 
539 /* return image of hessians */
540 
541 Imrect *im_mat2_hessian(Imrect * im)
542 {
543     Imrect *g;
544     Imrect *h;
545 
546     im_mat2_grad_hessian(im, &g, &h);
547     im_vec2_free(g);
548     return (h);
549 }
550 
551 /* image of determinants */
552 
553 static double pmat2_det(Mat2 * m)
554 {
555     return (mat2_det(*m));
556 }
557 
558 Imrect *im_mat2_det(Imrect * m)
559 {
560     return (im_pf_apply(m, pmat2_det, NULL));
561 }
562 
563 /* components of vec2 and mat2 images */
564 
565 static double pvec2_x(Vec2 * v)
566 {
567     return (vec2_x(*v));
568 }
569 
570 Imrect *im_vec2_x(Imrect * v)
571 {
572     return (im_pf_apply(v, pvec2_x, NULL));
573 }
574 
575 static double pvec2_y(Vec2 * v)
576 {
577     return (vec2_y(*v));
578 }
579 
580 Imrect *im_vec2_y(Imrect * v)
581 {
582     return (im_pf_apply(v, pvec2_y, NULL));
583 }
584 
585 static double pmat2_xx(Mat2 * m)
586 {
587     return (mat2_xx(*m));
588 }
589 
590 Imrect *im_mat2_xx(Imrect * m)
591 {
592     return (im_pf_apply(m, pmat2_xx, NULL));
593 }
594 
595 static double pmat2_xy(Mat2 * m)
596 {
597     return (mat2_xy(*m));
598 }
599 
600 Imrect *im_mat2_xy(Imrect * m)
601 {
602     return (im_pf_apply(m, pmat2_xy, NULL));
603 }
604 
605 static double pmat2_yx(Mat2 * m)
606 {
607     return (mat2_yx(*m));
608 }
609 
610 Imrect *im_mat2_yx(Imrect * m)
611 {
612     return (im_pf_apply(m, pmat2_yx, NULL));
613 }
614 
615 static double pmat2_yy(Mat2 * m)
616 {
617     return (mat2_yy(*m));
618 }
619 
620 Imrect *im_mat2_yy(Imrect * m)
621 {
622     return (im_pf_apply(m, pmat2_yy, NULL));
623 }
624 
625 /* make image of ptr's to vec3's coords from im1 im2 im3 */
626  
627 static void *pvec3_make(double x, double y, double z)
628 {
629     return (vec2_make(vec2(x, y)));
630 }
631  
632 Imrect *im_vec3(Imrect * im1, Imrect * im2, Imrect *im3)
633 {
634     return (im_fffp_combine(im1, im2, im3, pvec2_make, NULL));
635 }
636 
637 

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