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

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

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

  1 /**@(#)
  2 **/
  3 /**im_warp.c:
  4 
  5 general image warping
  6 **/
  7 
  8 #include <math.h>
  9 #include <tina/sys.h>
 10 #include <tina/sysfuncs.h>
 11 #include <tina/math.h>
 12 #include <tina/mathfuncs.h>
 13 #include <tina/vision.h>
 14 
 15 /**
 16 phase this version out
 17 **/
 18 
 19 void    imf_warp(Imrect * im1, Imrect * im2, Vec2(*f) ( /* ??? */ ), void *data)
 20 {
 21     double  x, y;
 22     Imregion *roi;
 23 
 24     roi = im2->region;
 25 
 26     for (x = roi->lx + 0.5; x < roi->ux; x++)
 27         for (y = roi->ly + 0.5; y < roi->uy; y++)
 28         {
 29             double  pixval;
 30             Vec2    v1 = {Vec2_id};
 31             Vec2    v2 = {Vec2_id};
 32 
 33             v2 = vec2(x, y);
 34             v1 = (*f) (v2, data);
 35             pixval = im_sub_pixf(im1, vec2_y(v1), vec2_x(v1));
 36             im_put_pixf(pixval, im2, (int) y, (int) x);
 37         }
 38 }
 39 
 40 Imrect *im_warp(Imrect * im1, Vec2(*f) ( /* ??? */ ), void *data)
 41 {
 42     Imrect *im2;
 43     double  x, y;
 44     Imregion *roi;
 45 
 46     if (im1 == NULL)
 47         return (NULL);
 48 
 49     roi = im1->region;
 50     im2 = im_copy(im1);
 51 
 52     for (x = roi->lx + 0.5; x < roi->ux; x++)
 53         for (y = roi->ly + 0.5; y < roi->uy; y++)
 54         {
 55             double  pixval;
 56             Vec2    v1 = {Vec2_id};
 57             Vec2    v2 = {Vec2_id};
 58 
 59             v2 = vec2(x, y);
 60             v1 = (*f) (v2, data);
 61             pixval = im_sub_pixf(im1, vec2_y(v1), vec2_x(v1));
 62             im_put_pixf(pixval, im2, (int) y, (int) x);
 63         }
 64     return (im2);
 65 }
 66 
 67 Imregion *roi_rectify(Imregion * roi, Mat3 rect)
 68 {
 69     Vec2    v = {Vec2_id};
 70     Vec2    vmin = {Vec2_id};
 71     Vec2    vmax = {Vec2_id};
 72     int     lx, ly, ux, uy;
 73 
 74     if (roi == NULL)
 75         return (NULL);
 76 
 77     v = vec2_rectify(rect, vec2((double) roi->lx, (double) roi->ly));
 78     vmin = vmax = v;
 79     v = vec2_rectify(rect, vec2((double) roi->ux + 1, (double) roi->ly));
 80     vec2_extend_hull(&vmin, &vmax, v);
 81     v = vec2_rectify(rect, vec2((double) roi->lx, (double) roi->uy + 1));
 82     vec2_extend_hull(&vmin, &vmax, v);
 83     v = vec2_rectify(rect, vec2((double) roi->ux + 1, (double) roi->uy + 1));
 84     vec2_extend_hull(&vmin, &vmax, v);
 85 
 86     lx = (int)floor(vec2_x(vmin));
 87     ux = (int)(ceil(vec2_x(vmax)) - 0.5);
 88     ly = (int)floor(vec2_y(vmin));
 89     uy = (int)(ceil(vec2_y(vmax)) - 0.5);
 90 
 91     return (roi_alloc(lx, ly, ux, uy));
 92 }
 93 
 94 Imrect *im_rectify(Imrect * im1, Mat3 rect)
 95 {
 96     Mat3    irect = {Mat3_id};
 97     Imrect *im2;
 98     Imregion *roi;
 99     int     x, y, lx, ly, ux, uy;
100 
101     if (im1 == NULL)
102         return (NULL);
103 
104     roi = roi_rectify(im1->region, rect);
105 
106     im2 = im_alloc(im1->height, im1->width, roi, im1->vtype);
107     lx = roi->lx;
108     ux = roi->ux;
109     ly = roi->ly;
110     uy = roi->uy;
111     rfree((void *) roi);
112 
113     irect = mat3_inverse(rect);
114 
115     for (x = lx; x < ux; x++)
116         for (y = ly; y < uy; y++)
117         {
118             Vec2    v = {Vec2_id};
119 
120             v = vec2_rectify(irect, vec2(x + 0.5, y + 0.5));
121             if (im2->vtype != complex_v)
122             {
123                 double  g;
124 
125                 g = im_sub_pixf(im1, vec2_y(v), vec2_x(v));
126                 im_put_pixf(g, im2, y, x);
127             } else
128             {
129                 Complex g = {Complex_id};
130 
131                 g = im_sub_pixz(im1, vec2_y(v), vec2_x(v));
132                 im_put_pixz(g, im2, y, x);
133             }
134         }
135 
136     return (im2);
137 }
138 

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