📄 module-imageop.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>14.2 imageop -- Manipulate raw image data</title>
<META NAME="description" CONTENT="14.2 imageop -- Manipulate raw image data">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" href="module-aifc.html" tppabs="http://www.python.org/doc/current/lib/module-aifc.html">
<LINK REL="previous" href="module-audioop.html" tppabs="http://www.python.org/doc/current/lib/module-audioop.html">
<LINK REL="up" href="mmedia.html" tppabs="http://www.python.org/doc/current/lib/mmedia.html">
<LINK REL="next" href="module-aifc.html" tppabs="http://www.python.org/doc/current/lib/module-aifc.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-audioop.html" tppabs="http://www.python.org/doc/current/lib/module-audioop.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="mmedia.html" tppabs="http://www.python.org/doc/current/lib/mmedia.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="module-aifc.html" tppabs="http://www.python.org/doc/current/lib/module-aifc.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-audioop.html" tppabs="http://www.python.org/doc/current/lib/module-audioop.html">14.1 audioop </A>
<b class="navlabel">Up:</b> <a class="sectref" href="mmedia.html" tppabs="http://www.python.org/doc/current/lib/mmedia.html">14. Multimedia Services</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-aifc.html" tppabs="http://www.python.org/doc/current/lib/module-aifc.html">14.3 aifc </A>
<br><hr></DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION0016200000000000000000">
14.2 <tt class="module">imageop</tt> --
Manipulate raw image data</A>
</H1>
<P>
<P>
The <tt class="module">imageop</tt> module contains some useful operations on images.
It operates on images consisting of 8 or 32 bit pixels stored in
Python strings. This is the same format as used by
<tt class="function">gl.lrectwrite()</tt> and the <tt class='module'><a href="module-imgfile.html" tppabs="http://www.python.org/doc/current/lib/module-imgfile.html">imgfile</a></tt> module.
<P>
The module defines the following variables and functions:
<P>
<dl><dt><b><a name='l2h-2794'><tt class='exception'>error</tt></a></b>
<dd>
This exception is raised on all errors, such as unknown number of bits
per pixel, etc.
</dl>
<P>
<dl><dt><b><a name='l2h-2795'><tt class='function'>crop</tt></a></b> (<var>image, psize, width, height, x0, y0, x1, y1</var>)
<dd>
Return the selected part of <var>image</var>, which should by
<var>width</var> by <var>height</var> in size and consist of pixels of
<var>psize</var> bytes. <var>x0</var>, <var>y0</var>, <var>x1</var> and <var>y1</var> are like
the <tt class="function">gl.lrectread()</tt> parameters, i.e. the boundary is
included in the new image. The new boundaries need not be inside the
picture. Pixels that fall outside the old image will have their value
set to zero. If <var>x0</var> is bigger than <var>x1</var> the new image is
mirrored. The same holds for the y coordinates.
</dl>
<P>
<dl><dt><b><a name='l2h-2796'><tt class='function'>scale</tt></a></b> (<var>image, psize, width, height, newwidth, newheight</var>)
<dd>
Return <var>image</var> scaled to size <var>newwidth</var> by <var>newheight</var>.
No interpolation is done, scaling is done by simple-minded pixel
duplication or removal. Therefore, computer-generated images or
dithered images will not look nice after scaling.
</dl>
<P>
<dl><dt><b><a name='l2h-2797'><tt class='function'>tovideo</tt></a></b> (<var>image, psize, width, height</var>)
<dd>
Run a vertical low-pass filter over an image. It does so by computing
each destination pixel as the average of two vertically-aligned source
pixels. The main use of this routine is to forestall excessive
flicker if the image is displayed on a video device that uses
interlacing, hence the name.
</dl>
<P>
<dl><dt><b><a name='l2h-2798'><tt class='function'>grey2mono</tt></a></b> (<var>image, width, height, threshold</var>)
<dd>
Convert a 8-bit deep greyscale image to a 1-bit deep image by
thresholding all the pixels. The resulting image is tightly packed and
is probably only useful as an argument to <tt class="function">mono2grey()</tt>.
</dl>
<P>
<dl><dt><b><a name='l2h-2799'><tt class='function'>dither2mono</tt></a></b> (<var>image, width, height</var>)
<dd>
Convert an 8-bit greyscale image to a 1-bit monochrome image using a
(simple-minded) dithering algorithm.
</dl>
<P>
<dl><dt><b><a name='l2h-2800'><tt class='function'>mono2grey</tt></a></b> (<var>image, width, height, p0, p1</var>)
<dd>
Convert a 1-bit monochrome image to an 8 bit greyscale or color image.
All pixels that are zero-valued on input get value <var>p0</var> on output
and all one-value input pixels get value <var>p1</var> on output. To
convert a monochrome black-and-white image to greyscale pass the
values <code>0</code> and <code>255</code> respectively.
</dl>
<P>
<dl><dt><b><a name='l2h-2801'><tt class='function'>grey2grey4</tt></a></b> (<var>image, width, height</var>)
<dd>
Convert an 8-bit greyscale image to a 4-bit greyscale image without
dithering.
</dl>
<P>
<dl><dt><b><a name='l2h-2802'><tt class='function'>grey2grey2</tt></a></b> (<var>image, width, height</var>)
<dd>
Convert an 8-bit greyscale image to a 2-bit greyscale image without
dithering.
</dl>
<P>
<dl><dt><b><a name='l2h-2803'><tt class='function'>dither2grey2</tt></a></b> (<var>image, width, height</var>)
<dd>
Convert an 8-bit greyscale image to a 2-bit greyscale image with
dithering. As for <tt class="function">dither2mono()</tt>, the dithering algorithm
is currently very simple.
</dl>
<P>
<dl><dt><b><a name='l2h-2804'><tt class='function'>grey42grey</tt></a></b> (<var>image, width, height</var>)
<dd>
Convert a 4-bit greyscale image to an 8-bit greyscale image.
</dl>
<P>
<dl><dt><b><a name='l2h-2805'><tt class='function'>grey22grey</tt></a></b> (<var>image, width, height</var>)
<dd>
Convert a 2-bit greyscale image to an 8-bit greyscale image.
</dl>
<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-audioop.html" tppabs="http://www.python.org/doc/current/lib/module-audioop.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="mmedia.html" tppabs="http://www.python.org/doc/current/lib/mmedia.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="module-aifc.html" tppabs="http://www.python.org/doc/current/lib/module-aifc.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-audioop.html" tppabs="http://www.python.org/doc/current/lib/module-audioop.html">14.1 audioop </A>
<b class="navlabel">Up:</b> <a class="sectref" href="mmedia.html" tppabs="http://www.python.org/doc/current/lib/mmedia.html">14. Multimedia Services</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-aifc.html" tppabs="http://www.python.org/doc/current/lib/module-aifc.html">14.3 aifc </A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -