"Fossies" - the Fresh Open Source Software Archive

Member "sip-0.12.1/help/en_US/bwlabel.xml" (8 Apr 2012, 6427 Bytes) of package /linux/privat/sip-0.12.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) XML source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "bwlabel.xml": 0.5.6_vs_0.12.1.

    1 <?xml version="1.0" encoding="ISO-8859-1"?><refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:lang="en" xml:id="bwlabel"><info><pubdate>February 2004</pubdate></info><refnamediv><refname>bwlabel</refname><refpurpose>Connected component labeling</refpurpose></refnamediv>
    2    
    3    
    4    
    5    
    6    
    7    
    8    
    9    
   10    
   11    
   12    
   13    <refsynopsisdiv><title>Calling Sequence</title><synopsis>[L, n] = bwlabel(img [, nhood])</synopsis></refsynopsisdiv>
   14    
   15    <refsection><title>Parameters</title>
   16    
   17       <variablelist>
   18       
   19          <varlistentry>
   20       
   21             <term>img</term>
   22       
   23             <listitem>
   24        A binary image, where 0 stands for background.
   25       </listitem>
   26       
   27          </varlistentry>
   28       
   29          <varlistentry>
   30       
   31             <term>nhood</term>
   32       
   33             <listitem>
   34        A scalar. The connectivity to consider in the algorithm. May be 4 or 8. Defaults to 8.
   35       </listitem>
   36       
   37          </varlistentry>
   38    
   39       </variablelist>
   40    
   41    </refsection>
   42    
   43    <refsection><title>Parameters</title>
   44    
   45       <variablelist>
   46       
   47          <varlistentry>
   48       
   49             <term>L</term>
   50       
   51             <listitem>
   52  A matrix of the same size as <literal>img</literal>, with the pixels of each connected object having the same number. The numbers vary from 1 to <literal>N</literal>, where <literal>N</literal> is the number of connected objects. The background is numbered 0.
   53       </listitem>
   54       
   55          </varlistentry>
   56       
   57          <varlistentry>
   58       
   59             <term>n</term>
   60       
   61             <listitem>
   62        The number of connected components. Equals to <literal>max(L)</literal>.
   63       </listitem>
   64       
   65          </varlistentry>
   66    
   67       </variablelist>
   68    
   69    </refsection>
   70    
   71    <refsection><title>Description</title>
   72    
   73       <para>
   74  Function <literal>bwlabel</literal> numbers all the objects in a binary image. One common application is to filter out objects that have less than a certain ammount of pixels. See the examples. </para>
   75    
   76       <para>
   77  You can use the Scilab find function in conjunction with
   78  <literal>bwlabel</literal> to return vectors of indices for the pixels that
   79  make up a specific object. For example, to return the coordinates
   80  for the pixels in object 3: </para>
   81  
   82       <programlisting><![CDATA[
   83     [r,c] = find(bwlabel(BW)==3)
   84  ]]></programlisting>
   85    
   86    </refsection>
   87    
   88    <refsection><title>Examples</title><programlisting role="example"><![CDATA[
   89    //
   90    // EXAMPLE 1
   91    //
   92 
   93    Img =[0     0     0     0     0     1     1
   94          0     1     1     0     0     1     1
   95          0     1     1     0     0     1     1
   96          0     0     0     1     0     1     1
   97          0     0     0     1     0     1     1
   98          0     0     0     1     0     1     1
   99          0     0     1     1     0     1     1
  100          0     0     0     0     0     1     1];
  101 
  102    L = bwlabel(Img,4)
  103 
  104    // Objects 2 and 3 are connected if 8-connectivity is used:
  105 
  106    L = bwlabel(Img) // default: 8-connectivity
  107 
  108    [r,c] = find(L==2);
  109 
  110    rc = [r' c']     // coordinates of object 2!
  111 
  112 
  113    //
  114    // EXAMPLE 2
  115    //
  116    xset('auto clear', 'on');
  117 
  118    a = gray_imread(SIPDIR + 'images/disks.bmp');
  119 
  120    // Add some noise
  121    //
  122    a = imnoise(a,'salt & pepper'); 
  123    a = 1-a;
  124    imshow(a,2);  // convention: objects are white(1)
  125 
  126    // Label every connected component with a unique number.
  127    //
  128    [L, n] = bwlabel(a);
  129 
  130    // Shows each component with a different color
  131    //
  132    imshow(L+1, rand(n+1,3));
  133 
  134    // Get one specific region (probably a single noise point)
  135    reg = (L == 300);
  136    imshow(reg*1, 2);
  137 
  138    // Eliminate regions smaller than 100 pixels (noise)
  139    // and those larger than 1000 pixels (cluttered disks)
  140    for i=1:n
  141       f = find(L==i);      // linear coordinates of i-th region
  142       reg_size = size(f,'*');
  143       if reg_size < 100 | reg_size > 1000
  144          L(f) = 0;         // merge small regions with the background
  145       end
  146    end
  147 
  148    imshow(L+1, rand(n+1,3));   // note how the small regions are gone
  149 
  150 
  151    // Just as a side-activity, let's fill the unwanted holes:
  152 
  153    bw = 1*(L>0);  // binarize the image
  154    imshow(bw,2)
  155    bw = dilate(bw);
  156    bw = erode(bw);
  157    imshow(bw,2);  // every hole is now filled
  158 
  159    xset('auto clear', 'off');
  160    ]]></programlisting></refsection>
  161 
  162 
  163     <para><emphasis role="bold">The original image, its label map, and a filter by passing blobs with between 100 and 1000 pixel area:</emphasis></para>
  164     <para><imagedata fileref="../images/disks-noisy.png" /> <imagedata fileref="../images/disks-label.png" /> <imagedata fileref="../images/disks-label-filtered.png" /></para>
  165 
  166 
  167    <refsection><title>Bibliography</title>
  168    
  169       <para>
  170 We use a simple stack-based flooding implementation written in C,
  171 but there exist many faster algorithms. The flood/fill region growing process may be found in most books of imaging science. For instance:
  172    </para>
  173    
  174       <para>
  175 "Shape Analysis and Classification", L. da
  176 F. Costa and R. M. Cesar Jr., CRC Press,
  177 pp. 335-347.
  178    </para>
  179    
  180       <para>
  181 Example of fast algorithm (not implemented):
  182    </para>
  183    
  184       <para>
  185 Haralick, Robert M., and Linda G. Shapiro, Computer and Robot Vision, Volume I, Addison-Wesley, 1992, pp. 28-48. 
  186    </para>
  187 
  188    </refsection>
  189 
  190    
  191    <refsection><title>Authors</title><simplelist type="vert">
  192       
  193       <member> Ricardo Fabbri &lt;ricardofabbri (AT) users DOT sf DOT net&gt; </member>
  194    
  195    </simplelist></refsection>
  196 
  197 
  198    <refsection><title>Availability</title>
  199 The latest version of the Scilab Image Processing toolbox can be found at
  200 <para>
  201          http://siptoolbox.sourceforge.net
  202       </para>
  203 
  204    </refsection>
  205 
  206    
  207    <refsection><title>See Also</title><simplelist type="inline">
  208       
  209       <member> 
  210          <link linkend="bwdist">bwdist</link> (nearest pixel label map)
  211       </member>
  212 
  213       <member> 
  214          <link linkend="bwborder">bwborder</link> 
  215       </member>
  216       
  217       <member> 
  218          <link linkend="erode">erode</link> 
  219       </member>
  220       
  221       <member> 
  222          <link linkend="dilate">dilate</link> 
  223       </member>
  224       
  225       <member> 
  226          <link linkend="watershed">watershed</link> 
  227       </member>
  228    
  229    </simplelist></refsection>
  230 
  231 </refentry>