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