blob: 836ae7655b99d06395a9e05034695e6d0bef3936 [file] [log] [blame]
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001\section{Built-in module \sectcode{imageop}}
2\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 Rossum6bb1adc1995-03-13 10:03:32 +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 Rossum6bb1adc1995-03-13 10:03:32 +000020This function takes the image in \var{image}, which should by
21\var{width} by \var{height} in size and consist of pixels of
22\var{psize} bytes, and returns the selected part of that image. \var{x0},
23\var{y0}, \var{x1} and \var{y1} are like the \code{lrectread}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000024parameters, i.e. the boundary is included in the new image.
25The new boundaries need not be inside the picture. Pixels that fall
26outside the old image will have their value set to zero.
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000027If \var{x0} is bigger than \var{x1} the new image is mirrored. The
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000028same holds for the y coordinates.
29\end{funcdesc}
30
31\begin{funcdesc}{scale}{image\, psize\, width\, height\, newwidth\, newheight}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000032This function returns an \var{image} scaled to size \var{newwidth} by
33\var{newheight}. No interpolation is done, scaling is done by
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000034simple-minded pixel duplication or removal. Therefore, computer-generated
35images or dithered images will not look nice after scaling.
36\end{funcdesc}
37
38\begin{funcdesc}{tovideo}{image\, psize\, width\, height}
39This function runs a vertical low-pass filter over an image. It does
40so by computing each destination pixel as the average of two
41vertically-aligned source pixels. The main use of this routine is to
42forestall excessive flicker if the image is displayed on a video
43device that uses interlacing, hence the name.
44\end{funcdesc}
45
46\begin{funcdesc}{grey2mono}{image\, width\, height\, threshold}
47This function converts a 8-bit deep greyscale image to a 1-bit deep
48image by tresholding all the pixels. The resulting image is tightly
49packed and is probably only useful as an argument to \code{mono2grey}.
50\end{funcdesc}
51
52\begin{funcdesc}{dither2mono}{image\, width\, height}
53This function also converts an 8-bit greyscale image to a 1-bit
54monochrome image but it uses a (simple-minded) dithering algorithm.
55\end{funcdesc}
56
57\begin{funcdesc}{mono2grey}{image\, width\, height\, p0\, p1}
58This function converts a 1-bit monochrome image to an 8 bit greyscale
59or color image. All pixels that are zero-valued on input get value
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000060\var{p0} on output and all one-value input pixels get value \var{p1}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000061on output. To convert a monochrome black-and-white image to greyscale
62pass the values \code{0} and \code{255} respectively.
63\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
77dithering. As for \code{dither2mono}, the dithering algorithm is
78currently 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}