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

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

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

  1 /**@(#)
  2 **/
  3 /**im_conv_1d.c:
  4 
  5  1d and separable 2d convolution functions
  6 
  7  use `Faltung' convolution convention:
  8  (func*prof)[i] = Sum func[i-j]*prof[j]
  9 
 10  func is set to 0 when undefined (see smooth.c for another
 11  convention at limits)
 12 
 13  accepts only floating point convolution profiles
 14 **/
 15 
 16 #include <math.h>
 17 #include <tina/sys.h>
 18 #include <tina/sysfuncs.h>
 19 #include <tina/math.h>
 20 #include <tina/vision.h>
 21 
 22 /**
 23 Convolves array line1 into line2.
 24 Upper and lower array limits are for line2.
 25 Line1 is assumed to be long enough for prof to go off end of line2.
 26 **/
 27 
 28 static void conv_line(float *line1, Prof1 * prof, int lower, int upper, float *line2)
 29 {
 30     int     i, j;
 31     int     n1, n2;
 32     double  sum;
 33     float  *el = prof->el.float_v;
 34 
 35     n1 = prof->n1;
 36     n2 = prof->n2;
 37     for (i = lower; i < upper; i++)
 38     {
 39         sum = 0.0;
 40         for (j = n1; j < n2; j++)
 41             sum += line1[i - j] * el[j];
 42         line2[i] = (float) sum;
 43     }
 44 }
 45 
 46 Imrect *im_conv_h(Imrect * im1, Prof1 * prof)
 47 {
 48     Imrect *im2;
 49     Imregion *roi;
 50     float  *row1, *row2;
 51     int     lx, ux, ly, uy;
 52     int     lxn, uxn;
 53     int     n1, n2;
 54     int     i;
 55 
 56     if (im1 == NULL)
 57         return (NULL);
 58     if (prof == NULL)
 59         return (NULL);
 60 
 61     if ((roi = im1->region) == NULL)
 62         return (NULL);
 63 
 64     lx = roi->lx;
 65     ux = roi->ux;
 66     ly = roi->ly;
 67     uy = roi->uy;
 68 
 69     n1 = prof->n1;
 70     n2 = prof->n2;
 71     lxn = MAX(lx, lx - n2 + 1);
 72     uxn = MIN(ux, ux - n1);
 73 
 74     im2 = im_alloc(im1->height, im1->width, roi, float_v);
 75 
 76     row1 = fvector_alloc(lx - n2 + 1, ux - n1);
 77     row2 = fvector_alloc(lx, ux);
 78 
 79     for (i = ly; i < uy; ++i)
 80     {
 81         im_get_rowf(row1, im1, i, lxn, uxn);
 82         conv_line(row1, prof, lx, ux, row2);
 83         im_put_rowf(row2, im2, i, lx, ux);
 84     }
 85 
 86     fvector_free((void *) row1, lx - n2 + 1);
 87     fvector_free((void *) row2, lx);
 88     return (im2);
 89 }
 90 
 91 Imrect *im_conv_v(Imrect * im1, Prof1 * prof)
 92 {
 93     Imrect *im2;
 94     Imregion *roi;
 95     float  *col1, *col2;
 96     int     lx, ux, ly, uy;
 97     int     lyn, uyn;
 98     int     n1, n2;
 99     int     i;
100 
101     if (im1 == NULL)
102         return (NULL);
103     if (prof == NULL)
104         return (NULL);
105 
106     if ((roi = im1->region) == NULL)
107         return (NULL);
108 
109     lx = roi->lx;
110     ux = roi->ux;
111     ly = roi->ly;
112     uy = roi->uy;
113 
114     n1 = prof->n1;
115     n2 = prof->n2;
116     lyn = MAX(ly, ly - n2 + 1);
117     uyn = MIN(uy, uy - n1);
118 
119     im2 = im_alloc(im1->height, im1->width, roi, float_v);
120 
121     col1 = fvector_alloc(ly - n2 + 1, uy - n1);
122     col2 = fvector_alloc(ly, uy);
123     for (i = lx; i < ux; ++i)
124     {
125         im_get_colf(col1, im1, i, lyn, uyn);
126         conv_line(col1, prof, ly, uy, col2);
127         im_put_colf(col2, im2, i, ly, uy);
128     }
129 
130     fvector_free((void *) col1, ly - n2 + 1);
131     fvector_free((void *) col2, ly);
132     return (im2);
133 }
134 
135 Imrect *im_conv_separable(Imrect * im1, Prof1 * prof_h, Prof1 * prof_v)
136 {
137     Imrect *im2;
138     Imrect *im3;
139 
140     if (im1 == NULL)
141         return (NULL);
142     if (prof_h == NULL)
143         return (NULL);
144     if (prof_v == NULL)
145         return (NULL);
146 
147     im2 = im_conv_h(im1, prof_h);
148     im3 = im_conv_v(im2, prof_v);
149 
150     im_free(im2);
151     return (im3);
152 }
153 

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