Sophie

Sophie

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

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

<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">
    <title>mmgray</title>
    <link href="../tbxdok.css" rel="stylesheet">
  </head>
  <body>
    <table class="topNav">
      <tr>
        <td class="index">
                  [<a href="../morph/mmfreedom.html"><tt>mmfreedom</tt></a>]
              
                  [<a href="index.html">Up</a>]
                  
                  [<a href="../morph/int32.html"><tt>int32</tt></a>]
              </td>
        <td class="title">Data Type Conversion</td>
      </tr>
    </table>
    <h1>mmgray
      <br>
      <span class="subtitle">Convert a binary image into a gray-scale image.
</span>
    </h1>
    <div class="synopsis">
      <H2>Synopsis</H2>
      <div class="H2">
        <div class="prototype">y = 
          <span class="fun">mmgray</span>(
                  
          <span class="par">f</span>, 
          <span class="par">TYPE</span> = "uint8", 
          <span class="par">k1</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">TYPE</span></td>
                  <td class="def"><span class="type"><a href="../mmtypes/mmString.html">String</a></span><p>'uint8', 'uint16', or 'int32'.</p><p>Default: 
                      <code>"uint8"</code>
                    </p></td>
                </tr>
                <tr>
                  <td class="term"><span class="par">k1</span></td>
                  <td class="def"><span class="type"><a href="../mmtypes/mmDouble.html">Double</a></span>      Non-negative integer.
                                <p>Default: 
                      <code>None</code> (Maximum pixel level in pixel type)
                    </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>          Unsigned gray-scale (uint8 or uint16), signed (int32) or binary image.
                        </td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
    <div class="descr">
      <H2>Description</H2>
      <div class="H2">
        <p>
          <span class="fun">mmgray</span> converts a binary image into a gray-scale image of a specified data type. The value 
          <code>k1</code> is assigned to the 1 pixels of  
          <code>f</code>, while the 0 pixels are assigned to the minimum value associated to the specified data type.
                  
        </p>
      </div>
    </div>
    <div class="examples">
      <H2>Examples</H2>
      <div class="H2">
        <p>
          <div class="example">
            <div class="listing">
              <pre class="user">&gt;&gt;&gt; b=mmbinary([0, 1, 0, 1])</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; print b</pre>
              <pre class="computer">[0 1 0 1]</pre>
              <pre class="user">&gt;&gt;&gt; c=mmgray(b)</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; print c</pre>
              <pre class="computer">[  0 255   0 255]</pre>
              <pre class="user">&gt;&gt;&gt; d=mmgray(b,'uint8',100)</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; print d</pre>
              <pre class="computer">[  0 100   0 100]</pre>
              <pre class="user">&gt;&gt;&gt; e=mmgray(b,'uint16')</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; print e</pre>
              <pre class="computer">[    0 65535     0 65535]</pre>
              <pre class="user">&gt;&gt;&gt; f=mmgray(b,'int32',0)</pre>
              <pre class="computer"></pre>
              <pre class="user">&gt;&gt;&gt; print f</pre>
              <pre class="computer">[-2147483647           0 -2147483647           0]</pre>
            </div>
          </div>
        </p>
      </div>
    </div>
    <div class="equation">
      <H2>Equation</H2>
      <div class="H2">
        <p>
          <div class="eqfig">
            <img src="../images/eq_mmgray001.png">
          </div>
        </p>
      </div>
    </div>
    <div class="sourcecode">
      <H2>Source Code</H2>
      <div class="H2">
        <pre class="listing">
def mmgray(f, TYPE="uint8", k1=None):
    from Numeric import array
    if k1 is None: k1 = mmmaxleveltype(TYPE)
    if type(f) is list: f = mmbinary(f)
    assert mmis(f,'binary'), 'f must be binary'
    if k1==None:
        k1=mmmaxleveltype(TYPE)
    if   TYPE == 'uint8' : y = uint8(f*k1)
    elif TYPE == 'uint16': y = uint16(f*k1)
    elif TYPE == 'int32' : y = int32(f*k1) - int32(mmneg(f)*mmmaxleveltype(TYPE))
    else:
        assert 0, 'type not supported:'+TYPE
    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/mmbinary.html">mmbinary</a></td>
              <td class="def">Convert a gray-scale image into a binary image</td>
            </tr>
            <tr>
              <td class="term"><a href="../morph/mmthreshad.html">mmthreshad</a></td>
              <td class="def">Threshold (adaptive)</td>
            </tr>
            <tr>
              <td class="term"><a href="../morph/mmis.html">mmis</a></td>
              <td class="def">Verify if a relationship among images is true or false.</td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
    <center>
      <table class="botNav">
        <tr>
          <td class="index">
                    [<a href="../morph/mmfreedom.html"><tt>mmfreedom</tt></a>]
                
                    [<a href="index.html">Up</a>]
                    
                    [<a href="../morph/int32.html"><tt>int32</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>