<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--Converted with LaTeX2HTML 98.2 beta6 (August 14th, 1998)
original version by:  Nikos Drakos, CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<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">
<LINK REL="next" HREF="module-aifc.html">
<LINK REL="previous" HREF="module-audioop.html">
<LINK REL="up" HREF="mmedia.html">
<LINK REL="next" HREF="module-aifc.html">
</HEAD>
<BODY bgcolor="#ffffff">
<div class=navigation>
<table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="module-aifc.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="mmedia.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="module-audioop.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python Library Reference</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="module-aifc.html">14.3 aifc  </A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="mmedia.html">14. Multimedia Services</A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="module-audioop.html">14.1 audioop  </A></span>
<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">imgfile</a></tt> module.

<P>
The module defines the following variables and functions:

<P>
<dl><dt><b><a name="l2h-2223"><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-2224"><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-2225"><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-2226"><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-2227"><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
tresholding 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-2228"><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-2229"><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 <tt>0</tt> and <tt>255</tt> respectively.
</dl>

<P>
<dl><dt><b><a name="l2h-2230"><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-2231"><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-2232"><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-2233"><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-2234"><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><p>
<div class=navigation><hr><table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="module-aifc.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="mmedia.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="module-audioop.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python Library Reference</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="module-aifc.html">14.3 aifc  </A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="mmedia.html">14. Multimedia Services</A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="module-audioop.html">14.1 audioop  </A></span>
</div>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>Send comments on this document to <a href="mailto:python-docs@python.org">python-docs@python.org</a>.
</ADDRESS>
</BODY>
</HTML>
