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

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

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

  1 /* fireburn.c
  2 
  3    Function to fireburn images. 
  4 
  5    Author: S.Crossley
  6    Date  : 29-7-96
  7 */
  8 
  9 #include <math.h>
 10 #include <tina/sys.h>
 11 #include <tina/sysfuncs.h>
 12 #include <tina/math.h>
 13 #include <tina/mathfuncs.h>
 14 #include <tina/vision.h>
 15 
 16 /* im_fireburn implments a fireburning alorithm to grow
 17    regions of known pixels values until entire image
 18    is filled with known values */
 19 
 20 Imrect *im_fireburn(Imrect *im, double low_thresh, double high_thresh)
 21 {
 22   Imrect *smask = NULL; /* source mask store */
 23   Imrect *dmask = NULL; /* destination mask store */
 24   Imrect *mask;         /* temporary store when pointers are swapped */
 25   int row, col;         /* loop variables */
 26   int burnt;            /* fully burnt control variable */
 27   Vartype vtype;
 28   Imrect *im2;
 29   int row_max, row_min, col_max, col_min;
 30 
 31   vtype = im->vtype;
 32   im2 = im_cast(im, float_v);
 33   im_free(im);
 34   im = im2;
 35 
 36   row_max = im->region->uy;
 37   row_min = im->region->ly;
 38   col_max = im->region->ux;
 39   col_min = im->region->lx;
 40 
 41   /* generate the source mask, 1 for a known value, 0 otherwise */
 42 
 43   smask = im_alloc(im->height, im->width, im->region, short_v);
 44 
 45   FOR_IM(im->region, row, col) IM_SHORT(smask, row, col) =
 46     (((IM_FLOAT(im, row, col)>=(float)low_thresh) &&
 47       (IM_FLOAT(im, row, col)<=(float)high_thresh)) ? 0 : 1);
 48 
 49   /* generate the destination mask, 1 for a known value, 0 otherwise */
 50 
 51   dmask = im_copy(smask);
 52 
 53   /* check to see if image is not already fully burnt */
 54 
 55   burnt = 1;
 56 
 57   FOR_IM(im->region, row, col) burnt = burnt && IM_SHORT(smask, row, col);
 58 
 59   /* fireburn the image */
 60 
 61   while (burnt==0)
 62     {
 63       FOR_IM(im->region, row, col)
 64         {
 65           if (IM_SHORT(smask, row, col)!=0)
 66             {
 67               IM_SHORT(dmask, row, col) = IM_SHORT(smask, row, col);
 68               if ((row+1<row_max)&&(col+1<col_max))
 69                 if (IM_SHORT(smask, row+1, col+1)==0)
 70                   {
 71                     IM_SHORT(dmask, row+1, col+1)=1;
 72                     IM_FLOAT(im, row+1, col+1)=IM_FLOAT(im, row, col);
 73                   }
 74               if (row+1<row_max)
 75                 if (IM_SHORT(smask, row+1, col)==0)
 76                   {
 77                     IM_SHORT(dmask, row+1, col)=1;
 78                     IM_FLOAT(im, row+1, col)=IM_FLOAT(im, row, col);
 79                   }
 80               if ((row+1<row_max)&&(col-1>=col_min))
 81                 if (IM_SHORT(smask, row+1, col-1)==0)
 82                   {
 83                     IM_SHORT(dmask, row+1, col-1)=1;
 84                     IM_FLOAT(im, row+1, col-1)=IM_FLOAT(im, row, col);
 85                   }
 86               if (col+1<col_max)
 87                 if (IM_SHORT(smask, row, col+1)==0)
 88                   {
 89                     IM_SHORT(dmask, row, col+1)=1;
 90                     IM_FLOAT(im, row, col+1)=IM_FLOAT(im, row, col);
 91                   }
 92               if (col-1>=col_min)
 93                 if (IM_SHORT(smask, row, col-1)==0)
 94                   {
 95                     IM_SHORT(dmask, row, col-1)=1;
 96                     IM_FLOAT(im, row, col-1)=IM_FLOAT(im, row, col);
 97                   }
 98               if ((row-1>=row_min)&&(col+1<col_max))
 99                 if (IM_SHORT(smask, row-1, col+1)==0)
100                   {
101                     IM_SHORT(dmask, row-1, col+1)=1;
102                     IM_FLOAT(im, row-1, col+1)=IM_FLOAT(im, row, col);
103                   }
104               if (row-1>=row_min)
105                 if (IM_SHORT(smask, row-1, col)==0)
106                   {
107                     IM_SHORT(dmask, row-1, col)=1;
108                     IM_FLOAT(im, row-1, col)=IM_FLOAT(im, row, col);
109                   }
110               if ((row-1>=row_min)&&(col-1>=col_min))
111                 if (IM_SHORT(smask, row-1, col-1)==0)
112                   {
113                     IM_SHORT(dmask, row-1, col-1)=1;
114                     IM_FLOAT(im, row-1, col-1)=IM_FLOAT(im, row, col);
115                   }
116             }
117         }
118           
119       /* check to see if image is now fully burnt */
120 
121       burnt = 1;
122 
123       FOR_IM(im->region, row, col) burnt = burnt && IM_SHORT(dmask, row, col);
124 
125       /* swap over the source and destination masks */
126 
127       mask = dmask;
128       dmask = smask;
129       smask = mask;
130     }
131 
132   im = im_cast(im2, vtype);
133   im_free(im2);
134 
135   im_free(smask);
136   im_free(dmask);
137 
138   return(im);
139 }
140 

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