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