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

Linux Cross Reference
Tina6/tina-libs/tina/image/imgPrc_connect.c

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

  1 /**********
  2  *
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  *
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-libs/tina/image/imgPrc_connect.c,v $
 37  * Date    :  $Date: 2005/01/23 19:10:21 $
 38  * Version :  $Revision: 1.6 $
 39  * CVS Id  :  $Id: imgPrc_connect.c,v 1.6 2005/01/23 19:10:21 paul Exp $
 40  *
 41  * Author  : Legacy TINA
 42  */
 43 
 44 /** 
 45  *  @file
 46  *  @brief Functions for the identification and processing of pixels connected to
 47  *  a specified point via a route of non-zero connected pixels. 
 48  *
 49  * Notes :   a reasonably efficient and simple expansion/contraction filling algorithm.
 50  *           Non-zero pixels in the mask image within the specified region and
 51  *           connected to the pixel at xy are set to a value of 1 in the output
 52  *           image connmask. A user specified function can also be applied to these
 53  *           pixels as they are identified.
 54  *
 55  */
 56 
 57 #include "imgPrc_connect.h"
 58 
 59 #if HAVE_CONFIG_H
 60 #include <config.h>
 61 #endif
 62 
 63 #include <stdio.h>
 64 #include <math.h>
 65 #include <tina/sys/sysDef.h>
 66 #include <tina/sys/sysPro.h>
 67 #include <tina/math/mathDef.h>
 68 #include <tina/math/mathPro.h>
 69 #include <tina/image/img_GenDef.h>
 70 #include <tina/image/imgGen_get.h>
 71 
 72 
 73 static Bool     connected(Imrect * c, int y, int x)
 74 {
 75         Bool            linked = false;
 76 
 77         if (IM_CHAR(c, y - 1, x) == 1)
 78                 linked = true;
 79         else if (IM_CHAR(c, y + 1, x) == 1)
 80                 linked = true;
 81         else if (IM_CHAR(c, y, x - 1) == 1)
 82                 linked = true;
 83         else if (IM_CHAR(c, y, x + 1) == 1)
 84                 linked = true;
 85 
 86         return (linked);
 87 }
 88 
 89 
 90 void            imc_connpixels(Imrect * mask, Imrect * connmask, Imregion roi,
 91                                     int x, int y, void (*pixelxy) ( /* */ ))
 92 {
 93         Bool            ccont;
 94         int             count = -1;
 95         int             i, j;
 96         int             n=1, incrn = -1;
 97 
 98         IM_CHAR(connmask, y, x) = 1;
 99         if (pixelxy != NULL)
100                 pixelxy(x, y);
101         while (count != 0)      /* keep on going until no new pixels selected
102                                  * NAT */
103         {
104                 if (incrn < 0)
105                 {
106                         incrn = 1;
107                         n = 1;
108                 } else
109                 {
110                         incrn = -1;
111                         n -= 1;
112                 }
113                 ccont = true;
114                 count = 0;
115                 for (; ccont || ((incrn < 0) && (n > 1)); n += incrn)
116                 {
117                         ccont = false;
118                         if (y - n <= roi.ly)
119                                 i = roi.ly + 1;
120                         else
121                                 i = y - n;
122                         for (; (i <= y + n) && (i < roi.uy - 1); i++)
123                         {
124                                 if ((i == y - n) || (i == y + n))
125                                 {
126                                         if (incrn > 0)  /* expansion and
127                                                          * contraction filling
128                                                          * NAT  */
129                                         {
130                                                 if (x - n <= roi.lx)
131                                                         j = roi.lx + 1;
132                                                 else
133                                                         j = x - n;
134                                                 for (; (j <= x + n) && (j < roi.ux - 1); j++)
135                                                         if ((im_get_pix(mask, i, j) != 0) && connected(connmask, i, j))
136                                                         {
137                                                                 if (IM_CHAR(connmask, i, j) == 0)
138                                                                 {
139                                                                         IM_CHAR(connmask, i, j) = 1;
140                                                                         count++;
141                                                                         if (pixelxy != NULL)
142                                                                                 pixelxy(j, i);
143                                                                 }
144                                                                 ccont = true;
145                                                         }
146                                         } else
147                                         {
148                                                 if (x + n >= roi.ux)
149                                                         j = roi.ux - 1;
150                                                 else
151                                                         j = x + n;
152                                                 for (; (j >= x - n) && (j >= roi.lx + 1); j--)
153                                                         if ((im_get_pix(mask, i, j) != 0) && connected(connmask, i, j))
154                                                         {
155                                                                 if (IM_CHAR(connmask, i, j) == 0)
156                                                                 {
157                                                                         IM_CHAR(connmask, i, j) = 1;
158                                                                         count++;
159                                                                         if (pixelxy != NULL)
160                                                                                 pixelxy(j, i);
161                                                                 }
162                                                                 ccont = true;
163                                                         }
164                                         }
165                                 } else
166                                 {
167                                         j = x - n;
168                                         if ((im_get_pix(mask, i, j) != 0) && connected(connmask, i, j))
169                                         {
170                                                 if (IM_CHAR(connmask, i, j) == 0)
171                                                 {
172                                                         IM_CHAR(connmask, i, j) = 1;
173                                                         count++;
174                                                         if (pixelxy != NULL)
175                                                                 pixelxy(j, i);
176                                                 }
177                                                 ccont = true;
178                                         }
179                                         j = x + n;
180                                         if ((im_get_pix(mask, i, j) != 0) && connected(connmask, i, j))
181                                         {
182                                                 if (IM_CHAR(connmask, i, j) == 0)
183                                                 {
184                                                         IM_CHAR(connmask, i, j) = 1;
185                                                         count++;
186                                                         if (pixelxy != NULL)
187                                                                 pixelxy(j, i);
188                                                 }
189                                                 ccont = true;
190                                         }
191                                 }
192                         }
193                 }
194         }
195 }
196 

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