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

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

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

  1 #include <math.h>
  2 #include <tina/sys.h>
  3 #include <tina/sysfuncs.h>
  4 #include <tina/math.h>
  5 #include <tina/mathfuncs.h>
  6 #include <tina/vision.h>
  7 #include <tina/visionfuncs.h>
  8 
  9 Imrect *imi_thresh(double k, Imrect *im1)
 10 {
 11     Imrect *im2;
 12     Imregion *roi;
 13     int *row1, *row2;
 14     int lx, ux, ly, uy;
 15     int i, j;
 16 
 17     if (im1 == NULL)
 18         return (NULL);
 19 
 20     roi = im1->region;
 21     if (roi == NULL)
 22         return (NULL);
 23     lx = roi->lx;
 24     ux = roi->ux;
 25     ly = roi->ly;
 26     uy = roi->uy;
 27 
 28     im2 = im_alloc(im1->height, im1->width, roi, int_v);
 29     row1 = ivector_alloc(lx, ux);
 30     row2 = ivector_alloc(lx, ux);
 31 
 32     for (i = ly; i < uy; ++i)
 33     {
 34         im_get_row(row1, im1, i, lx, ux);
 35         for (j = lx; j < ux; ++j)
 36             if(row1[j] > k)
 37                 row2[j] = row1[j];
 38             else
 39                 row2[j] = (int)0.0;
 40         im_put_row(row2, im2, i, lx, ux);
 41     }
 42 
 43     ivector_free(row1, lx);
 44     ivector_free(row2, lx);
 45     return (im2);
 46 }
 47 
 48 Imrect *imi_bthresh(double k, Imrect *im1)
 49 {
 50     Imrect *im2;
 51     Imregion *roi;
 52     int *row1, *row2;
 53     int lx, ux, ly, uy;
 54     int i, j;
 55  
 56     if (im1 == NULL)
 57         return (NULL);
 58  
 59     roi = im1->region;
 60     if (roi == NULL)
 61         return (NULL);
 62     lx = roi->lx;
 63     ux = roi->ux;
 64     ly = roi->ly;
 65     uy = roi->uy;
 66  
 67     im2 = im_alloc(im1->height, im1->width, roi, int_v);
 68     row1 = ivector_alloc(lx, ux);
 69     row2 = ivector_alloc(lx, ux);
 70  
 71     for (i = ly; i < uy; ++i)
 72     {
 73         im_get_row(row1, im1, i, lx, ux);
 74         for (j = lx; j < ux; ++j)
 75             if(row1[j] > k)
 76                 row2[j] = (int)1.0;
 77             else
 78                 row2[j] = (int)0.0;
 79         im_put_row(row2, im2, i, lx, ux);
 80     }
 81  
 82     ivector_free(row1, lx);
 83     ivector_free(row2, lx);
 84     return (im2);
 85 }
 86 
 87 Imrect *imf_thresh(double k, Imrect *im1)
 88 {
 89     Imrect *im2;
 90     Imregion *roi;
 91     float *row1, *row2;
 92     int lx, ux, ly, uy;
 93     int i, j;
 94 
 95     if (im1 == NULL)
 96         return (NULL);
 97 
 98     roi = im1->region;
 99     if (roi == NULL)
100         return (NULL);
101     lx = roi->lx;
102     ux = roi->ux;
103     ly = roi->ly;
104     uy = roi->uy;
105 
106     im2 = im_alloc(im1->height, im1->width, roi, float_v);
107     row1 = fvector_alloc(lx, ux);
108     row2 = fvector_alloc(lx, ux);
109 
110     for (i = ly; i < uy; ++i)
111     {
112         im_get_rowf(row1, im1, i, lx, ux);
113         for (j = lx; j < ux; ++j)
114             if(row1[j] > k)
115                 row2[j] = row1[j];
116             else
117                 row2[j] = (float)0.0;
118         im_put_rowf(row2, im2, i, lx, ux);
119     }
120 
121     fvector_free(row1, lx);
122     fvector_free(row2, lx);
123     return (im2);
124 }
125 
126 Imrect *imf_bthresh(double k, Imrect *im1)
127 {
128     Imrect *im2;
129     Imregion *roi;
130     float *row1, *row2;
131     int lx, ux, ly, uy;
132     int i, j;
133  
134     if (im1 == NULL)
135         return (NULL);
136  
137     roi = im1->region;
138     if (roi == NULL)
139         return (NULL);
140     lx = roi->lx;
141     ux = roi->ux;
142     ly = roi->ly;
143     uy = roi->uy;
144  
145     im2 = im_alloc(im1->height, im1->width, roi, float_v);
146     row1 = fvector_alloc(lx, ux);
147     row2 = fvector_alloc(lx, ux);
148  
149     for (i = ly; i < uy; ++i)
150     {
151         im_get_rowf(row1, im1, i, lx, ux);
152         for (j = lx; j < ux; ++j)
153             if(row1[j] > k)
154                 row2[j] = (float)1.0;
155             else
156                 row2[j] = (float)0.0;
157         im_put_rowf(row2, im2, i, lx, ux);
158     }
159  
160     fvector_free(row1, lx);
161     fvector_free(row2, lx);
162     return (im2);
163 }
164 
165 Imrect *imz_thresh(double k, Imrect *im1)
166 {
167     Imrect *im2;
168     Imregion *roi;
169     Complex *row1, *row2;
170     int lx, ux, ly, uy;
171     int i, j;
172  
173     if (im1 == NULL)
174         return (NULL);
175  
176     roi = im1->region;
177     if (roi == NULL)
178         return (NULL);
179     lx = roi->lx;
180     ux = roi->ux;
181     ly = roi->ly;
182     uy = roi->uy;
183  
184     im2 = im_alloc(im1->height, im1->width, roi, float_v);
185     row1 = zvector_alloc(lx, ux);
186     row2 = zvector_alloc(lx, ux);
187  
188     for (i = ly; i < uy; ++i)
189     {
190         im_get_rowz(row1, im1, i, lx, ux);
191         for (j = lx; j < ux; ++j)
192             if(row1[j].x > k)
193             {
194                 row2[j].x = row1[j].x;
195                 row2[j].y = row1[j].y;
196             }
197             else
198             {
199                 row2[j].x = 0.0;
200                 row2[j].y = 0.0;
201             }
202         im_put_rowz(row2, im2, i, lx, ux);
203     }
204  
205     zvector_free(row1, lx);
206     zvector_free(row2, lx);
207     return (im2);
208 }
209 
210 Imrect *imz_bthresh(double k, Imrect *im1)
211 {
212     Imrect *im2;
213     Imregion *roi;
214     Complex *row1, *row2;
215     int lx, ux, ly, uy;
216     int i, j;
217  
218     if (im1 == NULL)
219         return (NULL);
220  
221     roi = im1->region;
222     if (roi == NULL)
223         return (NULL);
224     lx = roi->lx;
225     ux = roi->ux;
226     ly = roi->ly;
227     uy = roi->uy;
228  
229     im2 = im_alloc(im1->height, im1->width, roi, float_v);
230     row1 = zvector_alloc(lx, ux);
231     row2 = zvector_alloc(lx, ux);
232  
233     for (i = ly; i < uy; ++i)
234     {
235         im_get_rowz(row1, im1, i, lx, ux);
236         for (j = lx; j < ux; ++j)
237             if(row1[j].x > k)
238             {
239                 row2[j].x = 1.0;
240                 row2[j].y = 0.0;
241             }
242             else
243             {
244                 row2[j].x = 0.0;
245                 row2[j].y = 0.0;
246             }
247         im_put_rowz(row2, im2, i, lx, ux);
248     }
249  
250     zvector_free(row1, lx);
251     zvector_free(row2, lx);
252     return (im2);
253 }
254 
255 Imrect *imp_bthresh(double k, Imrect *im1)
256 {
257     Imrect *im2;
258     Imregion *roi;
259     float *row2;
260     void **row1;
261     int lx, ux, ly, uy;
262     int i, j;
263  
264     if (im1 == NULL)
265         return (NULL);
266  
267     roi = im1->region;
268     if (roi == NULL)
269         return (NULL);
270     lx = roi->lx;
271     ux = roi->ux;
272     ly = roi->ly;
273     uy = roi->uy;
274  
275     im2 = im_alloc(im1->height, im1->width, roi, float_v);
276     row2 = fvector_alloc(lx, ux);
277  
278     for (i = ly; i < uy; ++i)
279     {
280         row1 = IM_ROW(im1,i);
281         for (j = lx; j < ux; ++j)
282             if(row1[j]&&((Edgel *)row1[j])->contrast > k)
283                 row2[j] = (float)1.0;
284             else
285                 row2[j] = (float)0.0;
286         im_put_rowf(row2, im2, i, lx, ux);
287     }
288  
289     fvector_free(row2, lx);
290     return (im2);
291 }
292 
293 Imrect *im_thresh(double k,Imrect *im)
294 {
295     if(im == NULL )
296         return(NULL);
297     switch(im->vtype)
298     {
299         case uchar_v:
300         case char_v:
301         case short_v:
302         case ushort_v:
303         case int_v:
304             return(imi_thresh(k,im));
305         case float_v:
306             return(imf_thresh(k,im));
307         case complex_v:
308             return(imz_thresh(k,im));
309         default:
310             return(NULL);
311     }
312 }
313 
314 Imrect *im_bthresh(double k,Imrect *im)
315 {
316     if(im == NULL )
317         return(NULL);
318     switch(im->vtype)
319     {
320         case uchar_v:
321         case char_v:
322         case short_v:
323         case ushort_v:
324         case int_v:
325             return(imi_bthresh(k,im));
326         case float_v:
327             return(imf_bthresh(k,im));
328         case complex_v:
329             return(imz_bthresh(k,im));
330         case ptr_v:
331             return(imp_bthresh(k,im));
332         default:
333             return(NULL);
334     }
335 }
336 

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