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