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

Linux Cross Reference
Tina4/src/sys/image/imfloatfns.c

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

  1 /*
  2 *
  3 * imfloatfns.c
  4 * general functions for images of type float
  5 *
  6 */
  7 
  8 #include <stdio.h>
  9 #include <tina/sys.h>
 10 #include <tina/sys_types.h>
 11 #include <tina/sysfuncs.h>
 12 #include <tina/image.h>
 13 #include <tina/math.h>
 14 
 15 double  im_get_quadmaxf(Imrect * image, float x, float y, float *px, float *py)
 16         /* image of type float */
 17 /* fits simple quadratic function to image and returns interpolated value
 18    and max/min of local area                                    NAT 10/10/90 */
 19 {
 20     Imregion       *region = image->region;
 21     double           pixval[3][3];
 22     double           a, b, c, d, e, f;
 23     double          inter;
 24     double           temp;
 25     int           i, j, n, m;
 26     double           xs, ys;
 27 
 28     i = tina_int(x - 1);
 29     j = tina_int(y - 1);
 30 
 31     if (j < region->ly + 1 || j > region->uy - 1
 32         || i < region->lx + 1 || i > region->ux - 1)
 33         return (0);
 34 
 35     for (n = 0; n < 3; n++)
 36     {
 37         for (m = 0; m < 3; m++)
 38         {
 39             pixval[n][m] = im_get_pixf(image, j + n, i + m);
 40         }
 41     }
 42 
 43     a = pixval[1][1];
 44     b = (pixval[0][2] - pixval[0][0]
 45         + pixval[1][2] - pixval[1][0]
 46         + pixval[2][2] - pixval[2][0]) / 6.0;
 47     c = (pixval[2][0] - pixval[0][0]
 48         + pixval[2][1] - pixval[0][1]
 49         + pixval[2][2] - pixval[0][2]) / 6.0;
 50     d = (pixval[0][0] - 2.0 * pixval[0][1] + pixval[0][2]
 51         + 3.0 * pixval[1][0] - 6.0 * pixval[1][1] + 3.0 * pixval[1][2]
 52         + pixval[2][0] - 2.0 * pixval[2][1] + pixval[2][2]) / 10.0;
 53     e = (pixval[0][0] - pixval[2][0]
 54         + pixval[2][2] - pixval[0][2]) / 4.0;
 55     f = (pixval[0][0] + 3.0 * pixval[0][1] + pixval[0][2]
 56         - 2.0 * pixval[1][0] - 6.0 * pixval[1][1] - 2.0 * pixval[1][2]
 57         + pixval[2][0] + 3.0 * pixval[2][1] + pixval[2][2]) / 10.0;
 58 
 59     temp = 4.0 * d * f - e * e;
 60     *px = 1.5 + (double) i + (e * c - 2 * f * b) / temp;
 61     *py = 1.5 + (double) j + (e * b - 2 * d * c) / temp;
 62 
 63     xs = (e * c - 2 * f * b) / temp;
 64     ys = (e * b - 2 * d * c) / temp;
 65 
 66     inter = a + b * xs + c * ys + d * xs * xs + e * xs * ys + f * ys * ys;
 67 
 68     return (inter);
 69 }
 70 
 71 double  im_get_quadinterpf(Imrect * image, float x, float y, float *pdx, float *pdy)
 72                 /* image of type float */
 73 /* fits simple quadratic function to image and returns interpolated value
 74                                                                 NAT 10/10/90 */
 75 {
 76     Imregion       *region = image->region;
 77     double           pixval[3][3];
 78     double           a, b, c, d, e, f;
 79     double          inter;
 80     int           i, j, n, m;
 81     double           xs, ys;
 82 
 83     i = tina_int(x-1);
 84     j = tina_int(y-1);
 85 
 86 /* assume that pixel contents are exaluated at the centre */
 87     xs = x - (float) i - 1.5;
 88     ys = y - (float) j - 1.5;
 89 
 90     if (j < region->ly + 1 || j > region->uy - 1
 91         || i < region->lx + 1 || i > region->ux - 1)
 92         return (0);
 93 
 94     for (n = 0; n < 3; n++)
 95     {
 96         for (m = 0; m < 3; m++)
 97         {
 98             pixval[n][m] = im_get_pixf(image, j + n, i + m);
 99         }
100     }
101 
102     a = pixval[1][1];
103     b = (pixval[0][2] - pixval[0][0]
104         + pixval[1][2] - pixval[1][0]
105         + pixval[2][2] - pixval[2][0]) / 6.0;
106     c = (pixval[2][0] - pixval[0][0]
107         + pixval[2][1] - pixval[0][1]
108         + pixval[2][2] - pixval[0][2]) / 6.0;
109     d = (pixval[0][0] - 2.0 * pixval[0][1] + pixval[0][2]
110         + 3.0 * pixval[1][0] - 6.0 * pixval[1][1] + 3.0 * pixval[1][2]
111         + pixval[2][0] - 2.0 * pixval[2][1] + pixval[2][2]) / 10.0;
112     e = (pixval[0][0] - pixval[2][0]
113         + pixval[2][2] - pixval[0][2]) / 4.0;
114     f = (pixval[0][0] + 3.0 * pixval[0][1] + pixval[0][2]
115         - 2.0 * pixval[1][0] - 6.0 * pixval[1][1] - 2.0 * pixval[1][2]
116         + pixval[2][0] + 3.0 * pixval[2][1] + pixval[2][2]) / 10.0;
117 
118     *pdx = b + 2.0 * d * xs + e * ys;
119     *pdy = c + e * xs + 2.0 * f * ys;
120 
121     inter = a + b * xs + c * ys + d * xs * xs + e * xs * ys + f * ys * ys;
122 
123     return (inter);
124 }
125 
126 /* sinc image interpolation using a 5*5 kernel */
127 
128 #define KERN_RANGE 2 /* 1 = 3*3 kernel, 2 = 5*5 kernel, 3 = 7*7 kernel */
129 
130 static float han_sinc5(float delta)
131 {
132   double sinc, phase, hanning;
133   
134   phase = PI * delta;
135   if(fabs(phase) > 0.000001) sinc = sin(phase) / phase;
136   else sinc = 1.0;
137   hanning = (0.5 + 0.5 * cos(phase / (float)(1.0 + KERN_RANGE)));
138   return(hanning * sinc);
139 }
140 
141 double im_get_sinc5interpf(Imrect *image, float x, float y,
142                            float *pdx, float *pdy)
143 {
144   static float *hx = NULL, *hy, *hxstart;
145   float hxtot = 0.0, hytot = 0.0;
146   float ypos, pfac, newpix = 0.0;
147   float *thispix, *hxptr;
148   float xoffset, yoffset;
149   int pos, rowoffset, xint, yint;
150 
151   xint = tina_int(x);
152   yint = tina_int(y);
153 
154   if (yint < image->region->ly + KERN_RANGE ||
155       yint > image->region->uy - KERN_RANGE - 1 ||
156       xint < image->region->lx + KERN_RANGE ||
157       xint > image->region->ux - KERN_RANGE - 1)
158     return (0.0);
159   
160   xoffset = x - (float)xint - 0.5;
161   yoffset = y - (float)yint - 0.5;
162   
163   if (hx == NULL)
164     {
165       hx = fvector_alloc(-KERN_RANGE, KERN_RANGE + 1);
166       hy = fvector_alloc(-KERN_RANGE, KERN_RANGE + 1);
167       hxstart = &hx[-KERN_RANGE];
168     }
169   
170   for (pos=-KERN_RANGE; pos<=KERN_RANGE; pos++)
171     {
172       hy[pos] = han_sinc5(yoffset - (float)pos);
173       hytot += hy[pos];
174       hx[pos] = han_sinc5(xoffset - (float)pos);
175       hxtot += hx[pos];
176     }
177 
178   rowoffset = tina_int(x - (float)KERN_RANGE);
179 
180   for (pos=-KERN_RANGE; pos<=KERN_RANGE; pos++)
181     {
182       ypos = y + (float)pos;
183       thispix = &((float **)image->data)[tina_int(ypos)][rowoffset];
184       hxptr = hxstart;  
185       pfac = 0.0;
186       switch(KERN_RANGE)
187         {
188         /* note: no break statements at case ends */
189         case 6:
190           pfac += *(thispix++) * *(hxptr++);
191           pfac += *(thispix++) * *(hxptr++);
192         case 5:
193           pfac += *(thispix++) * *(hxptr++);
194           pfac += *(thispix++) * *(hxptr++);
195         case 4:
196           pfac += *(thispix++) * *(hxptr++);
197           pfac += *(thispix++) * *(hxptr++);
198         case 3:
199           pfac += *(thispix++) * *(hxptr++);
200           pfac += *(thispix++) * *(hxptr++);
201         case 2:
202           pfac += *(thispix++) * *(hxptr++);
203           pfac += *(thispix++) * *(hxptr++);
204         case 1:
205           pfac += *(thispix++) * *(hxptr++);
206           pfac += *(thispix++) * *(hxptr++);
207           pfac += *(thispix++) * *(hxptr++);
208         }
209       newpix += hy[pos] * pfac;
210     }
211   
212   return(newpix / (hxtot * hytot)); 
213 }
214 
215 #undef KERN_RANGE
216 
217 /* sinc image interpolation using a 3*3 kernel */
218 
219 #define KERN_RANGE 1 /* 1 = 3*3 kernel, 2 = 5*5 kernel, 3 = 7*7 kernel */
220 
221 static float han_sinc3(float delta)
222 {
223   double sinc, phase, hanning;
224   
225   phase = PI * delta;
226   if(fabs(phase) > 0.000001) sinc = sin(phase) / phase;
227   else sinc = 1.0;
228   hanning = (0.5 + 0.5 * cos(phase / (float)(1.0 + KERN_RANGE)));
229   return(hanning * sinc);
230 }
231 
232 double im_get_sinc3interpf(Imrect *image, float x, float y,
233                            float *pdx, float *pdy)
234 {
235   static float *hx = NULL, *hy, *hxstart;
236   float hxtot = 0.0, hytot = 0.0;
237   float ypos, pfac, newpix = 0.0;
238   float *thispix, *hxptr;
239   float xoffset, yoffset;
240   int pos, rowoffset, xint, yint;
241 
242   xint = tina_int(x);
243   yint = tina_int(y);
244 
245   if (yint < image->region->ly + KERN_RANGE ||
246       yint > image->region->uy - KERN_RANGE - 1 ||
247       xint < image->region->lx + KERN_RANGE ||
248       xint > image->region->ux - KERN_RANGE - 1)
249     return (0.0);
250   
251   xoffset = x - (float)xint - 0.5;
252   yoffset = y - (float)yint - 0.5;
253   
254   if (hx == NULL)
255     {
256       hx = fvector_alloc(-KERN_RANGE, KERN_RANGE + 1);
257       hy = fvector_alloc(-KERN_RANGE, KERN_RANGE + 1);
258       hxstart = &hx[-KERN_RANGE];
259     }
260   
261   for (pos=-KERN_RANGE; pos<=KERN_RANGE; pos++)
262     {
263       hy[pos] = han_sinc5(yoffset - (float)pos);
264       hytot += hy[pos];
265       hx[pos] = han_sinc5(xoffset - (float)pos);
266       hxtot += hx[pos];
267     }
268 
269   rowoffset = tina_int(x - (float)KERN_RANGE);
270 
271   for (pos=-KERN_RANGE; pos<=KERN_RANGE; pos++)
272     {
273       ypos = y + (float)pos;
274       thispix = &((float **)image->data)[tina_int(ypos)][rowoffset];
275       hxptr = hxstart;  
276       pfac = 0.0;
277       switch(KERN_RANGE)
278         {
279         /* note: no break statements at case ends */
280         case 6:
281           pfac += *(thispix++) * *(hxptr++);
282           pfac += *(thispix++) * *(hxptr++);
283         case 5:
284           pfac += *(thispix++) * *(hxptr++);
285           pfac += *(thispix++) * *(hxptr++);
286         case 4:
287           pfac += *(thispix++) * *(hxptr++);
288           pfac += *(thispix++) * *(hxptr++);
289         case 3:
290           pfac += *(thispix++) * *(hxptr++);
291           pfac += *(thispix++) * *(hxptr++);
292         case 2:
293           pfac += *(thispix++) * *(hxptr++);
294           pfac += *(thispix++) * *(hxptr++);
295         case 1:
296           pfac += *(thispix++) * *(hxptr++);
297           pfac += *(thispix++) * *(hxptr++);
298           pfac += *(thispix++) * *(hxptr++);
299         }
300       newpix += hy[pos] * pfac;
301     }
302   
303   return(newpix / (hxtot * hytot)); 
304 }
305 
306 #undef KERN_RANGE
307 
308 

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