All image structures share the following important fields:
nrow,ncol: define the size of the image, by the number of rows and the number of columns (not to be overwritten by user). Notice that the range over the x axis is 0...
ncol- 1 and that the range over the y axis is 0...
previous, next: pointers to the previous and the next image. These fields are used only when the image is part of a movie.
Each image structure has also one or several fields to record the pixel values.
When the image is monochrome, there is only one field called
Color images use three fields called
The C type of these array fields depends to the image object: they can be pointers to
unsigned char values or pointers to
floating points values.
You can put values in those arrays, at the expressed condition that you respect
the C type of the field and that you do not exceed the maximum value of the
index, given by
ncol×nrow - 1.
image->gray[y*image->ncol+x] is the gray level of the pixel of coordinates (x, y) that is, the column #x and the row #y.
0...nrow - 1 for y and
0...ncol - 1 for x.
You can shorten this expression in your modules using C macro, for example:
#define _(a,i,j) ((a)->gray[(j)*(a)->ncol+(i)] )allows you to access to the pixel (x, y) by writing
Tip to speed your modules: images are built from left to right and up to down. If you can write your algorithm to access to the pixel following this natural order, you can speed it considerably using the following scheme. In this example, one copies each pixel of the cimage M into the fimage B only if the pixel of M is not equal to zero:
Cimage M; /* Input of the module */ Fimage *B; /* Output of the module */ register float *ptrB; register unsigned char *ptrM; register int i; for (i=0, ptrB = (*B)->gray, ptrM = M->gray; i< M->ncol*M->nrow; i++, ptrB++, ptrM++) if (*ptrM) *ptrB = (float) *ptrM;If you scan the pixels in a random order, you may rather define a bi-dimensional tab
A[l][c]points to the pixel's value
(c,l). See the functions