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

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

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