| 
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 |  |  | \section{Built-in module \sectcode{imageop}} | 
					
						
							|  |  |  | \bimodindex{imageop} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-03-13 10:03:32 +00:00
										 |  |  | The \code{imageop} module contains some useful operations on images. | 
					
						
							| 
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 |  |  | It operates on images consisting of 8 or 32 bit pixels | 
					
						
							| 
									
										
										
										
											1995-03-13 10:03:32 +00:00
										 |  |  | stored in Python strings. This is the same format as used | 
					
						
							| 
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 |  |  | by \code{gl.lrectwrite} and the \code{imgfile} module. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The module defines the following variables and functions: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \renewcommand{\indexsubitem}{(in module imageop)} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{excdesc}{error} | 
					
						
							|  |  |  | This exception is raised on all errors, such as unknown number of bits | 
					
						
							|  |  |  | per pixel, etc. | 
					
						
							|  |  |  | \end{excdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{funcdesc}{crop}{image\, psize\, width\, height\, x0\, y0\, x1\, y1} | 
					
						
							| 
									
										
										
										
											1995-03-13 10:03:32 +00:00
										 |  |  | This function takes the image in \var{image}, which should by | 
					
						
							|  |  |  | \var{width} by \var{height} in size and consist of pixels of | 
					
						
							|  |  |  | \var{psize} bytes, and returns the selected part of that image. \var{x0}, | 
					
						
							|  |  |  | \var{y0}, \var{x1} and \var{y1} are like the \code{lrectread} | 
					
						
							| 
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 |  |  | parameters, i.e. the boundary is included in the new image. | 
					
						
							|  |  |  | The new boundaries need not be inside the picture. Pixels that fall | 
					
						
							|  |  |  | outside the old image will have their value set to zero. | 
					
						
							| 
									
										
										
										
											1995-03-13 10:03:32 +00:00
										 |  |  | If \var{x0} is bigger than \var{x1} the new image is mirrored. The | 
					
						
							| 
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 |  |  | same holds for the y coordinates. | 
					
						
							|  |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{funcdesc}{scale}{image\, psize\, width\, height\, newwidth\, newheight} | 
					
						
							| 
									
										
										
										
											1995-03-13 10:03:32 +00:00
										 |  |  | This function returns an \var{image} scaled to size \var{newwidth} by | 
					
						
							|  |  |  | \var{newheight}. No interpolation is done, scaling is done by | 
					
						
							| 
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 |  |  | simple-minded pixel duplication or removal. Therefore, computer-generated | 
					
						
							|  |  |  | images or dithered images will not look nice after scaling. | 
					
						
							|  |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{funcdesc}{tovideo}{image\, psize\, width\, height} | 
					
						
							|  |  |  | This function runs a vertical low-pass filter over an image. It does | 
					
						
							|  |  |  | so by computing each destination pixel as the average of two | 
					
						
							|  |  |  | vertically-aligned source pixels. The main use of this routine is to | 
					
						
							|  |  |  | forestall excessive flicker if the image is displayed on a video | 
					
						
							|  |  |  | device that uses interlacing, hence the name. | 
					
						
							|  |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{funcdesc}{grey2mono}{image\, width\, height\, threshold} | 
					
						
							|  |  |  | This function converts a 8-bit deep greyscale image to a 1-bit deep | 
					
						
							|  |  |  | image by tresholding all the pixels. The resulting image is tightly | 
					
						
							|  |  |  | packed and is probably only useful as an argument to \code{mono2grey}. | 
					
						
							|  |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{funcdesc}{dither2mono}{image\, width\, height} | 
					
						
							|  |  |  | This function also converts an 8-bit greyscale image to a 1-bit | 
					
						
							|  |  |  | monochrome image but it uses a (simple-minded) dithering algorithm. | 
					
						
							|  |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{funcdesc}{mono2grey}{image\, width\, height\, p0\, p1} | 
					
						
							|  |  |  | This function converts a 1-bit monochrome image to an 8 bit greyscale | 
					
						
							|  |  |  | or color image. All pixels that are zero-valued on input get value | 
					
						
							| 
									
										
										
										
											1995-03-13 10:03:32 +00:00
										 |  |  | \var{p0} on output and all one-value input pixels get value \var{p1} | 
					
						
							| 
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 |  |  | on output. To convert a monochrome black-and-white image to greyscale | 
					
						
							|  |  |  | pass the values \code{0} and \code{255} respectively. | 
					
						
							|  |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{funcdesc}{grey2grey4}{image\, width\, height} | 
					
						
							|  |  |  | Convert an 8-bit greyscale image to a 4-bit greyscale image without | 
					
						
							|  |  |  | dithering. | 
					
						
							|  |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{funcdesc}{grey2grey2}{image\, width\, height} | 
					
						
							|  |  |  | Convert an 8-bit greyscale image to a 2-bit greyscale image without | 
					
						
							|  |  |  | dithering. | 
					
						
							|  |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{funcdesc}{dither2grey2}{image\, width\, height} | 
					
						
							|  |  |  | Convert an 8-bit greyscale image to a 2-bit greyscale image with | 
					
						
							|  |  |  | dithering. As for \code{dither2mono}, the dithering algorithm is | 
					
						
							|  |  |  | currently very simple. | 
					
						
							|  |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{funcdesc}{grey42grey}{image\, width\, height} | 
					
						
							|  |  |  | Convert a 4-bit greyscale image to an 8-bit greyscale image. | 
					
						
							|  |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{funcdesc}{grey22grey}{image\, width\, height} | 
					
						
							|  |  |  | Convert a 2-bit greyscale image to an 8-bit greyscale image. | 
					
						
							|  |  |  | \end{funcdesc} |