Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 4a71d9984febeb5a206904a5a379841a > files > 710

python-morph-0.8-7mdv2010.0.noarch.rpm

<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">
    <title>mmlabel</title>
    <link href="../tbxdok.css" rel="stylesheet">
  </head>
  <body>
    <table class="topNav">
      <tr>
        <td class="index">
                  [<a href="../morph/mmhistogram.html"><tt>mmhistogram</tt></a>]
              
                  [<a href="index.html">Up</a>]
                  
                  [<a href="../morph/mmblob.html"><tt>mmblob</tt></a>]
              </td>
        <td class="title">Measurements</td>
      </tr>
    </table>
    <h1>mmlabel
      <br>
      <span class="subtitle">Label a binary image.
</span>
    </h1>
    <div class="synopsis">
      <H2>Synopsis</H2>
      <div class="H2">
        <div class="prototype">y = 
          <span class="fun">mmlabel</span>(
                  
          <span class="par">f</span>, 
          <span class="par">Bc</span> = None
                  )
        </div>
        <p>Implemented in 
          <b>Python.</b>
        </p>
        <div class="input">
          <H3>Input</H3>
          <div class="H3">
            <table class="deflist">
              <tbody valign="baseline">
                <tr>
                  <td class="term"><span class="par">f</span></td>
                  <td class="def"><span class="type"><a href="../mmtypes/mmImage.html">Image</a></span>          Binary image.
                        </td>
                </tr>
                <tr>
                  <td class="term"><span class="par">Bc</span></td>
                  <td class="def"><span class="type"><a href="../mmtypes/mmSe.html">Structuring Element</a></span><p>( connectivity).</p><p>Default: 
                      <code>None</code> (3x3 elementary cross)
                    </p></td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
        <div class="output">
          <H3>Output</H3>
          <div class="H3">
            <table class="deflist">
              <tbody valign="baseline">
                <tr>
                  <td class="term"><span class="par">y</span></td>
                  <td class="def"><span class="type"><a href="../mmtypes/mmImage.html">Image</a></span><p>If number of labels is less than 65535, the data type is uint16, otherwise it is int32.</p></td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
    <div class="descr">
      <H2>Description</H2>
      <div class="H2">
        <p>
          <span class="fun">mmlabel</span> creates the image 
          <code>y</code> by labeling the connect components of a binary image 
          <code>f</code>, according to the connectivity defined by the structuring element 
          <code>Bc</code>. The background pixels (with value 0) are not labeled. The maximum label value in the output image gives the number of its connected components.
                  
        </p>
      </div>
    </div>
    <div class="examples">
      <H2>Examples</H2>
      <div class="H2">
        <p>
          <div class="bridge">Numerical Example</div>
          <div class="example">
            <div class="listing">
              <pre class="user">&gt;&gt;&gt; f=mmbinary([
   [0,1,0,1,1],
   [1,0,0,1,0]])</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; g=mmlabel(f)</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; print g</pre>
              <pre class="computer">[[0 1 0 2 2]
 [3 0 0 2 0]]</pre>
            </div>
          </div>
          <div class="bridge">Image Example</div>
          <br>The maximum label value gives the number of connected blobs in the image.

          <br>
          <div class="example">
            <div class="listing">
              <pre class="user">&gt;&gt;&gt; f = mmreadgray('blob3.tif')</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; g=mmlabel(f)</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; nblobs=mmstats(g,'max')</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; print nblobs</pre>
              <pre class="computer">18.0</pre>
              <pre class="user">&gt;&gt;&gt; mmshow(f)</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; mmlblshow(g)</pre>
              <pre class="computer"></pre>
            </div>
            <table class="images">
              <tbody align="center">
                <tr class="image" valign="bottom">
                  <td><img width="128" src="../images/img_mmlabel_001.jpg"></td>
                  <td><img width="128" src="../images/img_mmlabel_002.jpg"></td>
                  <td class="spare"></td>
                </tr>
                <tr class="title" valign="baseline">
                  <td><a href="../images/img_mmlabel_001.jpg">f</a></td>
                  <td><a href="../images/img_mmlabel_002.jpg">g</a></td>
                  <td class="spare"></td>
                </tr>
              </tbody>
            </table>
          </div>
        </p>
      </div>
    </div>
    <div class="equation">
      <H2>Equation</H2>
      <div class="H2">
        <p>
          <div class="eqfig">
            <img src="../images/eq_mmlabel001.png">
          </div>Where 
          <i>H</i> is the number of image rows, and 
          <i>y1</i> and 
          <i>y2</i> are the row and column coordinates respectively.
                      
        </p>
      </div>
    </div>
    <div class="sourcecode">
      <H2>Source Code</H2>
      <div class="H2">
        <pre class="listing">
def mmlabel(f, Bc=None):
    from Numeric import allclose, ravel, nonzero, array
    if Bc is None: Bc = mmsecross()
    assert mmisbinary,'Can only label binary image'
    zero = mmsubm(f,f)               # zero image
    faux=f
    r = array(zero)
    label = 1
    y = mmgray( f,'uint16',0)        # zero image (output)
    while not allclose(faux,0):
        x=nonzero(ravel(faux))[0]      # get first unlabeled pixel
        fmark = array(zero)
        fmark.flat[x] = 1              # get the first unlabeled pixel
        r = mminfrec( fmark, faux, Bc) # detects all pixels connected to it
        faux = mmsubm( faux, r)        # remove them from faux
        r = mmgray( r,'uint16',label)  # label them with the value label
        y = mmunion( y, r)             # merge them with the labeled image
        label = label + 1
    return y
    </pre>
      </div>
    </div>
    <div class="seealso">
      <H2>See also</H2>
      <div class="H2">
        <table class="deflist">
          <tbody valign="baseline">
            <tr>
              <td class="term"><a href="../morph/mmlabelflat.html">mmlabelflat</a></td>
              <td class="def">Label the flat zones of gray-scale images.</td>
            </tr>
            <tr>
              <td class="term"><a href="../morph/mmfreedom.html">mmfreedom</a></td>
              <td class="def">Control automatic data type conversion.</td>
            </tr>
            <tr>
              <td class="term"><a href="../morph/mmsebox.html">mmsebox</a></td>
              <td class="def">Create a box structuring element.</td>
            </tr>
            <tr>
              <td class="term"><a href="../morph/mmsecross.html">mmsecross</a></td>
              <td class="def">Diamond structuring element and elementary 3x3 cross.</td>
            </tr>
            <tr>
              <td class="term"><a href="../morph/mmareaopen.html">mmareaopen</a></td>
              <td class="def">Area opening</td>
            </tr>
            <tr>
              <td class="term"><a href="../morph/mmblob.html">mmblob</a></td>
              <td class="def">Blob measurements from a labeled image.</td>
            </tr>
            <tr>
              <td class="term"><a href="../morph/mmgrain.html">mmgrain</a></td>
              <td class="def">Gray-scale statistics for each labeled region.</td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
    <center>
      <table class="botNav">
        <tr>
          <td class="index">
                    [<a href="../morph/mmhistogram.html"><tt>mmhistogram</tt></a>]
                
                    [<a href="index.html">Up</a>]
                    
                    [<a href="../morph/mmblob.html"><tt>mmblob</tt></a>]
                </td>
          <td rowspan="2" class="xhtml"><a href="http://www.python.org"><img width="55" alt="Python" height="22" src="../PythonPoweredSmall.gif"></a></td>
        </tr>
        <tr>
          <td class="copyright">Copyright (c) 2003, Roberto A. Lotufo, UNICAMP-University of Campinas; Rubens C. Machado, CenPRA-Renato Archer Research Center.</td>
        </tr>
      </table>
    </center>
  </body>
</html>