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