1 | \section{\module{imageop} ---
|
---|
2 | Manipulate raw image data}
|
---|
3 |
|
---|
4 | \declaremodule{builtin}{imageop}
|
---|
5 | \modulesynopsis{Manipulate raw image data.}
|
---|
6 |
|
---|
7 |
|
---|
8 | The \module{imageop} module contains some useful operations on images.
|
---|
9 | It operates on images consisting of 8 or 32 bit pixels stored in
|
---|
10 | Python strings. This is the same format as used by
|
---|
11 | \function{gl.lrectwrite()} and the \refmodule{imgfile} module.
|
---|
12 |
|
---|
13 | The module defines the following variables and functions:
|
---|
14 |
|
---|
15 | \begin{excdesc}{error}
|
---|
16 | This exception is raised on all errors, such as unknown number of bits
|
---|
17 | per pixel, etc.
|
---|
18 | \end{excdesc}
|
---|
19 |
|
---|
20 |
|
---|
21 | \begin{funcdesc}{crop}{image, psize, width, height, x0, y0, x1, y1}
|
---|
22 | Return the selected part of \var{image}, which should by
|
---|
23 | \var{width} by \var{height} in size and consist of pixels of
|
---|
24 | \var{psize} bytes. \var{x0}, \var{y0}, \var{x1} and \var{y1} are like
|
---|
25 | the \function{gl.lrectread()} parameters, i.e.\ the boundary is
|
---|
26 | included in the new image. The new boundaries need not be inside the
|
---|
27 | picture. Pixels that fall outside the old image will have their value
|
---|
28 | set to zero. If \var{x0} is bigger than \var{x1} the new image is
|
---|
29 | mirrored. The same holds for the y coordinates.
|
---|
30 | \end{funcdesc}
|
---|
31 |
|
---|
32 | \begin{funcdesc}{scale}{image, psize, width, height, newwidth, newheight}
|
---|
33 | Return \var{image} scaled to size \var{newwidth} by \var{newheight}.
|
---|
34 | No interpolation is done, scaling is done by simple-minded pixel
|
---|
35 | duplication or removal. Therefore, computer-generated images or
|
---|
36 | dithered images will not look nice after scaling.
|
---|
37 | \end{funcdesc}
|
---|
38 |
|
---|
39 | \begin{funcdesc}{tovideo}{image, psize, width, height}
|
---|
40 | Run a vertical low-pass filter over an image. It does so by computing
|
---|
41 | each destination pixel as the average of two vertically-aligned source
|
---|
42 | pixels. The main use of this routine is to forestall excessive
|
---|
43 | flicker if the image is displayed on a video device that uses
|
---|
44 | interlacing, hence the name.
|
---|
45 | \end{funcdesc}
|
---|
46 |
|
---|
47 | \begin{funcdesc}{grey2mono}{image, width, height, threshold}
|
---|
48 | Convert a 8-bit deep greyscale image to a 1-bit deep image by
|
---|
49 | thresholding all the pixels. The resulting image is tightly packed and
|
---|
50 | is probably only useful as an argument to \function{mono2grey()}.
|
---|
51 | \end{funcdesc}
|
---|
52 |
|
---|
53 | \begin{funcdesc}{dither2mono}{image, width, height}
|
---|
54 | Convert an 8-bit greyscale image to a 1-bit monochrome image using a
|
---|
55 | (simple-minded) dithering algorithm.
|
---|
56 | \end{funcdesc}
|
---|
57 |
|
---|
58 | \begin{funcdesc}{mono2grey}{image, width, height, p0, p1}
|
---|
59 | Convert a 1-bit monochrome image to an 8 bit greyscale or color image.
|
---|
60 | All pixels that are zero-valued on input get value \var{p0} on output
|
---|
61 | and all one-value input pixels get value \var{p1} on output. To
|
---|
62 | convert a monochrome black-and-white image to greyscale pass the
|
---|
63 | values \code{0} and \code{255} respectively.
|
---|
64 | \end{funcdesc}
|
---|
65 |
|
---|
66 | \begin{funcdesc}{grey2grey4}{image, width, height}
|
---|
67 | Convert an 8-bit greyscale image to a 4-bit greyscale image without
|
---|
68 | dithering.
|
---|
69 | \end{funcdesc}
|
---|
70 |
|
---|
71 | \begin{funcdesc}{grey2grey2}{image, width, height}
|
---|
72 | Convert an 8-bit greyscale image to a 2-bit greyscale image without
|
---|
73 | dithering.
|
---|
74 | \end{funcdesc}
|
---|
75 |
|
---|
76 | \begin{funcdesc}{dither2grey2}{image, width, height}
|
---|
77 | Convert an 8-bit greyscale image to a 2-bit greyscale image with
|
---|
78 | dithering. As for \function{dither2mono()}, the dithering algorithm
|
---|
79 | is currently very simple.
|
---|
80 | \end{funcdesc}
|
---|
81 |
|
---|
82 | \begin{funcdesc}{grey42grey}{image, width, height}
|
---|
83 | Convert a 4-bit greyscale image to an 8-bit greyscale image.
|
---|
84 | \end{funcdesc}
|
---|
85 |
|
---|
86 | \begin{funcdesc}{grey22grey}{image, width, height}
|
---|
87 | Convert a 2-bit greyscale image to an 8-bit greyscale image.
|
---|
88 | \end{funcdesc}
|
---|
89 |
|
---|
90 | \begin{datadesc}{backward_compatible}
|
---|
91 | If set to 0, the functions in this module use a non-backward
|
---|
92 | compatible way of representing multi-byte pixels on little-endian
|
---|
93 | systems. The SGI for which this module was originally written is a
|
---|
94 | big-endian system, so setting this variable will have no effect.
|
---|
95 | However, the code wasn't originally intended to run on anything else,
|
---|
96 | so it made assumptions about byte order which are not universal.
|
---|
97 | Setting this variable to 0 will cause the byte order to be reversed on
|
---|
98 | little-endian systems, so that it then is the same as on big-endian
|
---|
99 | systems.
|
---|
100 | \end{datadesc}
|
---|