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

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

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

  1 /**@(#)
  2 **/
  3 /* smooth_1d.c
  4  * 
  5  * one dimensional smoothing function
  6  * 
  7  * smoothing is a special form of convolution in which edge effects can be
  8  * approximated using sub-total ratios.
  9  * 
 10  * functions accept only  floating point covolution profiles
 11  * 
 12  */
 13 
 14 #include <math.h>
 15 #include <tina/sys.h>
 16 #include <tina/sysfuncs.h>
 17 #include <tina/math.h>
 18 #include <tina/vision.h>
 19 
 20 static Prof1 *prof1_subtot_ratio(Prof1 * profile)
 21 {
 22     Prof1  *subtot;
 23     Prof1  *prof1_alloc();
 24     int     i, n1, n2;
 25     float   tot = (float)0.0;
 26 
 27     n1 = profile->n1;
 28     n2 = profile->n2;
 29     subtot = prof1_alloc(n1, n2, float_v);
 30 
 31     for (i = n1; i < n2; ++i)
 32     {
 33         subtot->el.float_v[i] = tot;
 34         tot += profile->el.float_v[i];
 35     }
 36     for (i = n1; i < n2; ++i)
 37         subtot->el.float_v[i] /= tot;
 38     return (subtot);
 39 }
 40 
 41 void    smooth_1d(float *line, int n1, int n2, Prof1 * profile) /* use profile forwards */
 42 
 43 
 44 
 45 {
 46     float   sum;
 47     int     i, j;
 48     int     p1, p2, firstfull, lastfull;
 49     float  *prof, *subtot;
 50     Prof1  *subtot_p;
 51     void    prof1_free();
 52     float  *temp;
 53 
 54     if (profile == NULL || profile->vtype != float_v)
 55         return;
 56 
 57     p1 = profile->n1;
 58     p2 = profile->n2;
 59     firstfull = MAX(n1 - p1, n1);
 60     lastfull = MIN(n2 - p2, n2);
 61     prof = profile->el.float_v;
 62     subtot_p = prof1_subtot_ratio(profile);
 63     subtot = subtot_p->el.float_v;
 64     temp = fvector_alloc(n1, n2);
 65 
 66     for (i = n1; i < firstfull; ++i)
 67     {
 68         for (sum = (float)0.0, j = n1 - i; j < p2; ++j)
 69             sum += prof[j] * line[i + j];
 70         temp[i] = (float) (sum / (1.0 - subtot[n1 - i]));
 71     }
 72 
 73     for (; i <= lastfull; ++i)  /* most work */
 74     {
 75         for (sum = (float)0.0, j = p1; j < p2; ++j)
 76             sum += (float) (prof[j] * line[i + j]);
 77         temp[i] = sum;
 78     }
 79 
 80     for (; i < n2; ++i)
 81     {
 82         for (sum = (float)0.0, j = p1; j < n2 - i; ++j)
 83             sum += prof[j] * line[i + j];
 84         temp[i] = sum / subtot[n2 - i];
 85     }
 86 
 87     for (i = n1; i < n2; ++i)
 88         line[i] = temp[i];
 89 
 90     fvector_free((void *) temp, n1);
 91     prof1_free(subtot_p);
 92 }
 93 
 94 void    smooth_1d_sym(float *line, int n1, int n2, Prof1 * profile)     /* use profile
 95                                                                          * symetrically */
 96 
 97 
 98 
 99 {
100     float   sum;
101     int     i, j;
102     int     p1, p2, firstfull, lastfull;
103     int     offset, pm, odd;
104     float  *prof, *subtot;
105     Prof1  *subtot_p;
106     void    prof1_free();
107     float  *temp;
108 
109     if (profile == NULL || profile->vtype != float_v)
110         return;
111 
112     p1 = profile->n1;
113     p2 = profile->n2;
114     firstfull = MAX(n1 - p1, n1);
115     lastfull = MIN(n2 - p2, n2);
116     prof = profile->el.float_v;
117     subtot_p = prof1_subtot_ratio(profile);
118     subtot = subtot_p->el.float_v;
119     temp = fvector_alloc(n1, n2);
120 
121     odd = (p2 - p1) % 2;        /* is the profile odd or even */
122     pm = p1 + (p2 - p1) / 2;    /* mid point of profile */
123     offset = p1 + p2 - 1;
124 
125     for (i = n1; i < firstfull; ++i)
126     {
127         for (sum = (float)0.0, j = n1 - i; j < p2; ++j)
128             sum += (float) (prof[j] * line[i + j]);
129         temp[i] = (float) (sum / (1.0 - subtot[n1 - i]));
130     }
131 
132     for (; i <= lastfull; ++i)  /* most work so exploit symetry */
133     {
134         sum = (odd) ? prof[pm] * line[i + pm] : 0;
135         for (j = p1; j < pm; ++j)
136             sum += prof[j] * (line[i + j] + line[i + offset - j]);
137         temp[i] = sum;
138     }
139 
140     for (; i < n2; ++i)
141     {
142         for (sum = (float)0.0, j = p1; j < n2 - i; ++j)
143             sum += prof[j] * line[i + j];
144         temp[i] = sum / subtot[n2 - i];
145     }
146 
147     for (i = n1; i < n2; ++i)
148         line[i] = temp[i];
149 
150     fvector_free((void *) temp, n1);
151     prof1_free(subtot_p);
152 }
153 
154 void    conv_1d(float *line, int n1, int n2, Prof1 * profile)   /* use profile backwards */
155 
156 
157 
158 {
159     float   sum;
160     int     i, j;
161     int     p1, p2;
162     int     lower, upper;
163     float  *prof;
164     float  *temp;
165 
166     if (profile == NULL || profile->vtype != float_v)
167         return;
168 
169     p1 = profile->n1;
170     p2 = profile->n2;
171     lower = MAX(n1 - p2 + 1, 0);
172     upper = MIN(n2 - p1, n2);
173     prof = profile->el.float_v;
174     temp = fvector_alloc(n1, n2);
175 
176     for (i = n1; i < lower; ++i)
177         temp[i] = (float)0.0;
178 
179     for (; i <= upper; ++i)     /* most work */
180     {
181         for (sum = (float)0.0, j = p1; j < p2; ++j)
182             sum += prof[j] * line[i - j];
183         temp[i] = sum;
184     }
185 
186     for (; i < n2; ++i)
187         temp[i] = (float)0.0;
188 
189     for (i = n1; i < n2; ++i)
190         line[i] = temp[i];
191 
192     fvector_free((void *) temp, n1);
193 }
194 

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