<html> <head> <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"> <title>mmbinary</title> <link href="../tbxdok.css" rel="stylesheet"> </head> <body> <table class="topNav"> <tr> <td class="index"> [<a href="index.html">Up</a>] [<a href="../morph/mmfreedom.html"><tt>mmfreedom</tt></a>] </td> <td class="title">Data Type Conversion</td> </tr> </table> <h1>mmbinary <br> <span class="subtitle">Convert a gray-scale image into a binary image </span> </h1> <div class="synopsis"> <H2>Synopsis</H2> <div class="H2"> <div class="prototype">y = <span class="fun">mmbinary</span>( <span class="par">f</span>, <span class="par">k1</span> = 1 ) </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> Unsigned gray-scale (uint8 or uint16), signed (int32) or binary image. </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><p>Threshold value.</p><p>Default: <code>1</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> Binary image. </td> </tr> </tbody> </table> </div> </div> </div> </div> <div class="descr"> <H2>Description</H2> <div class="H2"> <p> <span class="fun">mmbinary</span> converts a gray-scale image <code>f</code> into a binary image <code>y</code> by a threshold rule. A pixel in <code>y</code> has the value 1 if and only if the corresponding pixel in <code>f</code> has a value greater or equal <code>k1</code>. </p> </div> </div> <div class="examples"> <H2>Examples</H2> <div class="H2"> <p> <div class="example"> <div class="listing"> <pre class="user">>>> a = array([0, 1, 2, 3, 4])</pre> <pre class="computer"></pre> <pre class="user">>>> b=mmbinary(a)</pre> <pre class="computer"></pre> <pre class="user">>>> print b </pre> <pre class="computer">[0 1 1 1 1]</pre> </div> </div> <div class="example"> <div class="listing"> <pre class="user">>>> a=mmreadgray('mm3.tif')</pre> <pre class="computer"></pre> <pre class="user">>>> b=mmbinary(a,82)</pre> <pre class="computer"></pre> <pre class="user">>>> mmshow(a)</pre> <pre class="computer"></pre> <pre class="user">>>> mmshow(b) </pre> <pre class="computer"></pre> </div> <table class="images"> <tbody align="center"> <tr class="image" valign="bottom"> <td><img width="256" src="../images/img_mmbinary_001.jpg"></td> <td><img width="256" src="../images/img_mmbinary_002.jpg"></td> <td class="spare"></td> </tr> <tr class="title" valign="baseline"> <td><a href="../images/img_mmbinary_001.jpg">a</a></td> <td><a href="../images/img_mmbinary_002.jpg">b</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_mmbinary001.png"> </div> </p> </div> </div> <div class="sourcecode"> <H2>Source Code</H2> <div class="H2"> <pre class="listing"> def mmbinary(f, k1=1): from Numeric import array if type(f) is not array: f = array(f) y = array(f>=k1).astype('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/mmthreshad.html">mmthreshad</a></td> <td class="def">Threshold (adaptive)</td> </tr> <tr> <td class="term"><a href="../morph/mmisbinary.html">mmisbinary</a></td> <td class="def">Check for binary image</td> </tr> <tr> <td class="term"><a href="../morph/mmgray.html">mmgray</a></td> <td class="def">Convert a binary image into a gray-scale image.</td> </tr> </tbody> </table> </div> </div> <center> <table class="botNav"> <tr> <td class="index"> [<a href="index.html">Up</a>] [<a href="../morph/mmfreedom.html"><tt>mmfreedom</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>