<html> <head> <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"> <title>mmareaopen</title> <link href="../tbxdok.css" rel="stylesheet"> </head> <body> <table class="topNav"> <tr> <td class="index"> [<a href="../morph/mmareaclose.html"><tt>mmareaclose</tt></a>] [<a href="index.html">Up</a>] [<a href="../morph/mmasfrec.html"><tt>mmasfrec</tt></a>] </td> <td class="title">Connected Operators</td> </tr> </table> <h1>mmareaopen <br> <span class="subtitle">Area opening </span> </h1> <div class="synopsis"> <H2>Synopsis</H2> <div class="H2"> <div class="prototype">y = <span class="fun">mmareaopen</span>( <span class="par">f</span>, <span class="par">a</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> Gray-scale (uint8 or uint16) or binary image. </td> </tr> <tr> <td class="term"><span class="par">a</span></td> <td class="def"><span class="type"><a href="../mmtypes/mmDouble.html">Double</a></span><p>non negative integer.</p></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>Same type of <code>f</code> </p></td> </tr> </tbody> </table> </div> </div> </div> </div> <div class="descr"> <H2>Description</H2> <div class="H2"> <p> <span class="fun">mmareaopen</span> removes any grain (i.e., connected component) with area less than <code>a</code> of a binary image <code>f</code>. The connectivity is given by the structuring element <code>Bc</code>. This operator is generalized to gray-scale images by applying the binary operator successively on slices of <code>f</code> taken from higher threshold levels to lower threshold levels. </p> </div> </div> <div class="examples"> <H2>Examples</H2> <div class="H2"> <p> <div class="bridge">Numerical examples:</div> <div class="example"> <div class="listing"> <pre class="user">>>> f=mmbinary(uint8([ [1, 1, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 0, 1], [0, 0, 0, 0, 1, 0, 0]]))</pre> <pre class="computer"></pre> <pre class="user">>>> y=mmareaopen(f,4,mmsecross())</pre> <pre class="computer"></pre> <pre class="user">>>> print y</pre> <pre class="computer">[[0 0 0 0 0 0 0] [0 0 1 1 1 0 0] [0 0 0 0 1 0 0]]</pre> </div> </div> <div class="example"> <div class="listing"> <pre class="user">>>> f=uint8([ [10, 11, 0, 0, 0, 0, 20], [10, 0, 5, 8, 9, 0, 15], [10, 0, 0, 0, 10, 0, 0]])</pre> <pre class="computer"></pre> <pre class="user">>>> y=mmareaopen(f,4,mmsecross())</pre> <pre class="computer"></pre> <pre class="user">>>> print y</pre> <pre class="computer">[[10 10 0 0 0 0 0] [10 0 5 5 5 0 0] [10 0 0 0 5 0 0]]</pre> </div> </div> <div class="bridge">Binary image</div> <div class="example"> <div class="listing"> <pre class="user">>>> a=mmreadgray('form-1.tif');</pre> <pre class="computer"></pre> <pre class="user">>>> b=mmareaopen(a,500);</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="320" src="../images/img_mmareaopen_001.jpg"></td> <td><img width="320" src="../images/img_mmareaopen_002.jpg"></td> <td class="spare"></td> </tr> <tr class="title" valign="baseline"> <td><a href="../images/img_mmareaopen_001.jpg">a</a></td> <td><a href="../images/img_mmareaopen_002.jpg">b</a></td> <td class="spare"></td> </tr> </tbody> </table> </div> <div class="bridge">Gray-scale image</div> <div class="example"> <div class="listing"> <pre class="user">>>> a=mmreadgray('bloodcells.tif');</pre> <pre class="computer"></pre> <pre class="user">>>> b=mmareaopen(a,500);</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_mmareaopen_003.jpg"></td> <td><img width="256" src="../images/img_mmareaopen_004.jpg"></td> <td class="spare"></td> </tr> <tr class="title" valign="baseline"> <td><a href="../images/img_mmareaopen_003.jpg">a</a></td> <td><a href="../images/img_mmareaopen_004.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_mmareaopen001.png"> </div> </p> </div> </div> <div class="descr"> <H2>Limitations</H2> <div class="H2"> <p> The structuring elements allowed are the elementary cross (4-connected) and the elementary box (8-connected). </p> </div> </div> <div class="sourcecode"> <H2>Source Code</H2> <div class="H2"> <pre class="listing"> def mmareaopen(f, a, Bc=None): if Bc is None: Bc = mmsecross() if mmisbinary(f): fr = mmlabel(f,Bc) # binary area open, use area measurement g = mmblob(fr,'area') y = mmthreshad(g,a) else: y = mmintersec(f,0) zero = mmbinary(y) k1 = mmstats(f,'min') k2 = mmstats(f,'max') for k in range(k1,k2+1): # gray-scale, use thresholding decomposition fk = mmthreshad(f,k) fo = mmareaopen(fk,a,Bc) if mmisequal(fo,zero): break y = mmunion(y, mmgray(fo,mmdatatype(f),k)) 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/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/mmareaclose.html">mmareaclose</a></td> <td class="def">Area closing</td> </tr> </tbody> </table> </div> </div> <center> <table class="botNav"> <tr> <td class="index"> [<a href="../morph/mmareaclose.html"><tt>mmareaclose</tt></a>] [<a href="index.html">Up</a>] [<a href="../morph/mmasfrec.html"><tt>mmasfrec</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>