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

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

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