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

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

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

  1 /**@(#)
  2 **/
  3 #include <math.h>
  4 #include <tina/sys.h>
  5 #include <tina/math.h>
  6 #include <tina/vision.h>
  7 
  8 static double prof_intg(double x, double s2)
  9 {
 10     float   i, sum = (float) 0.0;
 11     short   tot = 0;
 12 
 13     for (i = (float)(x - 0.5); i <= (float)(x + 0.5); i += (float)0.1)
 14     {
 15         sum += (float)exp(-i * i / s2);
 16         tot++;
 17     }
 18     return (sum / tot);
 19 }
 20 
 21 static double prof_g(double x, double s2)
 22 {
 23     return (exp(-x * x / s2));
 24 }
 25 
 26 Prof1  *prof_gauss_simple(double sig, double precision)
 27 {
 28     float   sig2;
 29     float  *profile;
 30     Prof1  *prof;
 31     Prof1  *prof1_alloc();
 32     int     n, i;
 33 
 34     sig2 = (float)(2.0 * sig * sig);
 35 
 36     for (n = 1;; ++n)
 37         if (prof_g((double) n, sig2) < precision)
 38             break;
 39 
 40     prof = prof1_alloc(-n + 1, n, float_v);
 41     profile = prof->el.float_v;
 42 
 43     for (i = 0; i < n; ++i)
 44         profile[-i] = profile[i] = (float)prof_intg((float) i, sig2);
 45     return (prof);
 46 }
 47 
 48 Prof1  *prof_gauss(double sig, double precision)
 49 
 50 /* as a ratio of max value */
 51 {
 52     float   sig2, total = (float) 0.0;
 53     float  *profile;
 54     Prof1  *prof;
 55     Prof1  *prof1_alloc();
 56     int     n, i;
 57 
 58     sig2 = (float)(2.0 * sig * sig);
 59 
 60     for (n = 1;; ++n)
 61         if (prof_g((double) n, sig2) < precision)
 62             break;
 63     if (n>20)
 64     {
 65         format("gaussian profile limited to length 20 \n");
 66         n = 20; 
 67     }
 68 
 69     prof = prof1_alloc(-n + 1, n, float_v);
 70     profile = prof->el.float_v;
 71 
 72     for (i = 0; i < n; ++i)
 73         total += profile[-i] = profile[i] = (float)prof_intg((float) i, sig2);
 74 
 75     total *= 2;
 76     total -= profile[0];
 77 
 78     for (i = -n + 1; i < n; ++i)
 79         profile[-i] /= total;
 80 
 81     return (prof);
 82 }
 83 

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