A number of tools are available to simplify the development of VisionX programs for image processing. An image is considered as a two dimensional array of pixels. In a VisionX file an image is represented by two elements: a bounding box which defines the image structure and a pixel vector which contains the data. A number of different base types for pixels are supported. In addition, each image may have multiple channels. For example, in a color image each pixel has three components (typically red, green and blue).
Within a program a the image programming tools create and maintain a data structure of type VisXimage_t to aid accessing the pixels in an image.
An image structure (including the two list elements) may be dynamically created in VisionX with the VXmakeimage function. The syntax for this function is:
VXmakeimage( &<i-structure>,<type>,<bounding box>,<channels>);
Where i-structure is the structure to be initialized, type is the base type for the pixels, bounding box specifies the bounding box ( in floating point numbers ) and channels specifies the number of elements for each pixel.
For example, consider the following image declaration:
VisXimage_t foo; VXmakeimage ( &foo, VX_PFLOAT, (float){0, 5, 0, 8}, 3);A (5 x 8) pixel image is created in which each pixel consists of three floating point numbers. The bounding box is specified by an array of four floating point numbers (xmin, xmax, ymin, ymax) and the number of channels is specified by an integer.
The base pixel types supported by VisionX and their VisionX names are given in the table below:
The Ext field specifies the element of the VisXimage data structure which will point to the two dimensional array.
VXmakeimage allocates memory for the image and
creates a two dimensional array structure to conveniently access
this structure. The following four structure elements are set
by VXmakeimage:
In addition, the extension corresponding to the pixel data type points
to the two dimensional array.
For example, consider the previous (5 x 8) image declaration: All pixels in the image may be set to zero with the following program sequence:
{int i, j; for ( i = foo.ylo; y <= foo.yhi; i++ ) for ( j = foo.xlo; x <= foo.xhi; j++ ) foo.f[i][j] = 0.0; }
The array must be referred to as foo.f since it was declared to be of type VX_PFLOAT. The values for the index limits for this example are as follows: foo.xlo = 0, foo.xhi = 14, foo.ylo = 0, and foo.yhi = 7. The x-range is three times the size of the bounding box since each pixel requires three consecutive floating point numbers. That is, the three components of the first pixel in the array are: foo.f[0][0], foo.f[0][1] and foo.f[0][2].
{ VisXfile_t fout; fout = VXopen("<file name>", 1); VXwrite(fout, foo.list); VXclose(fout); }
VisionX files may contain a large number of different types of elements; the function VXsetimage has been developed to construct an VisXimage structure to conveniently access an image if a pixel type element is found in the file. The syntax for this function is:
VXsetimage ( &<i-structure>, <pixel-ptr>, <file-struct> );Where pixel-ptr is a pointer to a pixel data element in a VisionX data list, and file-struct is the structure returned by the VXopen command.
For example, an image structure could be set up with the contents of an VisionX image file with the following program sequence:
VisXfile_t *ifile; VisXelem_t *list, ptr; VisXimage_t fie; ifile = VXopen("<filename>", 0); list = VXread(ifile); if (VXNIL != (ptr = VXfind(list, VX_PBYTE)) VXsetimage( &fie, ptr, ifile);The function VXfind will locate the first element in the list of type VX_PBYTE (8-bit unsigned pixels); therfore, the given segment will only create a structure if a byte pixel image is located in the data list. (Note: you can use VXfindin for situations where more than one pixel type is possible). In addition to the array accessing structure elements, the following structure elements are set by VXsetimage.
.type the pixel type .chan the number of channels .bbx the bounding box .imitem the item in the list where the image is located
The simple program presented in Figure 2 will work on simple files which just contain a single byte image. The following more advanced program segment shown in Figure 3 performs the same function but on a VisionX file of arbitrary complexity and length. Files may contain many different types of data, the new program will just replace the byte images with short images all other data elements will be maintained without modification. The revised program has the following features: