| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> |
| 5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> |
| 6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> |
| 7 | <link rel="first" href="lib.html" title='Python Library Reference' /> |
| 8 | <link rel='contents' href='contents.html' title="Contents" /> |
| 9 | <link rel='index' href='genindex.html' title='Index' /> |
| 10 | <link rel='last' href='about.html' title='About this document...' /> |
| 11 | <link rel='help' href='about.html' title='About this document...' /> |
| 12 | <link rel="next" href="module-aifc.html" /> |
| 13 | <link rel="prev" href="module-audioop.html" /> |
| 14 | <link rel="parent" href="mmedia.html" /> |
| 15 | <link rel="next" href="module-aifc.html" /> |
| 16 | <meta name='aesop' content='information' /> |
| 17 | <title>14.2 imageop -- Manipulate raw image data</title> |
| 18 | </head> |
| 19 | <body> |
| 20 | <DIV CLASS="navigation"> |
| 21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> |
| 22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 23 | <tr> |
| 24 | <td class='online-navigation'><a rel="prev" title="14.1 audioop " |
| 25 | href="module-audioop.html"><img src='../icons/previous.png' |
| 26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 27 | <td class='online-navigation'><a rel="parent" title="14. Multimedia Services" |
| 28 | href="mmedia.html"><img src='../icons/up.png' |
| 29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 30 | <td class='online-navigation'><a rel="next" title="14.3 aifc " |
| 31 | href="module-aifc.html"><img src='../icons/next.png' |
| 32 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 33 | <td align="center" width="100%">Python Library Reference</td> |
| 34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 35 | href="contents.html"><img src='../icons/contents.png' |
| 36 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 38 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 39 | <td class='online-navigation'><a rel="index" title="Index" |
| 40 | href="genindex.html"><img src='../icons/index.png' |
| 41 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 42 | </tr></table> |
| 43 | <div class='online-navigation'> |
| 44 | <b class="navlabel">Previous:</b> |
| 45 | <a class="sectref" rel="prev" href="module-audioop.html">14.1 audioop </A> |
| 46 | <b class="navlabel">Up:</b> |
| 47 | <a class="sectref" rel="parent" href="mmedia.html">14. Multimedia Services</A> |
| 48 | <b class="navlabel">Next:</b> |
| 49 | <a class="sectref" rel="next" href="module-aifc.html">14.3 aifc </A> |
| 50 | </div> |
| 51 | <hr /></div> |
| 52 | </DIV> |
| 53 | <!--End of Navigation Panel--> |
| 54 | |
| 55 | <H1><A NAME="SECTION0016200000000000000000"> |
| 56 | 14.2 <tt class="module">imageop</tt> -- |
| 57 | Manipulate raw image data</A> |
| 58 | </H1> |
| 59 | |
| 60 | <P> |
| 61 | <A NAME="module-imageop"></A> |
| 62 | |
| 63 | <P> |
| 64 | The <tt class="module">imageop</tt> module contains some useful operations on images. |
| 65 | It operates on images consisting of 8 or 32 bit pixels stored in |
| 66 | Python strings. This is the same format as used by |
| 67 | <tt class="function">gl.lrectwrite()</tt> and the <tt class="module"><a href="module-imgfile.html">imgfile</a></tt> module. |
| 68 | |
| 69 | <P> |
| 70 | The module defines the following variables and functions: |
| 71 | |
| 72 | <P> |
| 73 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-4622' xml:id='l2h-4622' class="exception">error</tt></b></dt> |
| 74 | <dd> |
| 75 | This exception is raised on all errors, such as unknown number of bits |
| 76 | per pixel, etc. |
| 77 | </dd></dl> |
| 78 | |
| 79 | <P> |
| 80 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 81 | <td><nobr><b><tt id='l2h-4623' xml:id='l2h-4623' class="function">crop</tt></b>(</nobr></td> |
| 82 | <td><var>image, psize, width, height, x0, y0, x1, y1</var>)</td></tr></table></dt> |
| 83 | <dd> |
| 84 | Return the selected part of <var>image</var>, which should by |
| 85 | <var>width</var> by <var>height</var> in size and consist of pixels of |
| 86 | <var>psize</var> bytes. <var>x0</var>, <var>y0</var>, <var>x1</var> and <var>y1</var> are like |
| 87 | the <tt class="function">gl.lrectread()</tt> parameters, i.e. the boundary is |
| 88 | included in the new image. The new boundaries need not be inside the |
| 89 | picture. Pixels that fall outside the old image will have their value |
| 90 | set to zero. If <var>x0</var> is bigger than <var>x1</var> the new image is |
| 91 | mirrored. The same holds for the y coordinates. |
| 92 | </dl> |
| 93 | |
| 94 | <P> |
| 95 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 96 | <td><nobr><b><tt id='l2h-4624' xml:id='l2h-4624' class="function">scale</tt></b>(</nobr></td> |
| 97 | <td><var>image, psize, width, height, newwidth, newheight</var>)</td></tr></table></dt> |
| 98 | <dd> |
| 99 | Return <var>image</var> scaled to size <var>newwidth</var> by <var>newheight</var>. |
| 100 | No interpolation is done, scaling is done by simple-minded pixel |
| 101 | duplication or removal. Therefore, computer-generated images or |
| 102 | dithered images will not look nice after scaling. |
| 103 | </dl> |
| 104 | |
| 105 | <P> |
| 106 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 107 | <td><nobr><b><tt id='l2h-4625' xml:id='l2h-4625' class="function">tovideo</tt></b>(</nobr></td> |
| 108 | <td><var>image, psize, width, height</var>)</td></tr></table></dt> |
| 109 | <dd> |
| 110 | Run a vertical low-pass filter over an image. It does so by computing |
| 111 | each destination pixel as the average of two vertically-aligned source |
| 112 | pixels. The main use of this routine is to forestall excessive |
| 113 | flicker if the image is displayed on a video device that uses |
| 114 | interlacing, hence the name. |
| 115 | </dl> |
| 116 | |
| 117 | <P> |
| 118 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 119 | <td><nobr><b><tt id='l2h-4626' xml:id='l2h-4626' class="function">grey2mono</tt></b>(</nobr></td> |
| 120 | <td><var>image, width, height, threshold</var>)</td></tr></table></dt> |
| 121 | <dd> |
| 122 | Convert a 8-bit deep greyscale image to a 1-bit deep image by |
| 123 | thresholding all the pixels. The resulting image is tightly packed and |
| 124 | is probably only useful as an argument to <tt class="function">mono2grey()</tt>. |
| 125 | </dl> |
| 126 | |
| 127 | <P> |
| 128 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 129 | <td><nobr><b><tt id='l2h-4627' xml:id='l2h-4627' class="function">dither2mono</tt></b>(</nobr></td> |
| 130 | <td><var>image, width, height</var>)</td></tr></table></dt> |
| 131 | <dd> |
| 132 | Convert an 8-bit greyscale image to a 1-bit monochrome image using a |
| 133 | (simple-minded) dithering algorithm. |
| 134 | </dl> |
| 135 | |
| 136 | <P> |
| 137 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 138 | <td><nobr><b><tt id='l2h-4628' xml:id='l2h-4628' class="function">mono2grey</tt></b>(</nobr></td> |
| 139 | <td><var>image, width, height, p0, p1</var>)</td></tr></table></dt> |
| 140 | <dd> |
| 141 | Convert a 1-bit monochrome image to an 8 bit greyscale or color image. |
| 142 | All pixels that are zero-valued on input get value <var>p0</var> on output |
| 143 | and all one-value input pixels get value <var>p1</var> on output. To |
| 144 | convert a monochrome black-and-white image to greyscale pass the |
| 145 | values <code>0</code> and <code>255</code> respectively. |
| 146 | </dl> |
| 147 | |
| 148 | <P> |
| 149 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 150 | <td><nobr><b><tt id='l2h-4629' xml:id='l2h-4629' class="function">grey2grey4</tt></b>(</nobr></td> |
| 151 | <td><var>image, width, height</var>)</td></tr></table></dt> |
| 152 | <dd> |
| 153 | Convert an 8-bit greyscale image to a 4-bit greyscale image without |
| 154 | dithering. |
| 155 | </dl> |
| 156 | |
| 157 | <P> |
| 158 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 159 | <td><nobr><b><tt id='l2h-4630' xml:id='l2h-4630' class="function">grey2grey2</tt></b>(</nobr></td> |
| 160 | <td><var>image, width, height</var>)</td></tr></table></dt> |
| 161 | <dd> |
| 162 | Convert an 8-bit greyscale image to a 2-bit greyscale image without |
| 163 | dithering. |
| 164 | </dl> |
| 165 | |
| 166 | <P> |
| 167 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 168 | <td><nobr><b><tt id='l2h-4631' xml:id='l2h-4631' class="function">dither2grey2</tt></b>(</nobr></td> |
| 169 | <td><var>image, width, height</var>)</td></tr></table></dt> |
| 170 | <dd> |
| 171 | Convert an 8-bit greyscale image to a 2-bit greyscale image with |
| 172 | dithering. As for <tt class="function">dither2mono()</tt>, the dithering algorithm |
| 173 | is currently very simple. |
| 174 | </dl> |
| 175 | |
| 176 | <P> |
| 177 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 178 | <td><nobr><b><tt id='l2h-4632' xml:id='l2h-4632' class="function">grey42grey</tt></b>(</nobr></td> |
| 179 | <td><var>image, width, height</var>)</td></tr></table></dt> |
| 180 | <dd> |
| 181 | Convert a 4-bit greyscale image to an 8-bit greyscale image. |
| 182 | </dl> |
| 183 | |
| 184 | <P> |
| 185 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 186 | <td><nobr><b><tt id='l2h-4633' xml:id='l2h-4633' class="function">grey22grey</tt></b>(</nobr></td> |
| 187 | <td><var>image, width, height</var>)</td></tr></table></dt> |
| 188 | <dd> |
| 189 | Convert a 2-bit greyscale image to an 8-bit greyscale image. |
| 190 | </dl> |
| 191 | |
| 192 | <P> |
| 193 | <dl><dt><b><tt id='l2h-4634' xml:id='l2h-4634'>backward_compatible</tt></b></dt> |
| 194 | <dd> |
| 195 | If set to 0, the functions in this module use a non-backward |
| 196 | compatible way of representing multi-byte pixels on little-endian |
| 197 | systems. The SGI for which this module was originally written is a |
| 198 | big-endian system, so setting this variable will have no effect. |
| 199 | However, the code wasn't originally intended to run on anything else, |
| 200 | so it made assumptions about byte order which are not universal. |
| 201 | Setting this variable to 0 will cause the byte order to be reversed on |
| 202 | little-endian systems, so that it then is the same as on big-endian |
| 203 | systems. |
| 204 | </dd></dl> |
| 205 | |
| 206 | <DIV CLASS="navigation"> |
| 207 | <div class='online-navigation'> |
| 208 | <p></p><hr /> |
| 209 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 210 | <tr> |
| 211 | <td class='online-navigation'><a rel="prev" title="14.1 audioop " |
| 212 | href="module-audioop.html"><img src='../icons/previous.png' |
| 213 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 214 | <td class='online-navigation'><a rel="parent" title="14. Multimedia Services" |
| 215 | href="mmedia.html"><img src='../icons/up.png' |
| 216 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 217 | <td class='online-navigation'><a rel="next" title="14.3 aifc " |
| 218 | href="module-aifc.html"><img src='../icons/next.png' |
| 219 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 220 | <td align="center" width="100%">Python Library Reference</td> |
| 221 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 222 | href="contents.html"><img src='../icons/contents.png' |
| 223 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 224 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 225 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 226 | <td class='online-navigation'><a rel="index" title="Index" |
| 227 | href="genindex.html"><img src='../icons/index.png' |
| 228 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 229 | </tr></table> |
| 230 | <div class='online-navigation'> |
| 231 | <b class="navlabel">Previous:</b> |
| 232 | <a class="sectref" rel="prev" href="module-audioop.html">14.1 audioop </A> |
| 233 | <b class="navlabel">Up:</b> |
| 234 | <a class="sectref" rel="parent" href="mmedia.html">14. Multimedia Services</A> |
| 235 | <b class="navlabel">Next:</b> |
| 236 | <a class="sectref" rel="next" href="module-aifc.html">14.3 aifc </A> |
| 237 | </div> |
| 238 | </div> |
| 239 | <hr /> |
| 240 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 241 | </DIV> |
| 242 | <!--End of Navigation Panel--> |
| 243 | <ADDRESS> |
| 244 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 245 | </ADDRESS> |
| 246 | </BODY> |
| 247 | </HTML> |