<html> <head> <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"> <title>mmdlabeltext</title> <link href="../tbxdok.css" rel="stylesheet"> </head> <body> <table class="topNav"> <tr> <td class="index"> [<a href="../mmdemos/mmdasp.html"><tt>mmdasp</tt></a>] [<a href="index.html">Up</a>] [<a href="../mmdemos/mmdbeef.html"><tt>mmdbeef</tt></a>] </td> <td class="title">Demonstrations</td> </tr> </table> <h1>mmdlabeltext <br> <span class="subtitle">Segmenting letters, words and paragraphs. </span> </h1> <div class="descr"> <H2>Description</H2> <div class="H2"> <p> In this example, a digitized text is processed to identify the letters, words and paragraphs. This demonstration uses only the <span class="fun">mmlabel</span> function with different connectivity parameters. </p> </div> </div> <div class="script"> <H2>Demo Script</H2> <div class="H2"> <div class="slide"> <H3>Reading</H3> <div class="H3"> <p> <p> The text image is read. </p> <div class="example"> <div class="listing"> <pre class="user">>>> f = mmreadgray('stext.tif')</pre> <pre class="computer"></pre> <pre class="user">>>> mmshow(f)</pre> <pre class="computer"></pre> </div> <table class="images"> <tbody align="center"> <tr class="image" valign="bottom"> <td><img width="320" src="../images/img_mmdlabeltext_001.jpg"></td> <td class="spare"></td> </tr> <tr class="title" valign="baseline"> <td><a href="../images/img_mmdlabeltext_001.jpg">f</a></td> <td class="spare"></td> </tr> </tbody> </table> </div> </p> </div> </div> <div class="slide"> <H3>First, label the letters.</H3> <div class="H3"> <p> <p> The letters are the main connected components in the image. So we use the classical 8-connectivity criteria for identify each letter. </p> <div class="example"> <div class="listing"> <pre class="user">>>> fl=mmlabel(f,mmsebox())</pre> <pre class="computer"></pre> <pre class="user">>>> mmlblshow(fl)</pre> <pre class="computer"></pre> </div> <table class="images"> <tbody align="center"> <tr class="image" valign="bottom"> <td><img width="320" src="../images/img_mmdlabeltext_002.jpg"></td> <td class="spare"></td> </tr> <tr class="title" valign="baseline"> <td><a href="../images/img_mmdlabeltext_002.jpg">fl</a></td> <td class="spare"></td> </tr> </tbody> </table> </div> </p> </div> </div> <div class="slide"> <H3>Second, label the words.</H3> <div class="H3"> <p> <p> The words are made of closed letters. In this case we use a connectivity specified by a rectangle structuring element of 7 pixels high and 11 pixels width, so any two pixels that can be hit by this rectangle, belong to the same connected component. The values 7 and 11 were chosen experimentally and depend on the font size. </p> <div class="example"> <div class="listing"> <pre class="user">>>> from Numeric import ones</pre> <pre class="computer"></pre> <pre class="user">>>> sew = mmimg2se(mmbinary(ones((7,11))))</pre> <pre class="computer"></pre> <pre class="user">>>> mmseshow(sew)</pre> <pre class="computer">array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]],'1')</pre> <pre class="user">>>> fw=mmlabel(f,sew)</pre> <pre class="computer"></pre> <pre class="user">>>> mmlblshow(fw)</pre> <pre class="computer"></pre> </div> <table class="images"> <tbody align="center"> <tr class="image" valign="bottom"> <td><img width="320" src="../images/img_mmdlabeltext_003.jpg"></td> <td class="spare"></td> </tr> <tr class="title" valign="baseline"> <td><a href="../images/img_mmdlabeltext_003.jpg">fw</a></td> <td class="spare"></td> </tr> </tbody> </table> </div> </p> </div> </div> <div class="slide"> <H3>Finally, label the paragraphs.</H3> <div class="H3"> <p> <p> Similarly, paragraphs are closed words. In this case the connectivity is given by a rectangle of 35 by 20 pixels. </p> <div class="example"> <div class="listing"> <pre class="user">>>> sep = mmimg2se(mmbinary(ones((20,35))))</pre> <pre class="computer"></pre> <pre class="user">>>> fp=mmlabel(f,sep)</pre> <pre class="computer"></pre> <pre class="user">>>> mmlblshow(fp)</pre> <pre class="computer"></pre> </div> <table class="images"> <tbody align="center"> <tr class="image" valign="bottom"> <td><img width="320" src="../images/img_mmdlabeltext_004.jpg"></td> <td class="spare"></td> </tr> <tr class="title" valign="baseline"> <td><a href="../images/img_mmdlabeltext_004.jpg">fp</a></td> <td class="spare"></td> </tr> </tbody> </table> </div> </p> </div> </div> </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> </tbody> </table> </div> </div> <center> <table class="botNav"> <tr> <td class="index"> [<a href="../mmdemos/mmdasp.html"><tt>mmdasp</tt></a>] [<a href="index.html">Up</a>] [<a href="../mmdemos/mmdbeef.html"><tt>mmdbeef</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>