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

Linux Cross Reference
Tina6/tina-libs/tina/image/imgPrc_ptr.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/imgPrc_ptr.c,v $
 37  * Date    :  $Date: 2005/01/23 19:10:21 $
 38  * Version :  $Revision: 1.5 $
 39  * CVS Id  :  $Id: imgPrc_ptr.c,v 1.5 2005/01/23 19:10:21 paul Exp $
 40  *
 41  * Author  : Legacy TINA
 42  */
 43 
 44 /** 
 45  *  @file
 46  *  @brief Handing of pointer images; operations Vec2 and Mat2.
 47  *
 48  * Handling images of vec2's and mat2's
 49  * Some image apply and combine functions are also defined here
 50  *
 51  * (shouldn't this file be split?)
 52  *
 53  */
 54 
 55 #include "imgPrc_ptr.h"
 56 
 57 #if HAVE_CONFIG_H
 58 #include <config.h>
 59 #endif
 60 
 61 #include <math.h>
 62 #include <tina/sys/sysDef.h>
 63 #include <tina/sys/sysPro.h>
 64 #include <tina/math/mathDef.h>
 65 #include <tina/math/mathPro.h>
 66 #include <tina/image/img_GenDef.h>
 67 #include <tina/image/img_GenPro.h>
 68 #include <tina/image/imgPrc_deriv.h>
 69 
 70 /**
 71 applying function to image
 72 ptr -> void
 73 **/
 74 
 75 void            im_ptr_apply(Imrect * im, void (*func) (), void *data)
 76 {
 77         int            *row;
 78         int             lx, ux, ly, uy;
 79         int             i, j;
 80 
 81         if (im == NULL)
 82                 return;
 83 
 84         lx = im->region->lx;
 85         ux = im->region->ux;
 86         ly = im->region->ly;
 87         uy = im->region->uy;
 88         row = tvector_alloc(lx, ux, int); 
 89 
 90         for (i = ly; i < uy; ++i)
 91         {
 92                 im_get_row(row, im, i, lx, ux);
 93                 for (j = lx; j < ux; ++j)
 94                         /*(*func) ((void *) row[j], data);*/
 95                         (*func) ((void *) (long int)row[j], data); /*JD, 2015.01.27*/
 96         }
 97 
 98         tvector_free(row, lx, int); 
 99 }
100 
101 /**
102 applying function to image
103 ptr -> ptr
104 **/
105 
106 Imrect         *im_pp_apply(Imrect * im1, void *(*func) (), void *data)
107 {
108         Imrect         *im2;
109         int            *row1, *row2;
110         int             lx, ux, ly, uy;
111         int             i, j;
112 
113         if (im1 == NULL)
114                 return (NULL);
115 
116         lx = im1->region->lx;
117         ux = im1->region->ux;
118         ly = im1->region->ly;
119         uy = im1->region->uy;
120         im2 = im_alloc(im1->height, im1->width, im1->region, ptr_v);
121         row1 = tvector_alloc(lx, ux, int); 
122         row2 = tvector_alloc(lx, ux, int); 
123 
124         for (i = ly; i < uy; ++i)
125         {
126                 im_get_row(row1, im1, i, lx, ux);
127                 for (j = lx; j < ux; ++j)
128                         /*row2[j] =  (int)(*func) ((void *) row1[j], data);*/
129                         row2[j] = (long int) (*func) ((void *) (long int)row1[j], data); /*JD, 2015.01.27*/
130                 im_put_row(row2, im2, i, lx, ux);
131         }
132 
133         tvector_free(row1, lx, int); 
134         tvector_free(row2, lx, int); 
135 
136         return (im2);
137 }
138 
139 /**
140 applying function to image
141 ptr -> float
142 **/
143 
144 Imrect         *im_pf_apply(Imrect * im1, double (*func) (), void *data)
145 {
146         Imrect         *im2;
147         int            *row1;
148         float          *row2;
149         int             lx, ux, ly, uy;
150         int             i, j;
151 
152         if (im1 == NULL)
153                 return (NULL);
154 
155         lx = im1->region->lx;
156         ux = im1->region->ux;
157         ly = im1->region->ly;
158         uy = im1->region->uy;
159         im2 = im_alloc(im1->height, im1->width, im1->region, float_v);
160         row1 = tvector_alloc(lx, ux, int);
161         row2 = tvector_alloc(lx, ux, float);
162 
163         for (i = ly; i < uy; ++i)
164         {
165                 im_get_row(row1, im1, i, lx, ux);
166                 for (j = lx; j < ux; ++j)
167                         /*row2[j] = (float) ((*func) ((void *) row1[j], data));*/
168                         row2[j] = (float) ((*func) ((void *) (long int)row1[j], data)); /*JD, 2015.01.27*/
169                 im_put_rowf(row2, im2, i, lx, ux);
170         }
171 
172         tvector_free(row1, lx, int);
173         tvector_free(row2, lx, float);
174 
175         return (im2);
176 }
177 
178 /**
179 combining two images
180 ptr ptr -> ptr
181 **/
182 
183 Imrect         *im_ppp_combine(Imrect * im1, Imrect * im2, void *(*func) (), void *data)
184 {
185         Imrect         *im3;
186         Imregion       *roi;
187         int            *row1, *row2, *row3;
188         int             lx, ux, ly, uy;
189         int             width, height;
190         int             i, j;
191 
192         if (im1 == NULL || im2 == NULL)
193                 return (NULL);
194 
195         roi = roi_inter(im1->region, im2->region);
196         if (roi == NULL)
197                 return (NULL);
198         lx = roi->lx;
199         ux = roi->ux;
200         ly = roi->ly;
201         uy = roi->uy;
202 
203         width = MIN(im1->width, im2->width);
204         height = MIN(im1->height, im2->height);
205 
206         im3 = im_alloc(height, width, roi, ptr_v);
207         row1 = tvector_alloc(lx, ux, int);
208         row2 = tvector_alloc(lx, ux, int);
209         row3 = tvector_alloc(lx, ux, int);
210 
211         for (i = ly; i < uy; ++i)
212         {
213                 im_get_row(row1, im1, i, lx, ux);
214                 im_get_row(row2, im2, i, lx, ux);
215                 for (j = lx; j < ux; ++j)
216                         /*row3[j] = (int) (*func) ((void *) row1[j], (void *) row2[j], data);*/
217                         row3[j] = (long int) (*func) ((void *) (long int)row1[j], (void *) (long int)row2[j], data); /*JD, 2015.01.27*/
218                 im_put_row(row3, im3, i, lx, ux);
219         }
220 
221         tvector_free(row1, lx, int);
222         tvector_free(row2, lx, int);
223         tvector_free(row3, lx, int);
224         rfree(roi);
225         return (im3);
226 }
227 
228 /**
229 combining two images
230 float float -> ptr
231 **/
232 
233 Imrect         *im_ffp_combine(Imrect * im1, Imrect * im2, void *(*func) (), void *data)
234 {
235         Imrect         *im3;
236         Imregion       *roi;
237         float          *row1, *row2;
238         int            *row3;
239         int             lx, ux, ly, uy;
240         int             width, height;
241         int             i, j;
242 
243         if (im1 == NULL || im2 == NULL)
244                 return (NULL);
245 
246         roi = roi_inter(im1->region, im2->region);
247         if (roi == NULL)
248                 return (NULL);
249         lx = roi->lx;
250         ux = roi->ux;
251         ly = roi->ly;
252         uy = roi->uy;
253 
254         width = MIN(im1->width, im2->width);
255         height = MIN(im1->height, im2->height);
256 
257         im3 = im_alloc(height, width, roi, ptr_v);
258         row1 = tvector_alloc(lx, ux, float);
259         row2 = tvector_alloc(lx, ux, float);
260         row3 = tvector_alloc(lx, ux, int);
261 
262         for (i = ly; i < uy; ++i)
263         {
264                 im_get_rowf(row1, im1, i, lx, ux);
265                 im_get_rowf(row2, im2, i, lx, ux);
266                 for (j = lx; j < ux; ++j)
267                         /*row3[j] = (int) (*func) (row1[j], row2[j], data);*/
268                         row3[j] = (long int) (*func) (row1[j], row2[j], data); /*JD, 2015.01.27*/
269                 im_put_row(row3, im3, i, lx, ux);
270         }
271 
272         tvector_free(row1, lx, float);
273         tvector_free(row2, lx, float);
274         tvector_free(row3, lx, int);
275         rfree(roi);
276         return (im3);
277 }
278 
279 Imrect         *im_fffp_combine(Imrect * im1, Imrect * im2, Imrect * im3, void *(*func) (), void *data)
280 {
281         Imrect         *im4=NULL;
282         Imregion       *roi=NULL;
283         float          *row1=NULL, *row2=NULL, *row3=NULL;
284         int            *row4=NULL;
285         int             lx, ux, ly, uy;
286         int             width, height;
287         int             i, j;
288 
289         if (im1 == NULL || im2 == NULL)
290                 return (NULL);
291 
292         roi = roi_inter(im1->region, im2->region);
293         if (roi == NULL)
294                 return (NULL);
295         lx = roi->lx;
296         ux = roi->ux;
297         ly = roi->ly;
298         uy = roi->uy;
299 
300         width = MIN(im1->width, im2->width);
301         height = MIN(im1->height, im2->height);
302 
303         im3 = im_alloc(height, width, roi, ptr_v);
304         row1 = tvector_alloc(lx, ux, float);
305         row2 = tvector_alloc(lx, ux, float);
306         row3 = tvector_alloc(lx, ux, float);
307         row4 = tvector_alloc(lx, ux, int);
308 
309         for (i = ly; i < uy; ++i)
310         {
311                 im_get_rowf(row1, im1, i, lx, ux);
312                 im_get_rowf(row2, im2, i, lx, ux);
313                 im_get_rowf(row3, im3, i, lx, ux);
314                 for (j = lx; j < ux; ++j)
315                         /*row4[j] = (int) (*func) (row1[j], row2[j], row3[j], data);*/
316                         row4[j] = (long int) (*func) (row1[j], row2[j], row3[j], data); /*JD, 2015.01.27*/
317                 im_put_row(row4, im4, i, lx, ux);
318         }
319 
320         tvector_free(row1, lx, float);
321         tvector_free(row2, lx, float);
322         tvector_free(row3, lx, float);
323         tvector_free(row4, lx, int);
324         rfree(roi);
325         return (im4);
326 }
327 
328 
329 /**
330 combining two images
331 float ptr -> ptr
332 **/
333 
334 Imrect         *im_fpp_combine(Imrect * im1, Imrect * im2, void *(*func) (), void *data)
335 {
336         Imrect         *im3;
337         Imregion       *roi;
338         float          *row1;
339         int            *row2, *row3;
340         int             lx, ux, ly, uy;
341         int             width, height;
342         int             i, j;
343 
344         if (im1 == NULL || im2 == NULL)
345                 return (NULL);
346 
347         roi = roi_inter(im1->region, im2->region);
348         if (roi == NULL)
349                 return (NULL);
350         lx = roi->lx;
351         ux = roi->ux;
352         ly = roi->ly;
353         uy = roi->uy;
354 
355         width = MIN(im1->width, im2->width);
356         height = MIN(im1->height, im2->height);
357 
358         im3 = im_alloc(height, width, roi, ptr_v);
359         row1 = tvector_alloc(lx, ux, float);
360         row2 = tvector_alloc(lx, ux, int);
361         row3 = tvector_alloc(lx, ux, int);
362 
363         for (i = ly; i < uy; ++i)
364         {
365                 im_get_rowf(row1, im1, i, lx, ux);
366                 im_get_row(row2, im2, i, lx, ux);
367                 for (j = lx; j < ux; ++j)
368                         /*row3[j] = (int) (*func) (row1[j], (void *) row2[j], data);*/
369                         row3[j] = (long int) (*func) (row1[j], (void *) (long int)row2[j], data); /*JD, 2015.01.27*/
370                 im_put_row(row3, im3, i, lx, ux);
371         }
372 
373         tvector_free(row1, lx, float);
374         tvector_free(row2, lx, int);
375         tvector_free(row3, lx, int);
376         rfree(roi);
377         return (im3);
378 }
379 
380 /**
381 combining two images
382 ptr ptr -> float
383 **/
384 
385 Imrect         *im_ppf_combine(Imrect * im1, Imrect * im2, double (*func) (), void *data)
386 {
387         Imrect         *im3;
388         Imregion       *roi;
389         int            *row1, *row2;
390         float          *row3;
391         int             lx, ux, ly, uy;
392         int             width, height;
393         int             i, j;
394 
395         if (im1 == NULL || im2 == NULL)
396                 return (NULL);
397 
398         roi = roi_inter(im1->region, im2->region);
399         if (roi == NULL)
400                 return (NULL);
401         lx = roi->lx;
402         ux = roi->ux;
403         ly = roi->ly;
404         uy = roi->uy;
405 
406         width = MIN(im1->width, im2->width);
407         height = MIN(im1->height, im2->height);
408 
409         im3 = im_alloc(height, width, roi, ptr_v);
410         row1 = tvector_alloc(lx, ux, int);
411         row2 = tvector_alloc(lx, ux, int);
412         row3 = tvector_alloc(lx, ux, float);
413 
414         for (i = ly; i < uy; ++i)
415         {
416                 im_get_row(row1, im1, i, lx, ux);
417                 im_get_row(row2, im2, i, lx, ux);
418                 for (j = lx; j < ux; ++j)
419                         /*row3[j] = (float) ((*func) ((void *) row1[j], (void *) row2[j], data));*/
420                         row3[j] = (float) ((*func) ((void *) (long int)row1[j], (void *) (long int)row2[j], data)); /*JD, 2015.01.27*/
421                 im_put_rowf(row3, im3, i, lx, ux);
422         }
423 
424         tvector_free(row1, lx, int);
425         tvector_free(row2, lx, int);
426         tvector_free(row3, lx, float);
427         rfree(roi);
428         return (im3);
429 }
430 
431 /* free image of vec2's or mat2's */
432 
433 void            im_vec2_free(Imrect * im)
434 {
435         im_ptr_apply(im, rfree, NULL);
436         im_free(im);
437 }
438 
439 void            im_vec3_free(Imrect * im)
440 {
441         im_ptr_apply(im, rfree, NULL);
442         im_free(im);
443 }
444 
445 void            im_mat2_free(Imrect * im)
446 {
447         im_ptr_apply(im, rfree, NULL);
448         im_free(im);
449 }
450 
451 /* make image of ptr's to vec2's x-coord from im1 y-coord from im2 */
452 
453 static void    *pvec2_make(double x, double y)
454 {
455         return (vec2_make(vec2(x, y)));
456 }
457 
458 Imrect         *im_vec2(Imrect * im1, Imrect * im2)
459 {
460         return (im_ffp_combine(im1, im2, pvec2_make, NULL));
461 }
462 
463 /* add two vec2 images */
464 
465 static void    *pvec2_sum(Vec2 * u, Vec2 * v)
466 {
467         return (vec2_make(vec2_sum(*u, *v)));
468 }
469 
470 Imrect         *im_vec2_sum(Imrect * u, Imrect * v)
471 {
472         return (im_ppp_combine(u, v, pvec2_sum, NULL));
473 }
474 
475 /* subtract  two vec2 images */
476 
477 static void    *pvec2_diff(Vec2 * u, Vec2 * v)
478 {
479         return (vec2_make(vec2_diff(*u, *v)));
480 }
481 
482 Imrect         *im_vec2_diff(Imrect * u, Imrect * v)
483 {
484         return (im_ppp_combine(u, v, pvec2_diff, NULL));
485 }
486 
487 /* dot product of two vec2 images */
488 
489 static double   pvec2_dot(Vec2 * u, Vec2 * v)
490 {
491         return (vec2_dot(*u, *v));
492 }
493 
494 Imrect         *im_vec2_dot(Imrect * u, Imrect * v)
495 {
496         return (im_ppf_combine(u, v, pvec2_dot, NULL));
497 }
498 
499 /* cross product of two vec2 images */
500 
501 static double   pvec2_cross(Vec2 * u, Vec2 * v)
502 {
503         return (vec2_cross(*u, *v));
504 }
505 
506 Imrect         *im_vec2_cross(Imrect * u, Imrect * v)
507 {
508         return (im_ppf_combine(u, v, pvec2_cross, NULL));
509 }
510 
511 /* product of mat2 image and vec2 image */
512 
513 static void    *pmat2_vprod(Mat2 * m, Vec2 * v)
514 {
515         return (vec2_make(mat2_vprod(*m, *v)));
516 }
517 
518 Imrect         *im_mat2_vprod(Imrect * m, Imrect * v)
519 {
520         return (im_ppp_combine(m, v, pmat2_vprod, NULL));
521 }
522 
523 /* scalar product of vec2 image, mat2 image and vec2 image */
524 
525 Imrect         *im_mat2_sprod(Imrect * u, Imrect * m, Imrect * v)
526 {
527         Imrect         *mv = im_mat2_vprod(m, v);
528         Imrect         *umv;
529 
530         umv = im_vec2_dot(u, mv);
531         im_ptr_apply(mv, rfree, NULL);
532         return (umv);
533 }
534 
535 /* invert mat2 image */
536 
537 static void    *pmat2_inverse(Mat2 * m)
538 {
539         return (mat2_make(mat2_inverse(*m)));
540 }
541 
542 Imrect         *im_mat2_inverse(Imrect * m)
543 {
544         return (im_pp_apply(m, pmat2_inverse, NULL));
545 }
546 
547 /* make image of mat2's from images of column vectors */
548 
549 static void    *pmat2_of_cols(Vec2 * cx, Vec2 * cy)
550 {
551         return (mat2_make(mat2_of_cols(*cx, *cy)));
552 }
553 
554 Imrect         *im_mat2_of_cols(Imrect * cx, Imrect * cy)
555 {
556         return (im_ppp_combine(cx, cy, pmat2_of_cols, NULL));
557 }
558 
559 /* make image of mat2's from images of row vectors */
560 
561 static void    *pmat2_of_rows(Vec2 * rx, Vec2 * ry)
562 {
563         return (mat2_make(mat2_of_rows(*rx, *ry)));
564 }
565 
566 Imrect         *im_mat2_of_rows(Imrect * rx, Imrect * ry)
567 {
568         return (im_ppp_combine(rx, ry, pmat2_of_rows, NULL));
569 }
570 
571 /* image of gradients */
572 
573 Imrect         *im_vec2_grad(Imrect * im)
574 {
575         Imrect         *imx = imf_diffx(im);
576         Imrect         *imy = imf_diffy(im);
577         Imrect         *g;
578 
579         g = im_vec2(imx, imy);
580         im_free(imx);
581         im_free(imy);
582         return (g);
583 }
584 
585 /* setup images of gradients and hessians */
586 
587 void            im_mat2_grad_hessian(Imrect * im, Imrect ** g, Imrect ** h)
588 {
589         Imrect         *imx = imf_diffx(im);
590         Imrect         *imy = imf_diffy(im);
591         Imrect         *gx;
592         Imrect         *gy;
593 
594         gx = im_vec2_grad(imx);
595         gy = im_vec2_grad(imy);
596         *g = im_vec2(imx, imy);
597         im_free(imx);
598         im_free(imy);
599         *h = im_mat2_of_cols(gx, gy);
600         im_vec2_free(gx);
601         im_vec2_free(gy);
602 }
603 
604 /* return image of hessians */
605 
606 Imrect         *im_mat2_hessian(Imrect * im)
607 {
608         Imrect         *g;
609         Imrect         *h;
610 
611         im_mat2_grad_hessian(im, &g, &h);
612         im_vec2_free(g);
613         return (h);
614 }
615 
616 /* image of determinants */
617 
618 static double   pmat2_det(Mat2 * m)
619 {
620         return (mat2_det(*m));
621 }
622 
623 Imrect         *im_mat2_det(Imrect * m)
624 {
625         return (im_pf_apply(m, pmat2_det, NULL));
626 }
627 
628 /* components of vec2 and mat2 images */
629 
630 static double   pvec2_x(Vec2 * v)
631 {
632         return (vec2_x(*v));
633 }
634 
635 Imrect         *im_vec2_x(Imrect * v)
636 {
637         return (im_pf_apply(v, pvec2_x, NULL));
638 }
639 
640 static double   pvec2_y(Vec2 * v)
641 {
642         return (vec2_y(*v));
643 }
644 
645 Imrect         *im_vec2_y(Imrect * v)
646 {
647         return (im_pf_apply(v, pvec2_y, NULL));
648 }
649 
650 static double   pmat2_xx(Mat2 * m)
651 {
652         return (mat2_xx(*m));
653 }
654 
655 Imrect         *im_mat2_xx(Imrect * m)
656 {
657         return (im_pf_apply(m, pmat2_xx, NULL));
658 }
659 
660 static double   pmat2_xy(Mat2 * m)
661 {
662         return (mat2_xy(*m));
663 }
664 
665 Imrect         *im_mat2_xy(Imrect * m)
666 {
667         return (im_pf_apply(m, pmat2_xy, NULL));
668 }
669 
670 static double   pmat2_yx(Mat2 * m)
671 {
672         return (mat2_yx(*m));
673 }
674 
675 Imrect         *im_mat2_yx(Imrect * m)
676 {
677         return (im_pf_apply(m, pmat2_yx, NULL));
678 }
679 
680 static double   pmat2_yy(Mat2 * m)
681 {
682         return (mat2_yy(*m));
683 }
684 
685 Imrect         *im_mat2_yy(Imrect * m)
686 {
687         return (im_pf_apply(m, pmat2_yy, NULL));
688 }
689 
690 /* make image of ptr's to vec3's coords from im1 im2 im3 */
691 /* UNUSED
692 static void    *pvec3_make(double x, double y, double z)
693 {
694         return (vec2_make(vec2(x, y)));
695 }
696 */
697 
698 Imrect         *im_vec3(Imrect * im1, Imrect * im2, Imrect * im3)
699 {
700         return (im_fffp_combine(im1, im2, im3, pvec2_make, NULL));
701 }
702 

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