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

Linux Cross Reference
Tina4/src/vision/conic/con_fltr.c

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

  1 /**@(#)Avoids too many parameters in conic_filter & calling functions
  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 
 12 
 13 static double (*filter) () = NULL;      /* Filter to be applied */
 14 
 15 double  (*conic_filter_get()) ( void /* ??? */ )
 16 {
 17     return (filter);
 18 }
 19 
 20 void    conic_filter_set(double (*newfilter) ( /* ??? */ ))
 21 {
 22     filter = newfilter;
 23 }
 24 
 25 /**
 26 sampling frequency on fitted curve
 27 **/
 28 
 29 static int sample = 4;
 30 
 31 int     conic_sample_get(void)
 32 {
 33     return (sample);
 34 }
 35 
 36 void    conic_sample_set(int newsample)
 37 {
 38     sample = newsample;
 39 }
 40 
 41 /**
 42 nominal variance of fitted points
 43 **/
 44 
 45 static double var = 1.0;
 46 
 47 double  conic_var_get(void)
 48 {
 49     return (var);
 50 }
 51 
 52 void    conic_var_set(double newvar)
 53 {
 54     var = newvar;
 55 }
 56 
 57 /**
 58 number of filter iterations
 59 **/
 60 
 61 static int iter = 3;
 62 
 63 int     conic_iter_get(void)
 64 {
 65     return (iter);
 66 }
 67 
 68 void    conic_iter_set(int newiter)
 69 {
 70     iter = newiter;
 71 }
 72 
 73 /* Apply chosen filter to point string */
 74 void    conic_filter(Conic * conic, List * start, List * end)
 75 {
 76     Conic_stat stats = {Conic_stat_id};
 77     double  scale;
 78     List *dptr;
 79     Vec2    p = {Vec2_id};
 80     Vec2    p1 = {Vec2_id};
 81     Vec2    p2 = {Vec2_id};
 82     int     i, j, len;
 83 
 84     if (conic == NULL || filter == NULL)
 85         return;
 86 
 87     /** store copy of unfiltered conic **/
 88     /* BUGFIX conic0 unused */
 89     /* Conic   conic0; conic0 = *conic; */
 90 
 91     conic_normalise(conic);
 92     scale = MAX(fabs(conic->alpha), fabs(conic->beta));
 93 
 94     /** filter at least 5 points **/
 95     len = ddstr_length(start, end);
 96     if (len / sample < 4)
 97         sample = len / 4;
 98 
 99     for (i = 0; i < iter; ++i)
100     {
101         conic_stat_init(&stats, scale, 100.0);
102         for (dptr = start;;)
103         {
104             DD_GET_POS2(dptr, p);
105             filter(conic, &stats, p, var);
106             if (dptr == end)
107                 break;
108             for (j = 0; dptr != end && j < sample; ++j)
109                 dptr = dptr->next;
110         }
111         conic_correct(conic, stats.x);
112     }
113     conic_setup(conic);
114 
115     DD_GET_POS2(start, p1);
116     DD_GET_POS2(end, p2);
117     DD_GET_POS2(ddstr_mid_point(start, end), p);
118     conic_set_ends(conic, p1, p2, p);
119     conic->props = proplist_add(conic->props,
120                                 (void *) conic_stat_copy(&stats),
121                                 STATS,
122                                 rfree);
123 }
124 
125 /**
126 apply chosen filter to point string but limit result to an ellipse
127 **/
128 void    conic_ellipse_filter(Conic * conic, List * start, List * end, double min_aratio)
129 {
130     Conic_stat stats = {Conic_stat_id};
131     double  scale;
132     List *dptr;
133     Vec2    p = {Vec2_id};
134     Vec2    p1 = {Vec2_id};
135     Vec2    p2 = {Vec2_id};
136     int     i, j, len;
137     Conic   conic0 = {Conic_id};
138 
139     if (conic == NULL || filter == NULL)
140         return;
141 
142     /** store copy of unfiltered conic **/
143     conic0 = *conic;
144 
145     conic_normalise(conic);
146     scale = MAX(fabs(conic->alpha), fabs(conic->beta));
147 
148     /** filter at least 5 points **/
149     len = ddstr_length(start, end);
150     if (len / sample < 4)
151         sample = len / 4;
152 
153     for (i = 0; i < iter; ++i)
154     {
155         conic_stat_init(&stats, scale, 100.0);
156         for (dptr = start;;)
157         {
158             DD_GET_POS2(dptr, p);
159             filter(conic, &stats, p, var);
160             if (dptr == end)
161                 break;
162             for (j = 0; dptr != end && j < sample; ++j)
163                 dptr = dptr->next;
164         }
165         conic_correct(conic, stats.x);
166     }
167     conic_setup(conic);
168 
169     if (conic->type == HYPERBOLA || conic_aratio(conic) < min_aratio)
170     {
171         /** have made things worse, use saved copy **/
172         double  t1 = conic0.t1;
173         double  dt = conic0.t2 - conic0.t1;
174 
175         *conic = conic0;
176 
177         /** set up 5pt stats without changing conic **/
178         conic_stat_init(&stats, scale, 100.0);
179         filter(conic, &stats, conic_point(conic, t1), var);
180         filter(conic, &stats, conic_point(conic, t1 + 0.25 * dt), var);
181         filter(conic, &stats, conic_point(conic, t1 + 0.50 * dt), var);
182         filter(conic, &stats, conic_point(conic, t1 + 0.75 * dt), var);
183         filter(conic, &stats, conic_point(conic, t1 + 1.00 * dt), var);
184     }
185     DD_GET_POS2(start, p1);
186     DD_GET_POS2(end, p2);
187     DD_GET_POS2(ddstr_mid_point(start, end), p);
188     conic_set_ends(conic, p1, p2, p);
189     conic->props = proplist_add(conic->props,
190                                 (void *) conic_stat_copy(&stats),
191                                 STATS,
192                                 rfree);
193 }
194 
195 Conic  *conic_fit(List * start, List * end)
196 {
197     Conic  *conic = ddstr_conic_5pt(start, end);
198 
199     conic_filter(conic, start, end);
200     return (conic);
201 }
202 
203 Conic  *conic_ellipse_fit(List * start, List * end, double min_aratio)
204 {
205     Conic  *conic = ddstr_conic_ellipse_5pt(start, end, min_aratio);
206 
207     conic_ellipse_filter(conic, start, end, min_aratio);
208     return (conic);
209 }
210 

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