Programming whith VisionX V4 structures

This introduction illustrates the basic concepts of the v4 image structure for a practical program template see the 2D example program c2mean.c

In VisionX programs, files are read into image structures to facilitate easy programming. A file structure is declared by a vfstruct statement, for example:

Vfstruct (im);
Vfstruct (om);
Note, only one structure may be declared in a statement.

Consider we wish to read a byte image and threshold it a grey level of 50. That is, the output image of the program will contain 0 where the input image is less than 50 and will contain 255 where the input image greater than 50. Further, let the input image file be called infile.vx and the output image be called outfile.vx.

The following program will accomplish this:

#include "VisXV4.h"    /* VisionX structure include file       */
#include "Vutil.h"     /* VisionX utility header files         */

int main(int argc, char** argv)
Vfstruct (im);
Vfstruct (om);
int x, y;
    Vfread( &im, "infile.vx");
    Vfnewim (&om, im.type, im.bbx, im.chan);
    for ( y = im.ylo; y <= im.yhi; y++) {
       for ( x = im.xlo; x <= im.xhi; x++) {
          if ( im.u[y][x] >= 50 ) {
              om.u[y][x] = 255;
          } else {
              om.u[y][x] = 0;
    Vfwrite( &om, "outfile.vx");


  1. All programs in VisionX should start with the two include statements “VisXV4.h” and “VXutil.h” as shown above. Note, you do NOT need to include that standard C programming language files <stdio.h> and <math.h> these have already been included.
  2. Vfread reads the file inimage.vx and builds the internal image data array in the Vfstructure im.
  3. Vmakeimage creates a image (set to zero) with the same parameters as the image im. Parameters specify the image type (byte in this case), bounding box and number of channels.
  4. A double loop is used to compute the function on the image im and store the result in the image om. Some features of this loop are a follows:
    1. Not the outer loop is associated with the y (vertical) direction and the inner loop is associated with the x (horizontal direction). This may appear to be counter intuitive but provides for the most efficient (fastest) implementation.
    2. The image indicies do not necessarily start at 0 ro 1. The lowest image location is (im.xlo, im.ylo)
    3. Since the highest legal index values are im.xhi and im.yhi the condition in the loop expression is “≥” rather than just “s>” which is the more typical value used in C program loops.
    4. For the image elements you must supply the image type explicitly since c programming is not polymorphic. That is, for the expression im.u[i][j] the .u is required to specify that we are refereeing to an image of type unsigned byte.
  5. The Vwrite statement writes the image in om to the file “outfile.vx

Essential members of the Vfstruct that you must know:

.bbx The bounding box for the image (float[6])
.type The base type of the image pixels; see next example for a list
.chan The number of channels in the image (e.g., color has 3)
.xlo The lowest defined x index
.xhi The highest defined x index
.ylo The lowest defined y index
.yhi The highest defined y index

 © 2019 Anthony P. Reeves