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

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

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

  1 #include <stdio.h>
  2 #include <math.h>
  3 #include <tina/sys.h>
  4 #include <tina/sysfuncs.h>
  5 #include <tina/math.h>
  6 #include <tina/mathfuncs.h>
  7 #include <tina/vision.h>
  8 #include <tina/visionfuncs.h>
  9 
 10 static Bool  connected(Imrect *c, int y, int x)
 11 {
 12         Bool  linked = false;
 13 
 14         if (IM_CHAR(c, y-1, x) == 1)
 15                 linked = true;
 16         else if (IM_CHAR(c, y+1, x) == 1)
 17                 linked = true;
 18         else if (IM_CHAR(c, y,   x-1) == 1)
 19                 linked = true;
 20         else if (IM_CHAR(c, y,   x+1) == 1)
 21                 linked = true;
 22 
 23         return(linked);
 24 }
 25 
 26 /*  a reasonably efficient and simple expansion/contraction filling algorithm
 27     based on Tony's initial unidirectional effort.
 28     non zero pixels in the mask image within the specified region and
 29     connected to the pixel at xy are set to a value of 1 in the output
 30     image connmask NAT */
 31 void imc_connpixels(Imrect *mask, Imrect *connmask, Imregion roi,
 32                  int x, int y, void (*pixelxy)(/* */))
 33 {
 34    Bool    ccont;
 35    int     count = -1;
 36    int     i, j;
 37    int     n, incrn=-1;
 38    int     lx,ux,ly,uy;
 39 
 40    IM_CHAR(connmask, y, x) = 1;
 41    if (pixelxy!=NULL) pixelxy(x, y);
 42    while (count!=0) /* keep on going until no new pixels selected NAT */
 43    {
 44       if (incrn<0)
 45       {
 46          incrn = 1;
 47          n = 1;
 48       }
 49       else
 50       {
 51          incrn = -1;
 52          n -= 1;
 53       }
 54       ccont = true;
 55       count =0;
 56       for (; ccont ||((incrn<0)&&(n>1)); n+=incrn)
 57       {
 58          ccont = false;
 59          if (y-n<=roi.ly) i = roi.ly+1;
 60          else i = y-n;
 61          for (; (i <= y+n)&&(i < roi.uy-1); i++)
 62          {
 63             if ((i == y-n) || (i == y+n))
 64             {
 65                if (incrn>0) /* expansion and contraction filling NAT  */
 66                {
 67                   if (x-n<=roi.lx) j = roi.lx+1;
 68                   else j = x-n;
 69                   for (; (j <= x+n) && (j < roi.ux-1); j++)
 70                      if ((im_get_pix(mask, i, j) !=0) && connected(connmask, i, j))
 71                      {
 72                         if (IM_CHAR(connmask, i, j)==0)
 73                         {
 74                             IM_CHAR(connmask, i, j) = 1;
 75                             count ++;
 76                             if (pixelxy!=NULL) pixelxy(j, i);
 77                         }
 78                         ccont = true;
 79                      }
 80                }
 81                else
 82                {
 83                   if (x+n>=roi.ux) j = roi.ux-1;
 84                   else j = x+n;
 85                   for (; (j >= x-n) && (j >= roi.lx+1); j--)
 86                      if ((im_get_pix(mask, i, j) !=0) && connected(connmask, i, j))
 87                      {
 88                         if (IM_CHAR(connmask, i, j)==0)
 89                         {
 90                             IM_CHAR(connmask, i, j) = 1;
 91                             count ++;
 92                             if (pixelxy!=NULL) pixelxy(j, i);
 93                         }
 94                         ccont = true;
 95                      }
 96                }
 97             }
 98             else
 99             {
100                j = x-n;
101                if ((im_get_pix(mask, i, j) !=0) && connected(connmask, i, j))
102                {
103                   if (IM_CHAR(connmask, i, j)==0)
104                   {
105                      IM_CHAR(connmask, i, j) = 1;
106                      count ++;
107                      if (pixelxy!=NULL) pixelxy(j, i);
108                   }
109                   ccont = true;
110                }
111                j = x+n;
112                if ((im_get_pix(mask, i, j) !=0 ) && connected(connmask, i, j))
113                {
114                   if (IM_CHAR(connmask, i, j)==0)
115                   {
116                      IM_CHAR(connmask, i, j) = 1;
117                      count ++;
118                      if (pixelxy!=NULL) pixelxy(j, i);
119                   }
120                   ccont = true;
121                }
122             }
123          }
124       }
125    }
126 }
127 
128 

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