![](http://images-20200215.ebookreading.net/23/1/1/9781482247336/9781482247336__a-computational-introduction__9781482247336__bg32.png)
32 A Computational Introduction to Digital Image Processing, Second Edition
Vector versus Raster Images
We may store image information in two different ways: as a collection of lines or vec-
tors, or as a collection of dots. We refer to the former as vector images; the latter as
raster images. The great advantage of vector images is that they can be magnified to any
desired size without losing any sharpness. The disadvantage is that are not very good for
the representation of natural scenes, in which lines may be scarce. The standard vector
format is Adobe PostScript; this is an international standard for page layout. PostScript
is the format of choice for images consisting mostly of lines and mathematic ally describ ed
curves: architectural and industrial plans, font information, and mathematical figures. The
reference manual [21] provides all necessary information about PostScript.
The great bulk of image file formats store images as raster information; that is, as a
list of the gray or color intensities of each pixel. Images captured by digital means–digital
cameras or scanners–will be stored in raster format.
A Simple Raster Format
As well as containing all pixel information, an image file must contain some header infor-
mation; this must include the size of the image, but may also include some documentation,
a color map, and compression used. To show the workings of a raster image file, we shall
briefly describe the ASCII PGM format. This was designed to be a generic format used
for conversion between other formats. Thus, to create conversion routines between, say, 40
different formats, rather than have 40 ×39 = 1560 different conversion routines, all we need
is the 40 × 2 = 80 conversion routines between the formats and PGM.
P2
# CREATOR: The GIMP’s PNM Filter Version 1.0
256 256
255
41 53 53 53 53 49 49 53 53 56 56 49 41 46 53 53 53
53 41 46 56 56 56 53 53 46 53 41 41 53 56 49 39 46
FIGURE 2.4: The start of a PGM file
Figure 2.4 shows the beginning of a PGM file. The file begins with
P2; this indicates
that the file is an ASCII PGM file. The next line gives some information about the file:
any line beginning with a hash symbol is treated as a comment line. The next line gives the
number of columns and rows, and the following line gives the number of grayscales. Finally
we have all the pixel information, starting at the top left of the image, and working across
and down. Spaces and carriage returns are delimiters, so the pixel information could be
written in one very long line or one very long column.
Note that this format has the advantage of being very easy to write to and to read from;
it has the disadvantage of producing very large files. Some space can be saved by using
“raw” PGM; the only difference is that the header number is
P5, and the pixel values are
stored one per byte. There are corresponding formats for binary and colored images (PBM
and PPM, respectively); colored images are stored as three matrices; one for each of red,
green, and blue; either as ASCII or raw. The format does not support color maps.