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

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

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

  1 /**@(#)
  2 **/
  3 #include <math.h>
  4 #include <tina/sys.h>
  5 #include <tina/sysfuncs.h>
  6 #include <tina/math.h>
  7 #include <tina/mathfuncs.h>
  8 #include <tina/vision.h>
  9 #include <tina/visionfuncs.h>
 10 
 11 /** combining two images, general case **/
 12 
 13 Imrect *im_combine(Imrect * im1, Imrect * im2, void *(*func) (), void *data)
 14 {
 15     Imrect *im3;
 16     Imregion *roi;
 17     int    *row1, *row2, *row3;
 18     int     lx, ux, ly, uy;
 19     int     width, height;
 20     int     i, j;
 21 
 22     if (im1 == NULL || im2 == NULL)
 23         return (NULL);
 24 
 25     roi = roi_inter(im1->region, im2->region);
 26     if (roi == NULL)
 27         return (NULL);
 28     lx = roi->lx;
 29     ux = roi->ux;
 30     ly = roi->ly;
 31     uy = roi->uy;
 32 
 33     width = MIN(im1->width, im2->width);
 34     height = MIN(im1->height, im2->height);
 35 
 36     im3 = im_alloc(height, width, roi, ptr_v);
 37     row1 = tvector_alloc(lx, ux, int);
 38     row2 = tvector_alloc(lx, ux, int);
 39     row3 = tvector_alloc(lx, ux, int);
 40 
 41     for (i = ly; i < uy; ++i)
 42     {
 43         im_get_row(row1, im1, i, lx, ux);
 44         im_get_row(row2, im2, i, lx, ux);
 45         for (j = lx; j < ux; ++j)
 46             row3[j] = (int) (*func) (row1[j], row2[j], data);
 47         im_put_row(row3, im3, i, lx, ux);
 48     }
 49 
 50     tvector_free(row1, lx, void *);
 51     tvector_free(row2, lx, void *);
 52     tvector_free(row3, lx, void *);
 53     rfree((void *) roi);
 54     return (im3);
 55 }
 56 
 57 /** combining two floating point images, in place version, and special cases **/
 58 
 59 Imrect *imf_combine(Imrect * im1, Imrect * im2, double (*func) ( /* ??? */ ), void *data)
 60 {
 61     Imrect *im3;
 62     Imregion *roi;
 63     float  *row1, *row2, *row3;
 64     int     lx, ux, ly, uy;
 65     int     width, height;
 66     int     i, j;
 67 
 68     if (im1 == NULL || im2 == NULL)
 69         return (NULL);
 70 
 71     roi = roi_inter(im1->region, im2->region);
 72     if (roi == NULL)
 73         return (NULL);
 74     lx = roi->lx;
 75     ux = roi->ux;
 76     ly = roi->ly;
 77     uy = roi->uy;
 78 
 79     width = MIN(im1->width, im2->width);
 80     height = MIN(im1->height, im2->height);
 81 
 82     im3 = im_alloc(height, width, roi, float_v);
 83     row1 = fvector_alloc(lx, ux);
 84     row2 = fvector_alloc(lx, ux);
 85     row3 = fvector_alloc(lx, ux);
 86 
 87     for (i = ly; i < uy; ++i)
 88     {
 89         im_get_rowf(row1, im1, i, lx, ux);
 90         im_get_rowf(row2, im2, i, lx, ux);
 91         for (j = lx; j < ux; ++j)
 92             row3[j] = (float)(*func) (row1[j], row2[j], data);
 93         im_put_rowf(row3, im3, i, lx, ux);
 94     }
 95 
 96     fvector_free((void *) row1, lx);
 97     fvector_free((void *) row2, lx);
 98     fvector_free((void *) row3, lx);
 99     rfree((void *) roi);
100     return (im3);
101 }
102 
103 void    imf_combine_inplace(Imrect * im1, Imrect * im2, double (*func) ( /* ??? */ ), void *data)
104 {
105     Imregion *roi;
106     float  *row1, *row2, *row3;
107     int     lx, ux, ly, uy;
108     int     i, j;
109 
110     if (im1 == NULL || im2 == NULL)
111         return;
112 
113     roi = roi_inter(im1->region, im2->region);
114     rfree((void *) im1->region);
115     im1->region = roi;
116 
117     if (roi == NULL)
118         return;
119     lx = roi->lx;
120     ux = roi->ux;
121     ly = roi->ly;
122     uy = roi->uy;
123 
124     row1 = fvector_alloc(lx, ux);
125     row2 = fvector_alloc(lx, ux);
126     row3 = fvector_alloc(lx, ux);
127 
128     for (i = ly; i < uy; ++i)
129     {
130         im_get_rowf(row1, im1, i, lx, ux);
131         im_get_rowf(row2, im2, i, lx, ux);
132         for (j = lx; j < ux; ++j)
133             row3[j] = (float)(*func) (row1[j], row2[j], data);
134         im_put_rowf(row3, im1, i, lx, ux);
135     }
136 
137     fvector_free((void *) row1, lx);
138     fvector_free((void *) row2, lx);
139     fvector_free((void *) row3, lx);
140     rfree((void *) roi);
141 }
142 
143 Imrect *imi_sum(Imrect * im1, Imrect * im2)
144 {
145     Imrect *im3;
146     Imregion *roi;
147     int    *row1, *row2, *row3;
148     int     lx, ux, ly, uy;
149     int     width, height;
150     int     i, j;
151 
152     if (im1 == NULL || im2 == NULL)
153         return (NULL);
154 
155     roi = roi_inter(im1->region, im2->region);
156     if (roi == NULL)
157         return (NULL);
158     lx = roi->lx;
159     ux = roi->ux;
160     ly = roi->ly;
161     uy = roi->uy;
162 
163     width = MIN(im1->width, im2->width);
164     height = MIN(im1->height, im2->height);
165 
166     im3 = im_alloc(height, width, roi, int_v);
167     row1 = ivector_alloc(lx, ux);
168     row2 = ivector_alloc(lx, ux);
169     row3 = ivector_alloc(lx, ux);
170 
171     for (i = ly; i < uy; ++i)
172     {
173         im_get_row(row1, im1, i, lx, ux);
174         im_get_row(row2, im2, i, lx, ux);
175         for (j = lx; j < ux; ++j)
176             row3[j] = row1[j] + row2[j];
177         im_put_row(row3, im3, i, lx, ux);
178     }
179 
180     ivector_free((void *) row1, lx);
181     ivector_free((void *) row2, lx);
182     ivector_free((void *) row3, lx);
183     rfree((void *) roi);
184     return (im3);
185 }
186 
187 Imrect *imf_sum(Imrect * im1, Imrect * im2)
188 {
189     Imrect *im3;
190     Imregion *roi;
191     float  *row1, *row2, *row3;
192     int     lx, ux, ly, uy;
193     int     width, height;
194     int     i, j;
195 
196     if (im1 == NULL || im2 == NULL)
197         return (NULL);
198 
199     roi = roi_inter(im1->region, im2->region);
200     if (roi == NULL)
201         return (NULL);
202     lx = roi->lx;
203     ux = roi->ux;
204     ly = roi->ly;
205     uy = roi->uy;
206 
207     width = MIN(im1->width, im2->width);
208     height = MIN(im1->height, im2->height);
209 
210     im3 = im_alloc(height, width, roi, float_v);
211     row1 = fvector_alloc(lx, ux);
212     row2 = fvector_alloc(lx, ux);
213     row3 = fvector_alloc(lx, ux);
214 
215     for (i = ly; i < uy; ++i)
216     {
217         im_get_rowf(row1, im1, i, lx, ux);
218         im_get_rowf(row2, im2, i, lx, ux);
219         for (j = lx; j < ux; ++j)
220             row3[j] = row1[j] + row2[j];
221         im_put_rowf(row3, im3, i, lx, ux);
222     }
223 
224     fvector_free((void *) row1, lx);
225     fvector_free((void *) row2, lx);
226     fvector_free((void *) row3, lx);
227     rfree((void *) roi);
228     return (im3);
229 }
230 
231 Imrect *imz_sum(Imrect * im1, Imrect * im2)
232 {
233     Imrect *im3;
234     Imregion *roi;
235     Complex *row1;
236     Complex *row2;
237     Complex *row3;
238     int     lx, ux, ly, uy;
239     int     width, height;
240     int     i, j;
241 
242     if (im1 == NULL || im2 == NULL)
243         return (NULL);
244 
245     roi = roi_inter(im1->region, im2->region);
246     if (roi == NULL)
247         return (NULL);
248     lx = roi->lx;
249     ux = roi->ux;
250     ly = roi->ly;
251     uy = roi->uy;
252 
253     width = MIN(im1->width, im2->width);
254     height = MIN(im1->height, im2->height);
255 
256     im3 = im_alloc(height, width, roi, complex_v);
257     row1 = zvector_alloc(lx, ux);
258     row2 = zvector_alloc(lx, ux);
259     row3 = zvector_alloc(lx, ux);
260 
261     for (i = ly; i < uy; ++i)
262     {
263         im_get_rowz(row1, im1, i, lx, ux);
264         im_get_rowz(row2, im2, i, lx, ux);
265         for (j = lx; j < ux; ++j)
266             row3[j] = cmplx_sum(row1[j], row2[j]);
267         im_put_rowz(row3, im3, i, lx, ux);
268     }
269 
270     zvector_free((void *) row1, lx);
271     zvector_free((void *) row2, lx);
272     zvector_free((void *) row3, lx);
273     rfree((void *) roi);
274     return (im3);
275 }
276 
277 Imrect *im_sum(Imrect * im1, Imrect * im2)
278 {
279     if (im1 == NULL || im2 == NULL)
280         return (NULL);
281     switch (im_sup_vtype(im1->vtype, im2->vtype))
282     {
283     case uchar_v:
284     case char_v:
285     case ushort_v:
286     case short_v:
287     case int_v:
288         return (imi_sum(im1, im2));
289     case float_v:
290         return (imf_sum(im1, im2));
291     case complex_v:
292         return (imz_sum(im1, im2));
293     default:
294         return (NULL);
295     }
296     return (NULL);
297 }
298 
299 Imrect *imi_diff(Imrect * im1, Imrect * im2)
300 {
301     Imrect *im3;
302     Imregion *roi;
303     int    *row1, *row2, *row3;
304     int     lx, ux, ly, uy;
305     int     width, height;
306     int     i, j;
307 
308     if (im1 == NULL || im2 == NULL)
309         return (NULL);
310 
311     roi = roi_inter(im1->region, im2->region);
312     if (roi == NULL)
313         return (NULL);
314     lx = roi->lx;
315     ux = roi->ux;
316     ly = roi->ly;
317     uy = roi->uy;
318 
319     width = MIN(im1->width, im2->width);
320     height = MIN(im1->height, im2->height);
321 
322     im3 = im_alloc(height, width, roi, int_v);
323     row1 = ivector_alloc(lx, ux);
324     row2 = ivector_alloc(lx, ux);
325     row3 = ivector_alloc(lx, ux);
326 
327     for (i = ly; i < uy; ++i)
328     {
329         im_get_row(row1, im1, i, lx, ux);
330         im_get_row(row2, im2, i, lx, ux);
331         for (j = lx; j < ux; ++j)
332             row3[j] = row1[j] - row2[j];
333         im_put_row(row3, im3, i, lx, ux);
334     }
335 
336     ivector_free((void *) row1, lx);
337     ivector_free((void *) row2, lx);
338     ivector_free((void *) row3, lx);
339     rfree((void *) roi);
340     return (im3);
341 }
342 
343 Imrect *imf_diff(Imrect * im1, Imrect * im2)
344 {
345     Imrect *im3;
346     Imregion *roi;
347     float  *row1, *row2, *row3;
348     int     lx, ux, ly, uy;
349     int     width, height;
350     int     i, j;
351 
352     if (im1 == NULL || im2 == NULL)
353         return (NULL);
354 
355     roi = roi_inter(im1->region, im2->region);
356     if (roi == NULL)
357         return (NULL);
358     lx = roi->lx;
359     ux = roi->ux;
360     ly = roi->ly;
361     uy = roi->uy;
362 
363     width = MIN(im1->width, im2->width);
364     height = MIN(im1->height, im2->height);
365 
366     im3 = im_alloc(height, width, roi, float_v);
367     row1 = fvector_alloc(lx, ux);
368     row2 = fvector_alloc(lx, ux);
369     row3 = fvector_alloc(lx, ux);
370 
371     for (i = ly; i < uy; ++i)
372     {
373         im_get_rowf(row1, im1, i, lx, ux);
374         im_get_rowf(row2, im2, i, lx, ux);
375         for (j = lx; j < ux; ++j)
376             row3[j] = row1[j] - row2[j];
377         im_put_rowf(row3, im3, i, lx, ux);
378     }
379 
380     fvector_free((void *) row1, lx);
381     fvector_free((void *) row2, lx);
382     fvector_free((void *) row3, lx);
383     rfree((void *) roi);
384     return (im3);
385 }
386 
387 Imrect *imz_diff(Imrect * im1, Imrect * im2)
388 {
389     Imrect *im3;
390     Imregion *roi;
391     Complex *row1;
392     Complex *row2;
393     Complex *row3;
394     int     lx, ux, ly, uy;
395     int     width, height;
396     int     i, j;
397 
398     if (im1 == NULL || im2 == NULL)
399         return (NULL);
400 
401     roi = roi_inter(im1->region, im2->region);
402     if (roi == NULL)
403         return (NULL);
404     lx = roi->lx;
405     ux = roi->ux;
406     ly = roi->ly;
407     uy = roi->uy;
408 
409     width = MIN(im1->width, im2->width);
410     height = MIN(im1->height, im2->height);
411 
412     im3 = im_alloc(height, width, roi, complex_v);
413     row1 = zvector_alloc(lx, ux);
414     row2 = zvector_alloc(lx, ux);
415     row3 = zvector_alloc(lx, ux);
416 
417     for (i = ly; i < uy; ++i)
418     {
419         im_get_rowz(row1, im1, i, lx, ux);
420         im_get_rowz(row2, im2, i, lx, ux);
421         for (j = lx; j < ux; ++j)
422             row3[j] = cmplx_diff(row1[j], row2[j]);
423         im_put_rowz(row3, im3, i, lx, ux);
424     }
425 
426     zvector_free((void *) row1, lx);
427     zvector_free((void *) row2, lx);
428     zvector_free((void *) row3, lx);
429     rfree((void *) roi);
430     return (im3);
431 }
432 
433 Imrect *im_diff(Imrect * im1, Imrect * im2)
434 {
435     if (im1 == NULL || im2 == NULL)
436         return (NULL);
437     switch (im_sup_vtype(im1->vtype, im2->vtype))
438     {
439     case uchar_v:
440     case char_v:
441     case short_v:
442     case ushort_v:
443     case int_v:
444         return(imi_diff(im1, im2));
445     case float_v:
446         return(imf_diff(im1, im2));
447     case complex_v:
448         return(imz_diff(im1, im2));
449     default:
450         return (NULL);
451     }
452     return (NULL);
453 }
454 
455 Imrect *imf_wsum(double a, double b, Imrect * im1, Imrect * im2)
456 {
457     Imrect *im3;
458     Imregion *roi;
459     float  *row1, *row2, *row3;
460     int     lx, ux, ly, uy;
461     int     width, height;
462     int     i, j;
463 
464     if (im1 == NULL || im2 == NULL)
465         return (NULL);
466 
467     roi = roi_inter(im1->region, im2->region);
468     if (roi == NULL)
469         return (NULL);
470     lx = roi->lx;
471     ux = roi->ux;
472     ly = roi->ly;
473     uy = roi->uy;
474 
475     width = MIN(im1->width, im2->width);
476     height = MIN(im1->height, im2->height);
477 
478     im3 = im_alloc(height, width, roi, float_v);
479     row1 = fvector_alloc(lx, ux);
480     row2 = fvector_alloc(lx, ux);
481     row3 = fvector_alloc(lx, ux);
482 
483     for (i = ly; i < uy; ++i)
484     {
485         im_get_rowf(row1, im1, i, lx, ux);
486         im_get_rowf(row2, im2, i, lx, ux);
487         for (j = lx; j < ux; ++j)
488             row3[j] = (float) (a * row1[j] + b * row2[j]);
489         im_put_rowf(row3, im3, i, lx, ux);
490     }
491 
492     fvector_free((void *) row1, lx);
493     fvector_free((void *) row2, lx);
494     fvector_free((void *) row3, lx);
495     rfree((void *) roi);
496     return (im3);
497 }
498 
499 Imrect *imf_sumsq(Imrect * im1, Imrect * im2)
500 {
501     Imrect *im3;
502     Imregion *roi;
503     float  *row1, *row2, *row3;
504     int     lx, ux, ly, uy;
505     int     width, height;
506     int     i, j;
507 
508     if (im1 == NULL || im2 == NULL)
509         return (NULL);
510 
511     roi = roi_inter(im1->region, im2->region);
512     if (roi == NULL)
513         return (NULL);
514     lx = roi->lx;
515     ux = roi->ux;
516     ly = roi->ly;
517     uy = roi->uy;
518 
519     width = MIN(im1->width, im2->width);
520     height = MIN(im1->height, im2->height);
521 
522     im3 = im_alloc(height, width, roi, float_v);
523     row1 = fvector_alloc(lx, ux);
524     row2 = fvector_alloc(lx, ux);
525     row3 = fvector_alloc(lx, ux);
526 
527     for (i = ly; i < uy; ++i)
528     {
529         im_get_rowf(row1, im1, i, lx, ux);
530         im_get_rowf(row2, im2, i, lx, ux);
531         for (j = lx; j < ux; ++j)
532             row3[j] = row1[j] * row1[j] + row2[j] * row2[j];
533         im_put_rowf(row3, im3, i, lx, ux);
534     }
535 
536     fvector_free((void *) row1, lx);
537     fvector_free((void *) row2, lx);
538     fvector_free((void *) row3, lx);
539     rfree((void *) roi);
540     return (im3);
541 }
542 
543 Imrect *imi_maxsel(Imrect * im1, Imrect * im2)
544 {
545     Imrect *im3;
546     Imregion *roi;
547     int    *row1, *row2, *row3;
548     int     lx, ux, ly, uy;
549     int     width, height;
550     int     i, j;
551 
552     if (im1 == NULL || im2 == NULL)
553         return (NULL);
554 
555     roi = roi_inter(im1->region, im2->region);
556     if (roi == NULL)
557         return (NULL);
558     lx = roi->lx;
559     ux = roi->ux;
560     ly = roi->ly;
561     uy = roi->uy;
562 
563     width = MIN(im1->width, im2->width);
564     height = MIN(im1->height, im2->height);
565 
566     im3 = im_alloc(height, width, roi, int_v);
567     row1 = ivector_alloc(lx, ux);
568     row2 = ivector_alloc(lx, ux);
569     row3 = ivector_alloc(lx, ux);
570 
571     for (i = ly; i < uy; ++i)
572     {
573         im_get_row(row1, im1, i, lx, ux);
574         im_get_row(row2, im2, i, lx, ux);
575         for (j = lx; j < ux; ++j)
576             row3[j] = MAX(row1[j] , row2[j]);
577         im_put_row(row3, im3, i, lx, ux);
578     }
579 
580     ivector_free((void *) row1, lx);
581     ivector_free((void *) row2, lx);
582     ivector_free((void *) row3, lx);
583     rfree((void *) roi);
584     return (im3);
585 }
586 
587 Imrect *imf_maxsel(Imrect * im1, Imrect * im2)
588 {
589     Imrect *im3;
590     Imregion *roi;
591     float  *row1, *row2, *row3;
592     int     lx, ux, ly, uy;
593     int     width, height;
594     int     i, j;
595 
596     if (im1 == NULL || im2 == NULL)
597         return (NULL);
598 
599     roi = roi_inter(im1->region, im2->region);
600     if (roi == NULL)
601         return (NULL);
602     lx = roi->lx;
603     ux = roi->ux;
604     ly = roi->ly;
605     uy = roi->uy;
606 
607     width = MIN(im1->width, im2->width);
608     height = MIN(im1->height, im2->height);
609 
610     im3 = im_alloc(height, width, roi, float_v);
611     row1 = fvector_alloc(lx, ux);
612     row2 = fvector_alloc(lx, ux);
613     row3 = fvector_alloc(lx, ux);
614 
615     for (i = ly; i < uy; ++i)
616     {
617         im_get_rowf(row1, im1, i, lx, ux);
618         im_get_rowf(row2, im2, i, lx, ux);
619         for (j = lx; j < ux; ++j)
620             row3[j] = MAX(row1[j] , row2[j]);
621         im_put_rowf(row3, im3, i, lx, ux);
622     }
623 
624     fvector_free((void *) row1, lx);
625     fvector_free((void *) row2, lx);
626     fvector_free((void *) row3, lx);
627     rfree((void *) roi);
628     return (im3);
629 }
630 
631 Imrect *imz_maxsel(Imrect * im1, Imrect * im2)
632 {
633     Imrect *im3;
634     Imregion *roi;
635     Complex *row1;
636     Complex *row2;
637     Complex *row3;
638     int     lx, ux, ly, uy;
639     int     width, height;
640     int     i, j;
641 
642     if (im1 == NULL || im2 == NULL)
643         return (NULL);
644 
645     roi = roi_inter(im1->region, im2->region);
646     if (roi == NULL)
647         return (NULL);
648     lx = roi->lx;
649     ux = roi->ux;
650     ly = roi->ly;
651     uy = roi->uy;
652 
653     width = MIN(im1->width, im2->width);
654     height = MIN(im1->height, im2->height);
655 
656     im3 = im_alloc(height, width, roi, complex_v);
657     row1 = zvector_alloc(lx, ux);
658     row2 = zvector_alloc(lx, ux);
659     row3 = zvector_alloc(lx, ux);
660 
661     for (i = ly; i < uy; ++i)
662     {
663         im_get_rowz(row1, im1, i, lx, ux);
664         im_get_rowz(row2, im2, i, lx, ux);
665         for (j = lx; j < ux; ++j)
666         {
667             if (cmplx_sqrmod(row1[j])>cmplx_sqrmod(row2[j]))
668                row3[j] = row1[j];
669             else
670                row3[j] = row2[j];
671         }
672         im_put_rowz(row3, im3, i, lx, ux);
673     }
674 
675     zvector_free((void *) row1, lx);
676     zvector_free((void *) row2, lx);
677     zvector_free((void *) row3, lx);
678     rfree((void *) roi);
679     return (im3);
680 }
681 
682 Imrect *im_maxsel(Imrect * im1, Imrect * im2)
683 {
684     if (im1 == NULL || im2 == NULL)
685         return (NULL);
686     switch (im_sup_vtype(im1->vtype, im2->vtype))
687     {
688     case uchar_v:
689     case char_v:
690     case short_v:
691     case ushort_v:
692     case int_v:
693         return(imi_maxsel(im1, im2));
694     case float_v:
695         return(imf_maxsel(im1, im2));
696     case complex_v:
697         return(imz_maxsel(im1, im2));
698     default:
699         return (NULL);
700     }
701     return (NULL);
702 }
703 
704 Imrect *imi_prod(Imrect * im1, Imrect * im2)
705 {
706     Imrect *im3;
707     Imregion *roi;
708     int    *row1, *row2, *row3;
709     int     lx, ux, ly, uy;
710     int     width, height;
711     int     i, j;
712 
713     if (im1 == NULL || im2 == NULL)
714         return (NULL);
715 
716     roi = roi_inter(im1->region, im2->region);
717     if (roi == NULL)
718         return (NULL);
719     lx = roi->lx;
720     ux = roi->ux;
721     ly = roi->ly;
722     uy = roi->uy;
723 
724     width = MIN(im1->width, im2->width);
725     height = MIN(im1->height, im2->height);
726 
727     im3 = im_alloc(height, width, roi, int_v);
728     row1 = ivector_alloc(lx, ux);
729     row2 = ivector_alloc(lx, ux);
730     row3 = ivector_alloc(lx, ux);
731 
732     for (i = ly; i < uy; ++i)
733     {
734         im_get_row(row1, im1, i, lx, ux);
735         im_get_row(row2, im2, i, lx, ux);
736         for (j = lx; j < ux; ++j)
737             row3[j] = row1[j] * row2[j];
738         im_put_row(row3, im3, i, lx, ux);
739     }
740 
741     ivector_free((void *) row1, lx);
742     ivector_free((void *) row2, lx);
743     ivector_free((void *) row3, lx);
744     rfree((void *) roi);
745     return (im3);
746 }
747 
748 Imrect *imf_prod(Imrect * im1, Imrect * im2)
749 {
750     Imrect *im3;
751     Imregion *roi;
752     float  *row1, *row2, *row3;
753     int     lx, ux, ly, uy;
754     int     width, height;
755     int     i, j;
756 
757     if (im1 == NULL || im2 == NULL)
758         return (NULL);
759 
760     roi = roi_inter(im1->region, im2->region);
761     if (roi == NULL)
762         return (NULL);
763     lx = roi->lx;
764     ux = roi->ux;
765     ly = roi->ly;
766     uy = roi->uy;
767 
768     width = MIN(im1->width, im2->width);
769     height = MIN(im1->height, im2->height);
770 
771     im3 = im_alloc(height, width, roi, float_v);
772     row1 = fvector_alloc(lx, ux);
773     row2 = fvector_alloc(lx, ux);
774     row3 = fvector_alloc(lx, ux);
775 
776     for (i = ly; i < uy; ++i)
777     {
778         im_get_rowf(row1, im1, i, lx, ux);
779         im_get_rowf(row2, im2, i, lx, ux);
780         for (j = lx; j < ux; ++j)
781             row3[j] = row1[j] * row2[j];
782         im_put_rowf(row3, im3, i, lx, ux);
783     }
784 
785     fvector_free((void *) row1, lx);
786     fvector_free((void *) row2, lx);
787     fvector_free((void *) row3, lx);
788     rfree((void *) roi);
789     return (im3);
790 }
791 
792 Imrect *imz_prod(Imrect * im1, Imrect * im2)
793 {
794     Imrect *im3;
795     Imregion *roi;
796     Complex *row1;
797     Complex *row2;
798     Complex *row3;
799     int     lx, ux, ly, uy;
800     int     width, height;
801     int     i, j;
802 
803     if (im1 == NULL || im2 == NULL)
804         return (NULL);
805 
806     roi = roi_inter(im1->region, im2->region);
807     if (roi == NULL)
808         return (NULL);
809     lx = roi->lx;
810     ux = roi->ux;
811     ly = roi->ly;
812     uy = roi->uy;
813 
814     width = MIN(im1->width, im2->width);
815     height = MIN(im1->height, im2->height);
816 
817     im3 = im_alloc(height, width, roi, complex_v);
818     row1 = zvector_alloc(lx, ux);
819     row2 = zvector_alloc(lx, ux);
820     row3 = zvector_alloc(lx, ux);
821 
822     for (i = ly; i < uy; ++i)
823     {
824         im_get_rowz(row1, im1, i, lx, ux);
825         im_get_rowz(row2, im2, i, lx, ux);
826         for (j = lx; j < ux; ++j)
827             row3[j] = cmplx_prod(row1[j], row2[j]);
828         im_put_rowz(row3, im3, i, lx, ux);
829     }
830 
831     zvector_free((void *) row1, lx);
832     zvector_free((void *) row2, lx);
833     zvector_free((void *) row3, lx);
834     rfree((void *) roi);
835     return (im3);
836 }
837 
838 Imrect *im_prod(Imrect * im1, Imrect * im2)
839 {
840     if (im1 == NULL || im2 == NULL)
841         return (NULL);
842     switch (im_sup_vtype(im1->vtype, im2->vtype))
843     {
844     case uchar_v:
845     case char_v:
846     case short_v:
847     case ushort_v:
848     case int_v:
849         return(imi_prod(im1, im2));
850     case float_v:
851         return(imf_prod(im1, im2));
852     case complex_v:
853         return(imz_prod(im1, im2));
854     default:
855         return (NULL);
856     }
857     return (NULL);
858 }
859 
860 Imrect *imf_div(Imrect * im1, Imrect * im2, double thresh, double val)
861 {
862     Imrect *im3;
863     Imregion *roi;
864     float  *row1, *row2, *row3;
865     int     lx, ux, ly, uy;
866     int     width, height;
867     int     i, j;
868 
869     if (im1 == NULL || im2 == NULL)
870         return (NULL);
871 
872     roi = roi_inter(im1->region, im2->region);
873     if (roi == NULL)
874         return (NULL);
875     lx = roi->lx;
876     ux = roi->ux;
877     ly = roi->ly;
878     uy = roi->uy;
879 
880     width = MIN(im1->width, im2->width);
881     height = MIN(im1->height, im2->height);
882 
883     im3 = im_alloc(height, width, roi, float_v);
884     row1 = fvector_alloc(lx, ux);
885     row2 = fvector_alloc(lx, ux);
886     row3 = fvector_alloc(lx, ux);
887 
888     for (i = ly; i < uy; ++i)
889     {
890         im_get_rowf(row1, im1, i, lx, ux);
891         im_get_rowf(row2, im2, i, lx, ux);
892         for (j = lx; j < ux; ++j)
893         {
894             if (row2[j] * row2[j] <= thresh*thresh)
895                 {
896                     if (row2[j]>=0.0)
897                         row3[j] = (float) (row1[j]*2.0/(row2[j]+val));
898                     else
899                         row3[j] = (float) (row1[j]*2.0/(row2[j]-val));
900                 }
901             else
902                 row3[j] = row1[j] / row2[j];
903         }
904         im_put_rowf(row3, im3, i, lx, ux);
905 
906     }
907 
908     fvector_free((void *) row1, lx);
909     fvector_free((void *) row2, lx);
910     fvector_free((void *) row3, lx);
911     rfree((void *) roi);
912     return (im3);
913 }
914 
915 Imrect *imz_div(Imrect * im1, Imrect * im2, double thresh, Complex val)
916 {
917     Imrect *im3;
918     Imregion *roi;
919     Complex *row1;
920     Complex *row2;
921     Complex *row3;
922     int     lx, ux, ly, uy;
923     int     width, height;
924     int     i, j;
925 
926     if (im1 == NULL || im2 == NULL)
927         return (NULL);
928 
929     roi = roi_inter(im1->region, im2->region);
930     if (roi == NULL)
931         return (NULL);
932     lx = roi->lx;
933     ux = roi->ux;
934     ly = roi->ly;
935     uy = roi->uy;
936 
937     width = MIN(im1->width, im2->width);
938     height = MIN(im1->height, im2->height);
939 
940     im3 = im_alloc(height, width, roi, complex_v);
941     row1 = zvector_alloc(lx, ux);
942     row2 = zvector_alloc(lx, ux);
943     row3 = zvector_alloc(lx, ux);
944 
945     for (i = ly; i < uy; ++i)
946     {
947         im_get_rowz(row1, im1, i, lx, ux);
948         im_get_rowz(row2, im2, i, lx, ux);
949         for (j = lx; j < ux; ++j)
950             if (cmplx_sqrmod(row2[j]) <= thresh*thresh)
951                 if (row2[j].x>0.0)
952                    row3[j] = cmplx_div(row1[j],
953                              cmplx_times(0.5,cmplx_sum(val,row2[j])));
954                 else
955                    row3[j] = cmplx_div(row1[j],
956                              cmplx_times(0.5,cmplx_diff(row2[j],val)));
957             else
958                 row3[j] = cmplx_div(row1[j], row2[j]);
959         im_put_rowz(row3, im3, i, lx, ux);
960     }
961 
962     zvector_free((void *) row1, lx);
963     zvector_free((void *) row2, lx);
964     zvector_free((void *) row3, lx);
965     rfree((void *) roi);
966     return (im3);
967 }
968 
969 Imrect *im_div(Imrect * im1, Imrect * im2, double thresh, double val)
970 {
971     if (im1 == NULL || im2 == NULL)
972         return (NULL);
973     switch (im_sup_vtype(im1->vtype, im2->vtype))
974     {
975     case uchar_v:
976     case char_v:
977     case short_v:
978     case ushort_v:
979     case int_v:
980     case float_v:
981         return(imf_div(im1, im2, thresh, val));
982     case complex_v:
983         return(imz_div(im1, im2, thresh, cmplx(val, 0.0)));
984     default:
985         return (NULL);
986     }
987     return (NULL);
988 }
989 

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