Page 30 -
P. 30
4 Chapter 1 ■ Practical Aspects of a Vision System
Other useful fields to know about include the following:
nChannels An integer specifying the number of colors per pixel (1–4).
depth An integer specifying the number of bits per pixel.
origin The origin of the coordinate system. An integer: 0=upper
left, 1=lower left.
widthStep An integer specifying, in bytes, the size of one row of the
image.
imageSize An integer specifying, in bytes, the size of the image
( = widthStep * height).
imageDataOrigin A pointer to the origin (root, base) of the image.
roi A pointer to a structure that defines a region of interest
within this image that is being processed.
When an image is created or read in from a file, an instance of an IplImage
is created for it, and the appropriate fields are given values. Consider the
following definition:
IplImage* img = 0;
As will be described later in more detail, an image can be read from a file by
the following code:
img = cvLoadImage(filename);
where the variable filename is a string holding the name of the image file. If
this succeeds, then
img->imageData
points to the block of memory where the pixels can be found. Figure 1.1 shows
a JPEG image named marchA062.jpg that can be used as an example.
Reading this image creates a specific type of internal representation common
to basic RGB images and will be the most likely variant of the IplImage
structure to be encountered in real situations. This representation has each
pixel represented as three bytes: one for red, one for green, and one for
blue. They appear in the order b, g, r, starting at the first row of the image
and stepping through columns, and then rows. Thus, the data pointed to by
img->imageData is stored in the following order:
b 0,0 g 0,0 r 0,0 b 0,1 g 0,1 r 0,1 b 0,2 g 0,2 r 0,2 ...
This means that the RGB values of the pixels in the first row (row 0) appear
in reverse order (b, g, r) for all pixels in that row. Then comes the next row,
starting over at column 0, and so on, until the final row.