<html> <head> <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"> <title>mmsubm</title> <link href="../tbxdok.css" rel="stylesheet"> </head> <body> <table class="topNav"> <tr> <td class="index"> [<a href="../morph/mmintersec.html"><tt>mmintersec</tt></a>] [<a href="index.html">Up</a>] [<a href="../morph/mmsymdif.html"><tt>mmsymdif</tt></a>] </td> <td class="title">Operations</td> </tr> </table> <h1>mmsubm <br> <span class="subtitle">Subtraction of two images, with saturation. </span> </h1> <div class="synopsis"> <H2>Synopsis</H2> <div class="H2"> <div class="prototype">y = <span class="fun">mmsubm</span>( <span class="par">f1</span>, <span class="par">f2</span> ) </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">f1</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">f2</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. <p>Or constant.</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">mmsubm</span> creates the image <code>y</code> by pixelwise subtraction of the image <code>f2</code> from the image <code>f1</code>. When the subtraction of the values of two pixels is negative, 0 is taken as the result of the subtraction. When <code>f1</code> and <code>f2</code> are binary images, <code>y</code> represents the set subtraction of <code>f2</code> from <code>f1</code>. </p> </div> </div> <div class="examples"> <H2>Examples</H2> <div class="H2"> <p> <div class="example"> <div class="listing"> <pre class="user">>>> f = uint8([255, 255, 0, 10, 20, 10, 0, 255, 255])</pre> <pre class="computer"></pre> <pre class="user">>>> g = uint8([10, 20, 30, 40, 50, 40, 30, 20, 10])</pre> <pre class="computer"></pre> <pre class="user">>>> print mmsubm(f, g)</pre> <pre class="computer">[245 235 0 0 0 0 0 235 245]</pre> <pre class="user">>>> print mmsubm(f, 100)</pre> <pre class="computer">Warning: Converting input image from int32 to uint8. [155 155 0 0 0 0 0 155 155]</pre> <pre class="user">>>> print mmsubm(100, f)</pre> <pre class="computer">Warning: Converting input image from uint8 to int32. [-155 -155 100 90 80 90 100 -155 -155]</pre> </div> </div> <div class="bridge">Gray scale image:</div> <div class="example"> <div class="listing"> <pre class="user">>>> a = mmreadgray('boxdrill-C.tif')</pre> <pre class="computer"></pre> <pre class="user">>>> b = mmreadgray('boxdrill-B.tif')</pre> <pre class="computer"></pre> <pre class="user">>>> c = mmsubm(a,b)</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> <pre class="user">>>> mmshow(c)</pre> <pre class="computer"></pre> </div> <table class="images"> <tbody align="center"> <tr class="image" valign="bottom"> <td><img width="185" src="../images/img_mmsubm_001.jpg"></td> <td><img width="185" src="../images/img_mmsubm_002.jpg"></td> <td><img width="185" src="../images/img_mmsubm_003.jpg"></td> <td class="spare"></td> </tr> <tr class="title" valign="baseline"> <td><a href="../images/img_mmsubm_001.jpg">a</a></td> <td><a href="../images/img_mmsubm_002.jpg">b</a></td> <td><a href="../images/img_mmsubm_003.jpg">c</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_mmsubm001.png"> </div> </p> </div> </div> <div class="sourcecode"> <H2>Source Code</H2> <div class="H2"> <pre class="listing"> def mmsubm(f1, f2): from Numeric import array, minimum, maximum if type(f2) is array: assert f1.typecode() == f2.typecode(), 'Cannot have different datatypes:' y = minimum(maximum(f1.astype('d')-f2, mmlimits(f1)[0]), mmlimits(f1)[1]) y = y.astype(f1.typecode()) 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/mmaddm.html">mmaddm</a></td> <td class="def">Addition of two images, with saturation.</td> </tr> </tbody> </table> </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/mmaddm.html">mmaddm</a></td> <td class="def">Addition of two images, with saturation.</td> </tr> <tr> <td class="term"><a href="../morph/mmlimits.html">mmlimits</a></td> <td class="def">Get the possible minimum and maximum of an image.</td> </tr> </tbody> </table> </div> </div> <center> <table class="botNav"> <tr> <td class="index"> [<a href="../morph/mmintersec.html"><tt>mmintersec</tt></a>] [<a href="index.html">Up</a>] [<a href="../morph/mmsymdif.html"><tt>mmsymdif</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>