How are images represented in the computer?

An image as defined on, say a photographic film, is a continuous function of brightness values. Each point on the developed film can be associated with a gray level value representing how bright that particular point is. To store images in a computer we have to sample and quantize (digitize) the image function. Sampling refers to considering the image only at a finite number of points. And quantization refers to the representation of the gray level value at the sampling point using finite number of bits. Each image sample is called a pixel. Your typical desktop image scanner does sampling and quantization for you.

One of the simpler scheme is sampling on a regular grid of squares. We can visualize the process as overlaying an uniform grid on the image and sampling the image function at the center of each grid square. Finer the grid, better the resolution of the image; coarser the grid, the more is the observed ``pixelization'' (see Figure below). At each pixel (or at each grid square) we usually represent the gray level value using an integer ranging from 0 for black to 255 for fully white.


In what format are the images stored in a computer?

A digital image is essentially a collection of pixel values. There are various formats of storing an image in a file. Essentially they all involve storing the pixels values along with other relevant information about the image. The image format we will be using is called PGM or Portable Gray Map. The extended format for a PGM file is given in Appendix of this document. For our example images we have a simplified PGM format. A typical image file will have data as shown below

P2
123 74
255
111 114 118 119 118 105 85 71 73 72 66 69 80 89 92 90 92
93 82 78 92 92 95 100 104 107 108 109 109 112 108 100 92 84
73 60 50 50 54 54 46 39 42 57 72 86 87 90 94 99 105
109 112 115 113 108 101 92 87 89 93 100 102 91 76 68 55 48
56 72 76 76 66 54 53 67 81 94 78 56 42 48 68 85 92
96 97 104 114 115 100 79 64 60 61 66 77 84 78 60 45 49
42 50 72 83 71 55 49 42 41 39 40 43 43 35 24 45 49
54 57 58 58 110 114 122 124 121 97 72 53 52 53 49 52 62

The first line is a ''magic number'' for identifying the file type. A pgm file's magic number is the two characters ''P2''. The second line contains two numbers denoting the image width and image height, respectively. The third line has the maximum number of gray levels which is, in our case, 255. The numbers in fourth line onwards are the pixel values. The number 255 denotes a white pixel and 0 denotes a black pixel. There are a total of (width * height) gray values. The pixels are stored in row­scanned order, starting at the top­left corner of the image, proceeding in normal English reading order.

How do I ``see'' images on the computer?

The program xv on Unix can read and write PPM, PGM, and other file formats (type "man xv" for information).

How do I get a print out of the image?

Convert the PGM file into a Postscript file (using xv) which can be sent to the printer (using the command lpr -Printer_name postscript_file).