Sophie

Sophie

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

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

<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">
    <title>mmdist</title>
    <link href="../tbxdok.css" rel="stylesheet">
  </head>
  <body>
    <table class="topNav">
      <tr>
        <td class="index">
                  [<a href="../morph/mmopen.html"><tt>mmopen</tt></a>]
              
                  [<a href="index.html">Up</a>]
                  
                  [<a href="../morph/mmgdist.html"><tt>mmgdist</tt></a>]
              </td>
        <td class="title">Image Transforms</td>
      </tr>
    </table>
    <h1>mmdist
      <br>
      <span class="subtitle">Distance transform.
</span>
    </h1>
    <div class="synopsis">
      <H2>Synopsis</H2>
      <div class="H2">
        <div class="prototype">y = 
          <span class="fun">mmdist</span>(
                  
          <span class="par">f</span>, 
          <span class="par">Bc</span> = None, 
          <span class="par">METRIC</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>
                <tr>
                  <td class="term"><span class="par">METRIC</span></td>
                  <td class="def"><span class="type"><a href="../mmtypes/mmString.html">String</a></span><p>'EUCLIDEAN', or 'EUC2' for squared Euclidean.</p><p>Default: 
                      <code>None</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>distance image in uint16, or in int32 datatype with EUC2 option.</p></td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
    <div class="descr">
      <H2>Description</H2>
      <div class="H2">
        <p>
          <span class="fun">mmdist</span> creates the distance image 
          <code>y</code> of the binary image 
          <code>f</code>.  The value of  
          <code>y</code> at the pixel 
          <code>x</code> is the distance of 
          <code>x</code> to the complement of 
          <code>f</code>, that is, the distance of 
          <code>x</code> to nearest point in the complement of 
          <code>f</code>. The distances available are based on the Euclidean metrics and on metrics generated by a a regular graph, that is characterized by a connectivity rule defined by the structuring element 
          <code>Bc</code>. The implementation of the Euclidean algorithm is based on LotuZamp:01.
                  
        </p>
      </div>
    </div>
    <div class="examples">
      <H2>Examples</H2>
      <div class="H2">
        <p>
          <div class="bridge">Simple numeric example</div>
          <div class="example">
            <div class="listing">
              <pre class="user">&gt;&gt;&gt; a = mmframe(mmbinary(ones((5,9))),2,4)</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; f4=mmdist(a)</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; f8=mmdist(a,mmsebox())</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; fe=mmdist(a,mmsebox(),'EUCLIDEAN')</pre>
              <pre class="computer"></pre>
            </div>
          </div>
          <div class="bridge">Image example</div>
          <div class="example">
            <div class="listing">
              <pre class="user">&gt;&gt;&gt; f = mmreadgray('gear.tif')</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; f = mmneg(mmgradm(f))</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; d4=mmdist(f)</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; d8=mmdist(f,mmsebox())</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; de=mmdist(f,mmsebox(),'EUCLIDEAN')</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; mmshow(f)</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; mmshow(d4%8)</pre>
              <pre class="computer">Warning: Converting input image from int32 to uint16.</pre>
              <pre class="user">&gt;&gt;&gt; mmshow(d8%8)</pre>
              <pre class="computer">Warning: Converting input image from int32 to uint16.</pre>
              <pre class="user">&gt;&gt;&gt; mmshow(de%8)</pre>
              <pre class="computer">Warning: Converting input image from int32 to uint16.</pre>
            </div>
            <table class="images">
              <tbody align="center">
                <tr class="image" valign="bottom">
                  <td><img width="139" src="../images/img_mmdist_001.jpg"></td>
                  <td><img width="139" src="../images/img_mmdist_002.jpg"></td>
                  <td><img width="139" src="../images/img_mmdist_003.jpg"></td>
                  <td><img width="139" src="../images/img_mmdist_004.jpg"></td>
                  <td class="spare"></td>
                </tr>
                <tr class="title" valign="baseline">
                  <td><a href="../images/img_mmdist_001.jpg">f</a></td>
                  <td><a href="../images/img_mmdist_002.jpg">d4%8</a></td>
                  <td><a href="../images/img_mmdist_003.jpg">d8%8</a></td>
                  <td><a href="../images/img_mmdist_004.jpg">de%8</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="bridge">distance of a point x to a set X:</div>
          <div class="eqfig">
            <img src="../images/eq_mmdist001.png">
          </div>
          <div class="bridge">distance function:</div>
          <div class="eqfig">
            <img src="../images/eq_mmdist002.png">
          </div>
          <div class="bridge">distance function using structuring element:</div>
          <div class="eqfig">
            <img src="../images/eq_mmdist003.png">
          </div>
          <div class="bridge">Relationship between erosion and distance transform:</div>
          <div class="eqfig">
            <img src="../images/eq_mmdist004.png">
          </div>
        </p>
      </div>
    </div>
    <div class="descr">
      <H2>Limitations</H2>
      <div class="H2">
        <p>
                      To generate useful Distance transforms, the structuring elements must be symmetric and have the origin included.
          The Euclidean distance transform is rounded to the nearest integer, since it is represented as an unsigned integer image. Use the option EUC2 to compute exact squared Euclidean distance transform.
                  
        </p>
      </div>
    </div>
    <div class="sourcecode">
      <H2>Source Code</H2>
      <div class="H2">
        <pre class="listing">
def mmdist(f, Bc=None, METRIC=None):
    from string import upper
    from Numeric import zeros, sqrt
    if Bc is None: Bc = mmsecross()
    if METRIC is not None:
       METRIC = upper(METRIC)
    f = mmgray(f,'uint16')
    y = mmintersec(f,0)
    if (METRIC == 'EUCLIDEAN') or (METRIC == 'EUC2'):
        b = int32(zeros((3,3)))
        i=1
        while not mmisequal(f,y):
            a4,a2 = -4*i+2, -2*i+1
            b = int32([[a4,a2,a4],
                       [a2, 0,a2],
                       [a4,a2,a4]])
            y=f
            i=i+1
            f = mmero(f,b)
        if METRIC == 'EUCLIDEAN':
            f = uint16(sqrt(f)+0.5)
    else:
        if mmisequal(Bc, mmsecross()):
            b = int32([[-2147483647,  -1, -2147483647],
                       [         -1,   0,          -1],
                       [-2147483647,  -1, -2147483647]])
        elif mmisequal(Bc, mmsebox()):
            b = int32([[-1,-1,-1],
                       [-1, 0,-1],
                       [-1,-1,-1]])
        else: b = Bc
        while not mmisequal(f,y):
            y=f
            f = mmero(f,b)
    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/mmfreedom.html">mmfreedom</a></td>
              <td class="def">Control automatic data type conversion.</td>
            </tr>
            <tr>
              <td class="term"><a href="../morph/mmdtshow.html">mmdtshow</a></td>
              <td class="def">Display a distance transform image with an iso-line color table.</td>
            </tr>
            <tr>
              <td class="term"><a href="../morph/mmero.html">mmero</a></td>
              <td class="def">Erode an image by a structuring element.</td>
            </tr>
            <tr>
              <td class="term"><a href="../morph/mmgdist.html">mmgdist</a></td>
              <td class="def">Geodesic Distance Transform.</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>
          </tbody>
        </table>
      </div>
    </div>
    <center>
      <table class="botNav">
        <tr>
          <td class="index">
                    [<a href="../morph/mmopen.html"><tt>mmopen</tt></a>]
                
                    [<a href="index.html">Up</a>]
                    
                    [<a href="../morph/mmgdist.html"><tt>mmgdist</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>