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

Linux Cross Reference
Tina6/tina-libs/tina/image/imgGen_get.c

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

  1 /**********
  2  *
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  *
  6  * Redistribution and use in source and binary forms, with or without modification,
  7  * are permitted provided that the following conditions are met:
  8  *
  9  *   . Redistributions of source code must retain the above copyright notice,
 10  *     this list of conditions and the following disclaimer.
 11  *
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation
 14  *     and/or other materials provided with the distribution.
 15  *
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this
 18  *     software without specific prior written permission.
 19  *
 20  *
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  *
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-libs/tina/image/imgGen_get.c,v $
 37  * Date    :  $Date: 2004/08/05 14:32:44 $
 38  * Version :  $Revision: 1.7 $
 39  * CVS Id  :  $Id: imgGen_get.c,v 1.7 2004/08/05 14:32:44 neil Exp $
 40  */
 41 /** 
 42  *  @file
 43  *  @brief Pixel level read access to Imrect data.
 44  *
 45  * This includes sub-pixel access via bi-linear interpolation and access access to lines of data by row, column and diagonals.
 46  *
 47  */
 48 
 49 
 50 #include "imgGen_get.h"
 51 
 52 #if HAVE_CONFIG_H
 53 #include <config.h>
 54 #endif
 55 
 56 #include <stdio.h>
 57 #include <tina/sys/sysPro.h>
 58 #include <tina/sys/sysDef.h>
 59 #include <tina/math/mathPro.h>
 60 #include <tina/math/mathDef.h>
 61 #include <tina/image/img_GenDef.h>
 62 
 63 
 64 /**
 65  * @brief Reads a value from the specified coordinates of an image, casting it to an integer.
 66  * @param image The image to read data from.
 67  * @param i The x coordinate of the desired pixel.
 68  * @param j The y coordinate of the desired pixel.
 69  * @return pixval The value of the pixel at the specified coordinates, cast to an integer.
 70  *
 71  * Returns zero for an image of pointers, or if the coordinates lie outside the image. If not, the pixel 
 72  * value is cast to an integer and returned.
 73  */
 74 int             im_get_pix(Imrect * image, int i, int j)
 75 {
 76         Imregion       *region;
 77         double          pixval;
 78 
 79         if (image == NULL || image->vtype == ptr_v)
 80                 return (0);
 81 
 82         region = image->region;
 83         if (i < region->ly || i >= region->uy || j < region->lx
 84             || j >= region->ux)
 85                 return (0);
 86 
 87         IM_PIX_GET(image, i, j, pixval);
 88 
 89         return ((int) pixval);
 90 }
 91 
 92 
 93 /**
 94  * @brief Returns the pointer to the specified coordinates of an image of pointers.
 95  * @param image The image to read data from.
 96  * @param i The x coordinate of the desired pixel.
 97  * @param j The y coordinate of the desired pixel.
 98  * @return IM_PTR Pointer to the desired pixel
 99  *
100  * Only useful for images of pointers.
101  */
102 void           *im_get_ptr(Imrect * image, int i, int j)
103 {
104         Imregion       *region;
105 
106         if (image == NULL || image->vtype != ptr_v)
107                 return (NULL);
108 
109         region = image->region;
110         if (i < region->ly || i >= region->uy || j < region->lx
111             || j >= region->ux)
112                 return (NULL);
113 
114         return (IM_PTR(image, i, j));
115 }
116 
117 
118 /**
119  * @brief Reads a value, as a double, from the specified coordinates of an image.
120  * @param image The image to read data from.
121  * @param i The x coordinate of the desired pixel.
122  * @param j The y coordinate of the desired pixel.
123  * @return pixval The value of the pixel at the specified coordinates, cast to a double.
124  *
125  * Returns zero for an image of pointers, or if the coordinates lie outside the image. If not, the pixel 
126  * value is cast to an double and returned.
127  */
128 double          im_get_pixf(Imrect * image, int i, int j)
129 {
130         Imregion       *region;
131         double          pixval;
132 
133         if (image == NULL || image->vtype == ptr_v)
134                 return (0);
135 
136         region = image->region;
137         if (i < region->ly || i >= region->uy || j < region->lx
138             || j >= region->ux)
139                 return (0);
140 
141         IM_PIX_GET(image, i, j, pixval);
142 
143         return (pixval);
144 }
145 
146 
147 /**
148  * @brief Reads a value from the specified coordinates of a complex image.
149  * @param image The image to read data from.
150  * @param i The x coordinate of the desired pixel.
151  * @param j The y coordinate of the desired pixel.
152  * @return pixval The value of the pixel at the specified coordinates, as a complex number.
153  *
154  * Returns complex zero for an image of pointers, or if the coordinates lie outside the image. If not, the pixel 
155  * value as a complex number is returned.
156  */
157 Complex         im_get_pixz(Imrect * image, int i, int j)
158 {
159         Imregion       *region;
160         Complex         pixval = {Complex_id};
161 
162         if (image == NULL || image->vtype == ptr_v)
163                 return (cmplx_zero());
164 
165         region = image->region;
166         if (i < region->ly || i >= region->uy || j < region->lx
167             || j >= region->ux)
168                 return (cmplx_zero());
169 
170         if (image->vtype == complex_v)
171                 pixval = IM_COMPLEX(image, i, j);
172         else
173         {
174                 pixval.y = 0.0;
175                 IM_PIX_GET(image, i, j, pixval.x);
176         }
177         return (pixval);
178 }
179 
180 
181 /**
182  * @brief Uses bi-linear interpolation to read a value from an image at the desired coordinates, casting it to an integer.
183  * @param image The image to read data from.
184  * @param r The image coordinate, to sub-pixel accuracy, in the y direction.
185  * @param c The image coordinate, to sub-pixel accuracy, in the x direction.
186  * @return pixval The value at the desired image coordinates, cast to an integer.
187  *
188  * Equivalent function to im_get_pix, but supports sub-pixel accuracy through bi-linear interpolation. 
189  * The pixel value at the desired coordinates is cast to an integer.
190  */
191 int             im_sub_pix(Imrect * image, double r, double c)
192 {
193         Imregion       *region;
194         int             i, j;
195         double          x1, x2, y1, y2;
196         double          gl, pix11, pix12, pix21, pix22;
197         double          pixval;
198 
199         if (image == NULL || image->vtype == ptr_v)
200                 return (0);
201 
202         r -= 0.5;
203         c -= 0.5;
204 
205         region = image->region;
206         if (r < region->ly || r + 1 >= region->uy || c < region->lx
207             || c + 1 >= region->ux)
208                 return (0);
209 
210         i = (int) r;
211         y1 = r - i;
212         y2 = 1.0 - y1;
213         j = (int) c;
214         x1 = c - j;
215         x2 = 1.0 - x1;
216 
217         IM_PIX_GET(image, i, j, pix11);
218         IM_PIX_GET(image, i, j + 1, pix12);
219         IM_PIX_GET(image, i + 1, j, pix21);
220         IM_PIX_GET(image, i + 1, j + 1, pix22);
221 
222         gl = (pix11 * x2 + pix12 * x1) * y2 + (pix21 * x2 + pix22 * x1) * y1;
223 
224         pixval = (gl > 0) ? gl + 0.5 : gl - 0.5;
225         return ((int) pixval);
226 }
227 
228 
229 /**
230  * @brief Uses bi-linear interpolation to read a value from an image at the desired coordinates, casting it to a double.
231  * @param image The image to read data from.
232  * @param r The image coordinate, to sub-pixel accuracy, in the y direction.
233  * @param c The image coordinate, to sub-pixel accuracy, in the x direction.
234  * @return pixval The value at the desired image coordinates, cast to an double.
235  *
236  * Equivalent function to im_get_pixf, but supports sub-pixel accuracy through bi-linear interpolation. 
237  * The pixel value at the desired coordinates is cast to an double.
238  */
239 double          im_sub_pixf(Imrect * image, double r, double c)
240 {
241         Imregion       *region;
242         int             i, j;
243         double          x1, x2, y1, y2;
244         double          pix11, pix12, pix21, pix22;
245         double          pixval;
246 
247         if (image == NULL || image->vtype == ptr_v)
248                 return (0);
249 
250         r -= 0.5;
251         c -= 0.5;
252 
253         region = image->region;
254         if (r < region->ly || r + 1 >= region->uy || c < region->lx
255             || c + 1 >= region->ux)
256                 return (0);
257 
258         i = (int) r;
259         y1 = r - i;
260         y2 = 1.0 - y1;
261         j = (int) c;
262         x1 = c - j;
263         x2 = 1.0 - x1;
264 
265         IM_PIX_GET(image, i, j, pix11);
266         IM_PIX_GET(image, i, j + 1, pix12);
267         IM_PIX_GET(image, i + 1, j, pix21);
268         IM_PIX_GET(image, i + 1, j + 1, pix22);
269 
270         pixval = (pix11 * x2 + pix12 * x1) * y2 + (pix21 * x2 + pix22 * x1) * y1;
271 
272         return (pixval);
273 }
274 
275 
276 /**
277  * @brief Uses 2d quadratic interpolation to read a value from an image at the desired coordinates, casting it to a double.
278  * @param image The image to read data from.
279  * @param r The image coordinate, to sub-pixel accuracy, in the y direction.
280  * @param c The image coordinate, to sub-pixel accuracy, in the x direction.
281  * @return pixval The value at the desired image coordinates, cast to an double.
282  *
283  * Equivalent function to im_get_pixf and im_sub_pixf, but supports sub-pixel accuracy through 2d quadratic interpolation. 
284  * The pixel value at the desired coordinates is cast to an double. NAT 10/10/90
285  */
286 double          im_sub_pixqf(Imrect * image, double y, double x)
287 {
288         Imregion       *region = image->region;
289         double          pixval[3][3];
290         float           a, b, c, d, e, f;
291         double          inter;
292         int             i, j, n, m;
293         float           xs, ys;
294 
295         i = tina_int(x - 1);
296         j = tina_int(y - 1);
297 
298         xs = (float) (x - i - 1.5);
299         ys = (float) (y - j - 1.5);
300 
301         if (j < region->ly || j > region->uy - 3
302             || i < region->lx || i > region->ux - 3)
303                 return (0);
304         for (n = 0; n < 3; n++)
305         {
306                 for (m = 0; m < 3; m++)
307                 {
308                         IM_PIX_GET(image, j + n, i + m, pixval[n][m]);
309                 }
310         }
311 
312         a = (float) pixval[1][1];
313         b = (float) ((pixval[0][2] - pixval[0][0]
314                       + pixval[1][2] - pixval[1][0]
315                       + pixval[2][2] - pixval[2][0]) / 6.0);
316         c = (float) ((pixval[2][0] - pixval[0][0]
317                       + pixval[2][1] - pixval[0][1]
318                       + pixval[2][2] - pixval[0][2]) / 6.0);
319         d = (float) ((pixval[0][0] - 2.0 * pixval[0][1] + pixval[0][2]
320                       + 3.0 * pixval[1][0] - 6.0 * pixval[1][1] +
321                     3.0 * pixval[1][2] + pixval[2][0] - 2.0 * pixval[2][1] +
322                       pixval[2][2]) / 10.0);
323         e =
324                 (float) ((pixval[0][0] - pixval[2][0] + pixval[2][2] - pixval[0][2])
325                          / 4.0);
326         f =
327                 (float) (
328                          (pixval[0][0] + 3.0 * pixval[0][1] + pixval[0][2] -
329                           2.0 * pixval[1][0] - 6.0 * pixval[1][1] -
330                     2.0 * pixval[1][2] + pixval[2][0] + 3.0 * pixval[2][1] +
331                           pixval[2][2]) / 10.0);
332 
333         xs *= (float) 2.0;
334         ys *= (float) 2.0;
335         inter =
336                 a + 0.5 * (b * xs + c * ys + d * xs * xs + e * xs * ys +
337                            f * ys * ys);
338 
339         return (inter);
340 }
341 
342 
343 /**
344  * @brief Uses bi-linear interpolation to read a value from a complex image at the desired coordinates.
345  * @param image The complex image to read data from.
346  * @param r The image coordinate, to sub-pixel accuracy, in the y direction.
347  * @param c The image coordinate, to sub-pixel accuracy, in the x direction.
348  * @return pixval The value at the desired image coordinates, as a complex number.
349  *
350  * Equivalent function to im_get_pixz, but supports sub-pixel accuracy through bi-linear interpolation. 
351  * The pixel value at the desired coordinates is returned as a complex number.
352  */
353 Complex         im_sub_pixz(Imrect * im, double y, double x)
354 {
355         int             i, j;
356         double          x1, x2, y1, y2;
357         Complex         z00 = {Complex_id};
358         Complex         z10 = {Complex_id};
359         Complex         z01 = {Complex_id};
360         Complex         z11 = {Complex_id};
361         double          re00, re01, re10, re11, re0;
362         double          im00, im01, im10, im11, im0;
363 
364         y -= 0.5;
365         i = (int) y;
366         y1 = y - i;
367         y2 = 1.0 - y1;
368         x -= 0.5;
369         j = (int) x;
370         x1 = x - j;
371         x2 = 1.0 - x1;
372 
373         z00 = im_get_pixz(im, i, j);
374         z01 = im_get_pixz(im, i, j + 1);
375         z10 = im_get_pixz(im, i + 1, j);
376         z11 = im_get_pixz(im, i + 1, j + 1);
377 
378         re00 = cmplx_re(z00);
379         re10 = cmplx_re(z10);
380         re01 = cmplx_re(z01);
381         re11 = cmplx_re(z11);
382         re0 = y2 * (x2 * re00 + x1 * re01) + y1 * (x2 * re10 + x1 * re11);
383 
384         im00 = cmplx_im(z00);
385         im10 = cmplx_im(z10);
386         im01 = cmplx_im(z01);
387         im11 = cmplx_im(z11);
388         im0 = y2 * (x2 * im00 + x1 * im01) + y1 * (x2 * im10 + x1 * im11);
389 
390         return (cmplx(re0, im0));
391 }
392 
393 
394 /**
395  * @brief Copies the values of a portion of a specified row of an image into a vector, casting them to integers.
396  * @param line An integer vector, which must already be allocated, to hold the image row data.
397  * @param image The image to read data from.
398  * @param i The coordinate of the row to read data from.
399  * @param from The column at which to start reading data.
400  * @param to The column at which to stop reading data.
401  * @return void
402  *
403  * Copies the values of a portion of a specified row of an image into an integer vector, which must be
404  * allocated before the function is called, casting the pixel values to integers. No check is made on line:
405  * this will crash if line is not allocated, too short etc. Any part of the vector outside the image will 
406  * be filled with zeros.
407  */
408 void            im_get_row(int *line, Imrect * image, int i, int from, int to)
409 {
410         int             j;
411         Imregion       *region;
412         double          pixval;
413 
414         for (j = from; j < to; ++j)
415                 line[j] = 0;
416 
417         if (image == NULL || image->vtype == ptr_v)
418                 return;
419 
420         region = image->region;
421         if (i < region->ly || i >= region->uy)
422                 return;
423 
424         if (from >= region->ux || to < region->lx)
425                 return;
426 
427         if (to > region->ux)
428                 to = region->ux;
429 
430         if (from < region->lx)
431                 from = region->lx;
432 
433         for (j = from; j < to; ++j)
434         {
435                 IM_PIX_GET(image, i, j, pixval);
436                 line[j] = (int) pixval;
437         }
438 }
439 
440 
441 /**
442  * @brief Copies the values of a portion of a specified row of image rdata into a vector, casting them to int.
443  * @param line An integer vector, which must already be allocated, to hold the image row rdata.
444  * @param image The image to read rdata from.
445  * @param i The coordinate of the row to read rdata from.
446  * @param from The column at which to start reading rdata.
447  * @param to The column at which to stop reading rdata.
448  * @return void
449  *
450  * Copies the values of a portion of a specified row of image rdata into an integer vector, which must be
451  * allocated before the function is called, casting the pixel values to integers. No check is made on line:
452  * this will crash if line is not allocated, too short etc. Any part of the vector outside the image will 
453  * be filled with zeros.
454  *
455  * Note: this function is used in the experimental colour image display code in drawPaint_imrect.c
456  * That is why there are no corresponding column etc. functions.
457  *
458  */
459 void            im_r_get_row(int *line, Imrect * image, int i, int from, int to)
460 {
461         int             j;
462         Imregion       *region;
463         double          pixval;
464 
465         for (j = from; j < to; ++j)
466                 line[j] = 0;
467 
468         if (image == NULL || image->vtype == ptr_v || image->vtype == complex_v || image->rdata==NULL)
469                 return;
470 
471         region = image->region;
472         if (i < region->ly || i >= region->uy)
473                 return;
474 
475         if (from >= region->ux || to < region->lx)
476                 return;
477 
478         if (to > region->ux)
479                 to = region->ux;
480 
481         if (from < region->lx)
482                 from = region->lx;
483 
484         for (j = from; j < to; ++j)
485         {
486                 IM_R_PIX_GET(image, i, j, pixval);
487                 line[j] = (int) pixval;
488         }
489 }
490 
491 
492 /**
493  * @brief Copies the values of a portion of a specified row of image gdata into a vector, casting them to int.
494  * @param line An integer vector, which must already be allocated, to hold the image row gdata.
495  * @param image The image to read gdata from.
496  * @param i The coordinate of the row to read gdata from.
497  * @param from The column at which to start reading gdata.
498  * @param to The column at which to stop reading gdata.
499  * @return void
500  *
501  * Copies the values of a portion of a specified row of image gdata into an integer vector, which must be
502  * allocated before the function is called, casting the pixel values to integers. No check is made on line:
503  * this will crash if line is not allocated, too short etc. Any part of the vector outside the image will 
504  * be filled with zeros.
505  *
506  * Note: this function is used in the experimental colour image display code in drawPaint_imrect.c
507  * That is why there are no corresponding column etc. functions.
508  *
509  */
510 void            im_g_get_row(int *line, Imrect * image, int i, int from, int to)
511 {
512         int             j;
513         Imregion       *region;
514         double          pixval;
515 
516         for (j = from; j < to; ++j)
517                 line[j] = 0;
518 
519         if (image == NULL || image->vtype == ptr_v || image->vtype == complex_v || image->gdata==NULL)
520                 return;
521 
522         region = image->region;
523         if (i < region->ly || i >= region->uy)
524                 return;
525 
526         if (from >= region->ux || to < region->lx)
527                 return;
528 
529         if (to > region->ux)
530                 to = region->ux;
531 
532         if (from < region->lx)
533                 from = region->lx;
534 
535         for (j = from; j < to; ++j)
536         {
537                 IM_G_PIX_GET(image, i, j, pixval);
538                 line[j] = (int) pixval;
539         }
540 }
541 
542 
543 /**
544  * @brief Copies the values of a portion of a specified row of image bdata into a vector, casting them to int.
545  * @param line An integer vector, which must already be allocated, to hold the image row bdata.
546  * @param image The image to read bdata from.
547  * @param i The coordinate of the row to read bdata from.
548  * @param from The column at which to start reading bdata.
549  * @param to The column at which to stop reading bdata.
550  * @return void
551  *
552  * Copies the values of a portion of a specified row of image bdata into an integer vector, which must be
553  * allocated before the function is called, casting the pixel values to integers. No check is made on line:
554  * this will crash if line is not allocated, too short etc. Any part of the vector outside the image will 
555  * be filled with zeros.
556  *
557  * Note: this function is used in the experimental colour image display code in drawPaint_imrect.c
558  * That is why there are no corresponding column etc. functions.
559  *
560  */
561 void            im_b_get_row(int *line, Imrect * image, int i, int from, int to)
562 {
563         int             j;
564         Imregion       *region;
565         double          pixval;
566 
567         for (j = from; j < to; ++j)
568                 line[j] = 0;
569 
570         if (image == NULL || image->vtype == ptr_v || image->vtype == complex_v || image->bdata==NULL)
571                 return;
572 
573         region = image->region;
574         if (i < region->ly || i >= region->uy)
575                 return;
576 
577         if (from >= region->ux || to < region->lx)
578                 return;
579 
580         if (to > region->ux)
581                 to = region->ux;
582 
583         if (from < region->lx)
584                 from = region->lx;
585 
586         for (j = from; j < to; ++j)
587         {
588                 IM_B_PIX_GET(image, i, j, pixval);
589                 line[j] = (int) pixval;
590         }
591 }
592 
593 
594 /**
595  * @brief Copies the values of a portion of a specified column of an image into a vector, casting them to integers.
596  * @param line An integer vector, which must already be allocated, to hold the image column data.
597  * @param image The image to read data from.
598  * @param i The coordinate of the column to read data from.
599  * @param from The row at which to start reading data.
600  * @param to The row at which to stop reading data.
601  * @return void
602  *
603  * Copies the values of a portion of a specified column of an image into an integer vector, which must be
604  * allocated before the function is called, casting the pixel values to integers. No check is made on line:
605  * this will crash if line is not allocated, too short etc. Any part of the vector outside the image will 
606  * be filled with zeros.
607  */
608 void            im_get_col(int *line, Imrect * image, int i, int from, int to)
609 {
610         int             j;
611         Imregion       *region;
612         double          pixval;
613 
614         for (j = from; j < to; ++j)
615                 line[j] = 0;
616 
617         if (image == NULL || image->vtype == ptr_v)
618                 return;
619 
620         region = image->region;
621         if (i < region->lx || i >= region->ux)
622                 return;
623 
624         if (from >= region->uy || to < region->ly)
625                 return;
626 
627         if (to > region->uy)
628                 to = region->uy;
629 
630         if (from < region->ly)
631                 from = region->ly;
632 
633         for (j = from; j < to; ++j)
634         {
635                 IM_PIX_GET(image, j, i, pixval);
636                 line[j] = (int) pixval;
637         }
638 }
639 
640 
641 /**
642  * @brief Copies the values of a portion of a specified row of an image into a vector, casting them to floats.
643  * @param line A float vector, which must already be allocated, to hold the image row data.
644  * @param image The image to read data from.
645  * @param i The coordinate of the row to read data from.
646  * @param from The column at which to start reading data.
647  * @param to The column at which to stop reading data.
648  * @return void
649  *
650  * Copies the values of a portion of a specified row of an image into an float vector, which must be
651  * allocated before the function is called, casting the pixel values to floats. No check is made on line:
652  * this will crash if line is not allocated, too short etc. Any part of the vector outside the image will 
653  * be filled with zeros.
654  */
655 void            im_get_rowf(float *line, Imrect * image, int i, int from, int to)
656 {
657         int             j;
658         Imregion       *region;
659         double          pixval;
660 
661         for (j = from; j < to; ++j)
662                 line[j] = (float) 0.0;
663 
664         if (image == NULL || image->vtype == ptr_v)
665                 return;
666 
667         region = image->region;
668         if (i < region->ly || i >= region->uy)
669                 return;
670 
671         if (from >= region->ux || to < region->lx)
672                 return;
673 
674         if (to > region->ux)
675                 to = region->ux;
676 
677         if (from < region->lx)
678                 from = region->lx;
679 
680         for (j = from; j < to; ++j)
681         {
682                 IM_PIX_GET(image, i, j, pixval);
683                 line[j] = (float) pixval;
684         }
685 }
686 
687 
688 /**
689  * @brief Copies the values of a portion of a specified column of an image into a vector, casting them to floats.
690  * @param line A float vector, which must already be allocated, to hold the image column data.
691  * @param image The image to read data from.
692  * @param i The coordinate of the column to read data from.
693  * @param from The row at which to start reading data.
694  * @param to The row at which to stop reading data.
695  * @return void
696  *
697  * Copies the values of a portion of a specified column of an image into an float vector, which must be
698  * allocated before the function is called, casting the pixel values to floats. No check is made on line:
699  * this will crash if line is not allocated, too short etc. Any part of the vector outside the image will 
700  * be filled with zeros.
701  */
702 void            im_get_colf(float *line, Imrect * image, int i, int from, int to)
703 {
704         int             j;
705         Imregion       *region;
706         double          pixval;
707 
708         for (j = from; j < to; ++j)
709                 line[j] = (float) 0.0;
710 
711         if (image == NULL || image->vtype == ptr_v)
712                 return;
713 
714         region = image->region;
715         if (i < region->lx || i >= region->ux)
716                 return;
717 
718         if (from >= region->uy || to < region->ly)
719                 return;
720 
721         if (to > region->uy)
722                 to = region->uy;
723 
724         if (from < region->ly)
725                 from = region->ly;
726 
727         for (j = from; j < to; ++j)
728         {
729                 IM_PIX_GET(image, j, i, pixval);
730                 line[j] = (float) pixval;
731         }
732 }
733 
734 
735 /**
736  * @brief Copies the values of a portion of a specified row of a complex image into a complex vector.
737  * @param line A complex vector, which must already be allocated, to hold the image row data.
738  * @param image The image to read data from.
739  * @param i The coordinate of the row to read data from.
740  * @param from The column at which to start reading data.
741  * @param to The column at which to stop reading data.
742  * @return void
743  *
744  * Copies the values of a portion of a specified row of a complex image into an complex vector, which must be
745  * allocated before the function is called. No check is made on line:
746  * this will crash if line is not allocated, too short etc. Any part of the vector outside the image will 
747  * be filled with zeros.
748  */
749 void            im_get_rowz(Complex * line, Imrect * image, int i, int from, int to)
750 {
751         int             j;
752         Imregion       *region;
753 
754         for (j = from; j < to; ++j)
755                 line[j] = cmplx_zero();
756 
757         if (image == NULL || image->vtype == ptr_v)
758                 return;
759 
760         region = image->region;
761         if (i < region->ly || i >= region->uy)
762                 return;
763 
764         if (from >= region->ux || to < region->lx)
765                 return;
766 
767         if (to > region->ux)
768                 to = region->ux;
769 
770         if (from < region->lx)
771                 from = region->lx;
772 
773         if (image->vtype == complex_v)
774         {
775                 for (j = from; j < to; ++j)
776                         line[j] = IM_COMPLEX(image, i, j);
777         } else
778         {
779                 for (j = from; j < to; ++j)
780                         IM_PIX_GET(image, i, j, line[j].x);
781         }
782 }
783 
784 
785 /**
786  * @brief Copies the values of a portion of a specified column of a complex image into a complex vector.
787  * @param line A complex vector, which must already be allocated, to hold the image column data.
788  * @param image The image to read data from.
789  * @param i The coordinate of the column to read data from.
790  * @param from The row at which to start reading data.
791  * @param to The row at which to stop reading data.
792  * @return void
793  *
794  * Copies the values of a portion of a specified column of a complex image into an complex vector, which must be
795  * allocated before the function is called. No check is made on line:
796  * this will crash if line is not allocated, too short etc. Any part of the vector outside the image will 
797  * be filled with zeros.
798  */
799 void            im_get_colz(Complex * line, Imrect * image, int i, int from, int to)
800 {
801         int             j;
802         Imregion       *region;
803 
804         for (j = from; j < to; ++j)
805                 line[j] = cmplx_zero();
806 
807         if (image == NULL || image->vtype == ptr_v)
808                 return;
809 
810         region = image->region;
811         if (i < region->lx || i >= region->ux)
812                 return;
813 
814         if (from >= region->uy || to < region->ly)
815                 return;
816 
817         if (to > region->uy)
818                 to = region->uy;
819 
820         if (from < region->ly)
821                 from = region->ly;
822 
823         if (image->vtype == complex_v)
824         {
825                 for (j = from; j < to; ++j)
826                         line[j] = IM_COMPLEX(image, j, i);
827         } else
828         {
829                 for (j = from; j < to; ++j)
830                         IM_PIX_GET(image, j, i, line[j].x);
831         }
832 }
833 
834 
835 /**
836  * @brief Copies the values along a positive diagonal line in an image into a vector, casting them to integers.
837  * @param line Integer vector into which the image data is copied.
838  * @param image The image to read data from.
839  * @param x x-coordinate of the starting point of the diagonal.
840  * @param y y-coordinate of the starting point of the diagonal.
841  * @param len length of the diagonal from which to copy data.
842  * @return void
843  *
844  * Copies the values from a positive diagonal line on an image, starting from a point specified by x,y and of 
845  * length len, into the integer vector line, casting them to integers where neccessary. The direction of the line is 
846  * such that both coordinates increase i.e. down and right in the image plane. No check is made on line:
847  * this will crash if line is not allocated, too short etc. Any part of the vector outside the image will 
848  * be filled with zeros, and the whole vector will be filled with zeros if the image is of type complex or
849  * pointer. 
850  */
851 void            im_get_pos_diag(int *line, Imrect * image, int x, int y, int len)
852 {
853         int             j;
854         int             minoff;
855         Imregion       *region;
856 
857         for (j = 0; j < len; ++j)
858                 line[j] = 0;
859 
860         if (image == NULL)
861                 return;
862 
863         region = image->region;
864         if (x >= region->ux || (x + len) < region->lx)
865                 return;
866 
867         if (y >= region->uy || (y + len) < region->ly)
868                 return;
869 
870         minoff = MIN(x - region->lx, y - region->ly);
871         if (minoff < 0)
872         {
873                 x -= minoff;
874                 y -= minoff;
875                 len += minoff;
876         }
877         minoff = MIN(region->ux - x - len, region->uy - y - len);
878         if (minoff < 0)
879                 len += minoff;
880 
881         switch (image->vtype)
882         {
883         case char_v:
884                 {
885                         char          **array = (char **) image->data;
886 
887                         for (j = 0; j < len; j++)
888                                 line[j] = array[y + j][x + j];
889                 }
890                 break;
891         case uchar_v:
892                 {
893                         unsigned char **array = (unsigned char **) image->data;
894 
895                         for (j = 0; j < len; j++)
896                                 line[j] = array[y + j][x + j];
897                 }
898                 break;
899         case short_v:
900                 {
901                         short         **array = (short **) image->data;
902 
903                         for (j = 0; j < len; j++)
904                                 line[j] = array[y + j][x + j];
905                 }
906                 break;
907         case ushort_v:
908                 {
909                         unsigned short **array = (unsigned short **) image->data;
910 
911                         for (j = 0; j < len; j++)
912                                 line[j] = array[y + j][x + j];
913                 }
914                 break;
915         case int_v:
916                 {
917                         int           **array = (int **) image->data;
918 
919                         for (j = 0; j < len; j++)
920                                 line[j] = array[y + j][x + j];
921                 }
922                 break;
923         case uint_v:
924                 {
925                         unsigned int  **array = (unsigned int **) image->data;
926 
927                         for (j = 0; j < len; j++)
928                                 line[j] = array[y + j][x + j];
929                 }
930                 break;
931         case float_v:
932                 {
933                         float         **array = (float **) image->data;
934 
935                         for (j = 0; j < len; j++)
936                         {
937                                 float           gl = array[y + j][x + j];
938 
939                                 line[j] = (int) ((gl > 0) ? gl + 0.5 : gl - 0.5);
940                         }
941                 }
942                 break;
943         case double_v:
944                 {
945                         double        **array = (double **) image->data;
946 
947                         for (j = 0; j < len; j++)
948                         {
949                                 double          gl = array[y + j][x + j];
950 
951                                 line[j] = (int) ((gl > 0) ? gl + 0.5 : gl - 0.5);
952                         }
953                 }
954                 break;
955         default:
956                 error("im_get_pos_diag: unsupported type", non_fatal);
957                 break;
958         }
959 }
960 
961 
962 /**
963  * @brief Copies the values along a negative diagonal line in an image into a vector, casting them to integers.
964  * @param line Integer vector into which the image data is copied.
965  * @param image The image to read data from.
966  * @param x x-coordinate of the starting point of the diagonal.
967  * @param y y-coordinate of the starting point of the diagonal.
968  * @param len length of the diagonal from which to copy data.
969  * @return void
970  *
971  * Copies the values from a negative diagonal line on an image, starting from a point specified by x,y and of 
972  * length len, into the integer vector line, casting them to integers where neccessary. The direction of the line is 
973  * such that the y coordinate increases whilst the x decreases i.e. down and left in the image plane. No check is made on line:
974  * this will crash if line is not allocated, too short etc. Any part of the vector outside the image will 
975  * be filled with zeros, and the whole vector will be filled with zeros if the image is of type complex or
976  * pointer. 
977  */
978 void            im_get_neg_diag(int *line, Imrect * image, int x, int y, int len)
979 {
980         int             j;
981         int             minoff;
982         Imregion       *region;
983 
984         for (j = 0; j < len; ++j)
985                 line[j] = 0;
986 
987         if (image == NULL)
988                 return;
989 
990         region = image->region;
991         if (x < region->lx || (x - len) >= region->ux)
992                 return;
993 
994         if (y >= region->uy || (y + len) < region->ly)
995                 return;
996 
997         minoff = MIN(region->ux - x, y - region->ly);
998         if (minoff < 0)
999         {
1000                 x += minoff;
1001                 y -= minoff;
1002                 len += minoff;
1003         }
1004         minoff = MIN(x - len - region->lx, region->uy - y - len);
1005         if (minoff < 0)
1006                 len += minoff;
1007 
1008 
1009         switch (image->vtype)
1010         {
1011         case char_v:
1012                 {
1013                         char          **array = (char **) image->data;
1014 
1015                         for (j = 0; j < len; j++)
1016                                 line[j] = array[y + j][x - j];
1017                 }
1018                 break;
1019         case uchar_v:
1020                 {
1021                         unsigned char **array = (unsigned char **) image->data;
1022 
1023                         for (j = 0; j < len; j++)
1024                                 line[j] = array[y + j][x - j];
1025                 }
1026                 break;
1027         case short_v:
1028                 {
1029                         short         **array = (short **) image->data;
1030 
1031                         for (j = 0; j < len; j++)
1032                                 line[j] = array[y + j][x - j];
1033                 }
1034                 break;
1035         case ushort_v:
1036                 {
1037                         unsigned short **array = (unsigned short **) image->data;
1038 
1039                         for (j = 0; j < len; j++)
1040                                 line[j] = array[y + j][x - j];
1041                 }
1042                 break;
1043         case int_v:
1044                 {
1045                         int           **array = (int **) image->data;
1046 
1047                         for (j = 0; j < len; j++)
1048                                 line[j] = array[y + j][x - j];
1049                 }
1050                 break;
1051         case uint_v:
1052                 {
1053                         unsigned int  **array = (unsigned int **) image->data;
1054 
1055                         for (j = 0; j < len; j++)
1056                                 line[j] = array[y + j][x - j];
1057                 }
1058                 break;
1059         case float_v:
1060                 {
1061                         float         **array = (float **) image->data;
1062 
1063                         for (j = 0; j < len; j++)
1064                         {
1065                                 float           gl = array[y + j][x - j];
1066 
1067                                 line[j] = (int) ((gl > 0) ? gl + 0.5 : gl - 0.5);
1068                         }
1069                 }
1070                 break;
1071         case double_v:
1072                 {
1073                         double        **array = (double **) image->data;
1074 
1075                         for (j = 0; j < len; j++)
1076                         {
1077                                 double          gl = array[y + j][x - j];
1078 
1079                                 line[j] = (int) ((gl > 0) ? gl + 0.5 : gl - 0.5);
1080                         }
1081                 }
1082                 break;
1083         default:
1084                 error("im_get_neg_diag: unsupported type", non_fatal);
1085                 break;
1086         }
1087 }
1088 
1089 
1090 /**
1091  * @brief Copies the values along a positive diagonal line in an image into a vector, casting them to floats.
1092  * @param line Vector into which the image data is copied.
1093  * @param image The image to read data from.
1094  * @param x x-coordinate of the starting point of the diagonal.
1095  * @param y y-coordinate of the starting point of the diagonal.
1096  * @param len length of the diagonal from which to copy data.
1097  * @return void
1098  *
1099  * Copies the values from a positive diagonal line on an image, starting from a point specified by x,y and of 
1100  * length len, into the integer vector line, casting them to floats. The direction of the line is 
1101  * such that both coordinates increase i.e. down and right in the image plane. No check is made on line:
1102  * this will crash if line is not allocated, too short etc. Any part of the vector outside the image will 
1103  * be filled with zeros, and the whole vector will be filled with zeros if the image is of type complex or
1104  * pointer. 
1105  */
1106 void            im_get_pos_diagf(float *line, Imrect * image, int x, int y, int len)
1107 {
1108         int             j;
1109         int             minoff;
1110         Imregion       *region;
1111 
1112         for (j = 0; j < len; ++j)
1113                 line[j] = (float) 0.0;
1114 
1115         if (image == NULL)
1116                 return;
1117 
1118         region = image->region;
1119         if (x >= region->ux || (x + len) < region->lx)
1120                 return;
1121 
1122         if (y >= region->uy || (y + len) < region->ly)
1123                 return;
1124 
1125         minoff = MIN(x - region->lx, y - region->ly);
1126         if (minoff < 0)
1127         {
1128                 x -= minoff;
1129                 y -= minoff;
1130                 len += minoff;
1131         }
1132         minoff = MIN(region->ux - x - len, region->uy - y - len);
1133         if (minoff < 0)
1134                 len += minoff;
1135 
1136         switch (image->vtype)
1137         {
1138         case char_v:
1139                 {
1140                         char          **array = (char **) image->data;
1141 
1142                         for (j = 0; j < len; j++)
1143                                 line[j] = array[y + j][x + j];
1144                 }
1145                 break;
1146         case uchar_v:
1147                 {
1148                         unsigned char **array = (unsigned char **) image->data;
1149 
1150                         for (j = 0; j < len; j++)
1151                                 line[j] = array[y + j][x + j];
1152                 }
1153                 break;
1154         case short_v:
1155                 {
1156                         short         **array = (short **) image->data;
1157 
1158                         for (j = 0; j < len; j++)
1159                                 line[j] = array[y + j][x + j];
1160                 }
1161                 break;
1162         case ushort_v:
1163                 {
1164                         unsigned short **array = (unsigned short **) image->data;
1165 
1166                         for (j = 0; j < len; j++)
1167                                 line[j] = array[y + j][x + j];
1168                 }
1169                 break;
1170         case int_v:
1171                 {
1172                         int           **array = (int **) image->data;
1173 
1174                         for (j = 0; j < len; j++)
1175                                 line[j] = (float) array[y + j][x + j];
1176                 }
1177                 break;
1178         case uint_v:
1179                 {
1180                         unsigned int  **array = (unsigned int **) image->data;
1181 
1182                         for (j = 0; j < len; j++)
1183                                 line[j] = (float) array[y + j][x + j];
1184                 }
1185                 break;
1186         case float_v:
1187                 {
1188                         float         **array = (float **) image->data;
1189 
1190                         for (j = 0; j < len; j++)
1191                         {
1192                                 float           gl = array[y + j][x + j];
1193 
1194                                 line[j] = (float) ((gl > 0) ? gl + 0.5 : gl - 0.5);
1195                         }
1196                 }
1197                 break;
1198         case double_v:
1199                 {
1200                         double        **array = (double **) image->data;
1201 
1202                         for (j = 0; j < len; j++)
1203                         {
1204                                 double          gl = array[y + j][x + j];
1205 
1206                                 line[j] = (float) ((gl > 0) ? gl + 0.5 : gl - 0.5);
1207                         }
1208                 }
1209                 break;
1210         default:
1211                 error("im_get_pos_diagf: unsupported type", non_fatal);
1212                 break;
1213         }
1214 }
1215 
1216 
1217 
1218 /**
1219  * @brief Copies the values along a negative diagonal line in an image into a vector, casting them to floats.
1220  * @param line Vector into which the image data is copied.
1221  * @param image The image to read data from.
1222  * @param x x-coordinate of the starting point of the diagonal.
1223  * @param y y-coordinate of the starting point of the diagonal.
1224  * @param len length of the diagonal from which to copy data.
1225  * @return void
1226  *
1227  * Copies the values from a negative diagonal line on an image, starting from a point specified by x,y and of 
1228  * length len, into the vector line, casting them to floats. The direction of the line is such that the y
1229  * coordinate increases whilst the x decreases i.e. down and left in the image plane. No check is made on line:
1230  * this will crash if line is not allocated, too short etc. Any part of the vector outside the image will 
1231  * be filled with zeros, and the whole vector will be filled with zeros if the image is of type complex or
1232  * pointer. 
1233  */
1234 void            im_get_neg_diagf(float *line, Imrect * image, int x, int y, int len)
1235 {
1236         int             j;
1237         int             minoff;
1238         Imregion       *region;
1239 
1240         for (j = 0; j < len; ++j)
1241                 line[j] = (float) 0.0;
1242 
1243         if (image == NULL)
1244                 return;
1245 
1246         region = image->region;
1247         if (x < region->lx || (x - len) >= region->ux)
1248                 return;
1249 
1250         if (y >= region->uy || (y + len) < region->ly)
1251                 return;
1252 
1253         minoff = MIN(region->ux - x, y - region->ly);
1254         if (minoff < 0)
1255         {
1256                 x += minoff;
1257                 y -= minoff;
1258                 len += minoff;
1259         }
1260         minoff = MIN(x - len - region->lx, region->uy - y - len);
1261         if (minoff < 0)
1262                 len += minoff;
1263 
1264         switch (image->vtype)
1265         {
1266         case char_v:
1267                 {
1268                         char          **array = (char **) image->data;
1269 
1270                         for (j = 0; j < len; j++)
1271                                 line[j] = array[y + j][x - j];
1272                 }
1273                 break;
1274         case uchar_v:
1275                 {
1276                         unsigned char **array = (unsigned char **) image->data;
1277 
1278                         for (j = 0; j < len; j++)
1279                                 line[j] = array[y + j][x - j];
1280                 }
1281                 break;
1282         case short_v:
1283                 {
1284                         short         **array = (short **) image->data;
1285 
1286                         for (j = 0; j < len; j++)
1287                                 line[j] = array[y + j][x - j];
1288                 }
1289                 break;
1290         case ushort_v:
1291                 {
1292                         unsigned short **array = (unsigned short **) image->data;
1293 
1294                         for (j = 0; j < len; j++)
1295                                 line[j] = array[y + j][x - j];
1296                 }
1297                 break;
1298         case int_v:
1299                 {
1300                         int           **array = (int **) image->data;
1301 
1302                         for (j = 0; j < len; j++)
1303                                 line[j] = (float) array[y + j][x - j];
1304                 }
1305                 break;
1306         case uint_v:
1307                 {
1308                         unsigned int  **array = (unsigned int **) image->data;
1309 
1310                         for (j = 0; j < len; j++)
1311                                 line[j] = (float) array[y + j][x - j];
1312                 }
1313                 break;
1314         case float_v:
1315                 {
1316                         float         **array = (float **) image->data;
1317 
1318                         for (j = 0; j < len; j++)
1319                         {
1320                                 float           gl = array[y + j][x - j];
1321 
1322                                 line[j] = (float) ((gl > 0) ? gl + 0.5 : gl - 0.5);
1323                         }
1324                 }
1325                 break;
1326         case double_v:
1327                 {
1328                         double        **array = (double **) image->data;
1329 
1330                         for (j = 0; j < len; j++)
1331                         {
1332                                 double          gl = array[y + j][x - j];
1333 
1334                                 line[j] = (float) ((gl > 0) ? gl + 0.5 : gl - 0.5);
1335                         }
1336                 }
1337                 break;
1338         default:
1339                 error("im_get_pos_diagf: unsupported type", non_fatal);
1340                 break;
1341         }
1342 }
1343 

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