blob: 48f9188009b3934e0fb38127a5598b40d4fc90df [file] [log] [blame]
Guido van Rossum470be141995-03-17 16:07:09 +00001\section{Built-in Module \sectcode{imageop}}
Guido van Rossume47da0a1997-07-17 16:34:52 +00002\label{module-imageop}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00003\bimodindex{imageop}
4
Guido van Rossum6bb1adc1995-03-13 10:03:32 +00005The \code{imageop} module contains some useful operations on images.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00006It operates on images consisting of 8 or 32 bit pixels
Guido van Rossum470be141995-03-17 16:07:09 +00007stored in Python strings. This is the same format as used
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00008by \code{gl.lrectwrite} and the \code{imgfile} module.
9
10The module defines the following variables and functions:
11
12\renewcommand{\indexsubitem}{(in module imageop)}
13
14\begin{excdesc}{error}
15This exception is raised on all errors, such as unknown number of bits
16per pixel, etc.
17\end{excdesc}
18
19
20\begin{funcdesc}{crop}{image\, psize\, width\, height\, x0\, y0\, x1\, y1}
Guido van Rossum470be141995-03-17 16:07:09 +000021Return the selected part of \var{image}, which should by
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000022\var{width} by \var{height} in size and consist of pixels of
Guido van Rossum470be141995-03-17 16:07:09 +000023\var{psize} bytes. \var{x0}, \var{y0}, \var{x1} and \var{y1} are like
24the \code{lrectread} parameters, i.e.\ the boundary is included in the
25new image. The new boundaries need not be inside the picture. Pixels
26that fall outside the old image will have their value set to zero. If
27\var{x0} is bigger than \var{x1} the new image is mirrored. The same
28holds for the y coordinates.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000029\end{funcdesc}
30
31\begin{funcdesc}{scale}{image\, psize\, width\, height\, newwidth\, newheight}
Guido van Rossum470be141995-03-17 16:07:09 +000032Return \var{image} scaled to size \var{newwidth} by \var{newheight}.
33No interpolation is done, scaling is done by simple-minded pixel
34duplication or removal. Therefore, computer-generated images or
35dithered images will not look nice after scaling.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000036\end{funcdesc}
37
38\begin{funcdesc}{tovideo}{image\, psize\, width\, height}
Guido van Rossum470be141995-03-17 16:07:09 +000039Run a vertical low-pass filter over an image. It does so by computing
40each destination pixel as the average of two vertically-aligned source
41pixels. The main use of this routine is to forestall excessive
42flicker if the image is displayed on a video device that uses
43interlacing, hence the name.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000044\end{funcdesc}
45
46\begin{funcdesc}{grey2mono}{image\, width\, height\, threshold}
Guido van Rossum470be141995-03-17 16:07:09 +000047Convert a 8-bit deep greyscale image to a 1-bit deep image by
48tresholding all the pixels. The resulting image is tightly packed and
49is probably only useful as an argument to \code{mono2grey}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000050\end{funcdesc}
51
52\begin{funcdesc}{dither2mono}{image\, width\, height}
Guido van Rossum470be141995-03-17 16:07:09 +000053Convert an 8-bit greyscale image to a 1-bit monochrome image using a
54(simple-minded) dithering algorithm.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000055\end{funcdesc}
56
57\begin{funcdesc}{mono2grey}{image\, width\, height\, p0\, p1}
Guido van Rossum470be141995-03-17 16:07:09 +000058Convert a 1-bit monochrome image to an 8 bit greyscale or color image.
59All pixels that are zero-valued on input get value \var{p0} on output
60and all one-value input pixels get value \var{p1} on output. To
61convert a monochrome black-and-white image to greyscale pass the
62values \code{0} and \code{255} respectively.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000063\end{funcdesc}
64
65\begin{funcdesc}{grey2grey4}{image\, width\, height}
66Convert an 8-bit greyscale image to a 4-bit greyscale image without
67dithering.
68\end{funcdesc}
69
70\begin{funcdesc}{grey2grey2}{image\, width\, height}
71Convert an 8-bit greyscale image to a 2-bit greyscale image without
72dithering.
73\end{funcdesc}
74
75\begin{funcdesc}{dither2grey2}{image\, width\, height}
76Convert an 8-bit greyscale image to a 2-bit greyscale image with
Guido van Rossum470be141995-03-17 16:07:09 +000077dithering. As for \code{dither2mono}, the dithering algorithm is
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000078currently very simple.
79\end{funcdesc}
80
81\begin{funcdesc}{grey42grey}{image\, width\, height}
82Convert a 4-bit greyscale image to an 8-bit greyscale image.
83\end{funcdesc}
84
85\begin{funcdesc}{grey22grey}{image\, width\, height}
86Convert a 2-bit greyscale image to an 8-bit greyscale image.
87\end{funcdesc}