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

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

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

  1 #include <math.h>
  2 #include <tina/sys.h>
  3 #include <tina/sysfuncs.h>
  4 #include <tina/math.h>
  5 #include <tina/mathfuncs.h>
  6 
  7 Imrect *im_fft(Imrect *im1,Imregion *region)
  8 {
  9     Imrect *im2;
 10     Imregion roi;
 11     Complex *line;
 12     int nx, ny;
 13     int lx, ux, ly, uy;
 14     int i;
 15 
 16     if (im1 == NULL)
 17         return (NULL);
 18 
 19     if (region==NULL) region = im1->region;
 20     if (region == NULL) return (NULL);
 21 
 22     lx = roi.lx = region->lx;
 23     ux = roi.ux = region->ux;
 24     ly = roi.ly = region->ly;
 25     uy = roi.uy = region->uy;
 26 
 27     for(nx = 1; nx <= ux-lx; nx *= 2);
 28     for(ny = 1; ny <= uy-ly; ny *= 2);
 29     nx/=2;
 30     ny/=2;
 31 
 32     ux = roi.ux = lx + nx;
 33     uy = roi.uy = ly + ny;
 34 
 35     im2 = im_alloc(ny, nx, &roi, complex_v);
 36     line = zvector_alloc(lx, ux);
 37 
 38     for (i = ly; i < uy; ++i)
 39     {
 40         im_get_rowz(line, im1, i, lx, ux);
 41         line += lx;
 42         fft_cmplx_inplace(line, nx);
 43         line -= lx;
 44         im_put_rowz(line, im2, i, lx, ux);
 45     }
 46 
 47     zvector_free(line, lx);
 48     line = zvector_alloc(ly, uy);
 49     for (i = lx; i < ux; ++i)
 50     {
 51         im_get_colz(line, im2, i, ly, uy);
 52         line += ly;
 53         fft_cmplx_inplace(line, ny);
 54         line -= ly;
 55         im_put_colz(line, im2, i, ly, uy);
 56     }
 57 
 58     zvector_free(line, ly);
 59     return (im2);
 60 }
 61 
 62 Imrect *im_fft_inverse(Imrect *im1,Imregion *region)
 63 {
 64     Imrect *im2;
 65     Imregion roi;
 66     Complex *line;
 67     int nx, ny;
 68     int lx, ux, ly, uy;
 69     int i;
 70 
 71     if (im1 == NULL)
 72         return (NULL);
 73 
 74     if (region==NULL) region = im1->region;
 75     if (region == NULL) return (NULL);
 76 
 77     lx = roi.lx = region->lx;
 78     ux = roi.ux = region->ux;
 79     ly = roi.ly = region->ly;
 80     uy = roi.uy = region->uy;
 81 
 82     for(nx = 1; nx <= ux-lx; nx *= 2);
 83     for(ny = 1; ny <= uy-ly; ny *= 2);
 84     nx/=2;
 85     ny/=2;
 86 
 87     ux = roi.ux = lx + nx;
 88     uy = roi.uy = ly + ny;
 89 
 90     im2 = im_alloc(ny, nx, &roi, complex_v);
 91     line = zvector_alloc(lx, ux);
 92 
 93     for (i = ly; i < uy; ++i)
 94     {
 95         im_get_rowz(line, im1, i, lx, ux);
 96         line += lx;
 97         fft_inverse_cmplx_inplace(line, nx);
 98         line -= lx;
 99         im_put_rowz(line, im2, i, lx, ux);
100     }
101 
102     zvector_free(line, lx);
103     line = zvector_alloc(ly, uy);
104     for (i = lx; i < ux; ++i)
105     {
106         im_get_colz(line, im2, i, ly, uy);
107         line += ly;
108         fft_inverse_cmplx_inplace(line, ny);
109         line -= ly;
110         im_put_colz(line, im2, i, ly, uy);
111     }
112 
113     zvector_free(line, ly);
114     return (im2);
115 }
116 
117 static void line_power_spectrum(Complex *l1, float *l2, int from, int to)
118 {
119     int i;
120 
121     for(i = from; i < to; i++)
122         l2[i] = (float)cmplx_sqrmod(l1[i]);
123 }
124 
125 Imrect *im_power_spectrum(Imrect *im1)
126 {
127     Imrect *im2;
128     Complex *l1;
129     float *l2;
130     int i;
131     int ux, uy, hx, hy;
132 
133     if (im1 == NULL)
134         return (NULL);
135 
136     ux = im1->width;  hx = ux/2;
137     uy = im1->height; hy = uy/2;
138 
139     im2 = im_alloc(uy, ux, NULL, float_v);
140     l1 = zvector_alloc(0, ux);
141     l2 = fvector_alloc(0, ux);
142 
143     for (i = 0; i < hy; ++i)
144     {
145         im_get_rowz(l1, im1, i, 0, hx);
146         line_power_spectrum(l1, l2, 0, hx);
147         im_put_rowf(l2-hx, im2, i+hy, hx, ux);
148 
149         im_get_rowz(l1, im1, i, hx, ux);
150         line_power_spectrum(l1, l2, hx, ux);
151         im_put_rowf(l2+hx, im2, i+hy, 0, hx);
152     }
153 
154     for (i = hy; i < uy; ++i)
155     {
156         im_get_rowz(l1, im1, i, 0, hx);
157         line_power_spectrum(l1, l2, 0, hx);
158         im_put_rowf(l2-hx, im2, i-hy, hx, ux);
159 
160         im_get_rowz(l1, im1, i, hx, ux);
161         line_power_spectrum(l1, l2, hx, ux);
162         im_put_rowf(l2+hx, im2, i-hy, 0, hx);
163     }
164 
165     zvector_free(l1, 0);
166     fvector_free(l2, 0);
167 
168     return(im2);
169 }
170 

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