next up previous contents index
Next: Char Images Up: guid2 Previous: Search path convention   Contents   Index

Images

All image structures share the following important fields:

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 gray. Color images use three fields called red, green and blue. 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. For example, 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. Ranges are 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 _(image,x,y).

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 so that A[l][c] points to the pixel's value (c,l). See the functions mw_newtab_cimage(), mw_newtab_fimage(), ...



Subsections
next up previous contents index
Next: Char Images Up: guid2 Previous: Search path convention   Contents   Index
mw 2004-05-05