Sophie

Sophie

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

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

<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">
    <title>mmlabelflat</title>
    <link href="../tbxdok.css" rel="stylesheet">
  </head>
  <body>
    <table class="topNav">
      <tr>
        <td class="index">
                  [<a href="../morph/mmgrain.html"><tt>mmgrain</tt></a>]
              
                  [<a href="index.html">Up</a>]
                  
                  [<a href="../morph/mmpatspec.html"><tt>mmpatspec</tt></a>]
              </td>
        <td class="title">Measurements</td>
      </tr>
    </table>
    <h1>mmlabelflat
      <br>
      <span class="subtitle">Label the flat zones of gray-scale images.
</span>
    </h1>
    <div class="synopsis">
      <H2>Synopsis</H2>
      <div class="H2">
        <div class="prototype">y = 
          <span class="fun">mmlabelflat</span>(
                  
          <span class="par">f</span>, 
          <span class="par">Bc</span> = None, 
          <span class="par">_lambda</span> = 0
                  )
        </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>          Gray-scale (uint8 or uint16) or 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>
                <tr>
                  <td class="term"><span class="par">_lambda</span></td>
                  <td class="def"><span class="type"><a href="../mmtypes/mmDouble.html">Double</a></span><p>Connectivity given by |f(q)-f(p)|&lt;=_lambda.</p><p>Default: 
                      <code>0</code>
                    </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">mmlabelflat</span> creates the image 
          <code>y</code> by labeling the flat zones of 
          <code>f</code>, according to the connectivity defined by the structuring element 
          <code>Bc</code>. A flat zone is a connected region of the image domain in which all the pixels have the same gray-level (
          <code>lambda=0</code>). When 
          <code>lambda</code> is different than zero, a quasi-flat zone is detected where two neighboring pixels belong to the same region if their difference gray-levels is smaller or equal 
          <code>lambda</code>. The minimum label of the output image is 1 and the maximum is the number of flat-zones in the image.
                  
        </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=uint8([
   [5,5,8,3,0],
   [5,8,8,0,2]])</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; g=mmlabelflat(f)</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; print g</pre>
              <pre class="computer">[[1 1 2 3 4]
 [1 2 2 5 6]]</pre>
              <pre class="user">&gt;&gt;&gt; g1=mmlabelflat(f,mmsecross(),2)</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; print g1</pre>
              <pre class="computer">[[1 1 2 3 4]
 [1 2 2 4 4]]</pre>
            </div>
          </div>
          <div class="bridge">Gray-scale image example</div>A quantized distance transform image is built to be used to compute its flat zones. Note that the background and the hole in the bottom right area are also labeled. The number of the flat zones can be determined by the maximum label value.

          <br>
          <div class="example">
            <div class="listing">
              <pre class="user">&gt;&gt;&gt; f=mmreadgray('blob.tif')</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; d=mmdist(f,mmsebox(),'euclidean')</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; g= d /8</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; mmshow(g)</pre>
              <pre class="computer">Warning: Converting input image from int32 to uint16.</pre>
              <pre class="user">&gt;&gt;&gt; fz=mmlabelflat(g,mmsebox());</pre>
              <pre class="computer">Warning: Converting input image from int32 to uint16.</pre>
              <pre class="user">&gt;&gt;&gt; mmlblshow(fz)</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; print mmstats(fz,'max')</pre>
              <pre class="computer">13.0</pre>
            </div>
            <table class="images">
              <tbody align="center">
                <tr class="image" valign="bottom">
                  <td><img width="239" src="../images/img_mmlabelflat_001.jpg"></td>
                  <td><img width="239" src="../images/img_mmlabelflat_002.jpg"></td>
                  <td class="spare"></td>
                </tr>
                <tr class="title" valign="baseline">
                  <td><a href="../images/img_mmlabelflat_001.jpg">g</a></td>
                  <td><a href="../images/img_mmlabelflat_002.jpg">fz</a></td>
                  <td class="spare"></td>
                </tr>
              </tbody>
            </table>
          </div>
          <div class="bridge">Quasi-flat zones</div>In this case two pixels belong to the same quasi-flat zones if they are 8-neighbors (
          <code><span class="fun">mmsebox</span></code>) and  if their gray-values difference is smaller or equal 3.

          <br>
          <div class="example">
            <div class="listing">
              <pre class="user">&gt;&gt;&gt; f=mmreadgray('pcb_gray.tif')</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; g=mmlabelflat(f,mmsebox(),3)</pre>
              <pre class="computer"></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="256" src="../images/img_mmlabelflat_003.jpg"></td>
                  <td><img width="256" src="../images/img_mmlabelflat_004.jpg"></td>
                  <td class="spare"></td>
                </tr>
                <tr class="title" valign="baseline">
                  <td><a href="../images/img_mmlabelflat_003.jpg">f</a></td>
                  <td><a href="../images/img_mmlabelflat_004.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_mmlabelflat001.png">
          </div>
        </p>
      </div>
    </div>
    <div class="sourcecode">
      <H2>Source Code</H2>
      <div class="H2">
        <pre class="listing">
def mmlabelflat(f, Bc=None, _lambda=0):
    from Numeric import allclose, ravel, nonzero, array
    if Bc is None: Bc = mmsecross()
    zero = mmbinary(mmsubm(f,f))       # zero image
    faux = mmneg(zero)
    r = array(zero)
    label = 1
    y = mmgray( zero,'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
        f2aux = mmcmp( f, '==', ravel(f)[x])
        r = mminfrec( fmark, f2aux, 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/mmlabel.html">mmlabel</a></td>
              <td class="def">Label a binary image.</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/mmgrain.html">mmgrain</a></td>
              <td class="def">Gray-scale statistics for each labeled region.</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>
          </tbody>
        </table>
      </div>
    </div>
    <center>
      <table class="botNav">
        <tr>
          <td class="index">
                    [<a href="../morph/mmgrain.html"><tt>mmgrain</tt></a>]
                
                    [<a href="index.html">Up</a>]
                    
                    [<a href="../morph/mmpatspec.html"><tt>mmpatspec</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>