VisionX V4 Matlab Programming

A beta version of a matlab api is available for the development and validation of V4 image processing functions. The current first version of this system provides support for single 2D images in byte, short integer and float pixel formats.

Unlike the c programming environment, the index origin must be 1,1 rather than ylo,xlo. Further, the index origin is located at the top left hand corner of the image rather than the lower left hand corner. As a consequence of the indexing limitation, offsets in location between images must be explicitly managed by the program. Also the image is transposed with respect to the usual interpretation of images in matlab as supported by imread etc..

The functions available for image programming include: vxparse(used by sh), vxread, vxwrite.

array = vxread(file-name);
vxwrite(array, file-name);
array = vfnewim(type, bbx, chan);
array = vfembed(array, xlo, xhi, ylo, yhi);

For documentation of these functions see the c programming language descriptions. For their use see the following example matlab program and compare to the c example program vtemp.c

Release Notes

  1. If the functions are not installed in the matlab library or in the local directory then they the addpath command must be used to locate them as outlined in the program example.
  2. In this example command line parsing is implemented in the shell script prior to starting matlab. It is also possible to do the same function from within matlab.
  3. Image indexing is from 1,1 at the top left corner of the image with the index increasing in a downward direction.
  4. Only 2D images are currently supported.

A template matlab program to implement a 2D local 5 element max filter is shown below:

#!/bin/sh
pname="vtempml"
#### this version handles command parameter parsing in sh
#### and inserts them in $ variables in the matlab script
eval `vshparse  if= of=  - with $0 $*`
lib=`vxgetdir lib`
#### the matlab script follows the next line
matlab -nodisplay -nojvm -nodesktop -nosplash >  /dev/null << EOF
% declare any command line parameters
if strcmp('$OPT', '-')
  fprintf(2, '$pname:   V4 matlab template\n')
  fprintf(2, '[if= ] input file\n')
  fprintf(2, '[of= ] input file\n')
  fprintf(2, '[-v  ] visible  mode\n')
  exit
end

addpath('$lib')

im = vxread('$if');
tm = vfembed(im,1,1,1,1);
for i=1:size(im,1)
   for j=1:size(im,2)
      im(i,j)=max([tm(i+1,j+1) tm(i,j+1)  ...
                tm(i+2,j+1) tm(i+1,j) tm(i+1,j+2)]);
   end
end

vxwrite(im, '$of' )
EOF

The conventional c language program for this function, for comparison, is as follows:
/* vtemp      Compute local max operation on a single byte image   */
/*******************************************************************/
#include "VisXV4.h"           /* VisionX structure include file    */
#include "Vutil.h"            /* VisionX utility header files      */

VXparam_t par[] =             /* command line structure            */
{ /* prefix, value,   description                         */   
{    "if=",    0,   " input file  vtemp: local max filter "},
{    "of=",    0,   " output file "},
{     0,       0,   0}  /* list termination */
};
#define  IVAL   par[0].val
#define  OVAL   par[1].val

main(argc, argv)
int argc;
char *argv[];
{
Vfstruct (im);                      /* i/o image structure          */
Vfstruct (tm);                      /* temp image structure         */
int        y,x;                     /* index counters               */
  VXparse(&argc, &argv, par);       /* parse the command line       */

  Vfread(&im, IVAL);                /* read image file              */
  Vfembed(&tm, &im, 1,1,1,1);       /* image structure with border  */

  for (y = im.ylo ; y <= im.yhi ; y++) {  /* compute the function */
     for (x = im.xlo; x <= im.xhi; x++)  { 
       im.u[y][x] = MAX(tm.u[y][x], MAX(tm.u[y][x+1],
                    MAX(tm.u[y+1][x], MAX(tm.u[y][x-1], tm.u[y-1][x]))));
     }
   }

   Vfwrite(&im, OVAL);             /* write image file                */
   exit(0);
}

SEE ALSO

Vnewim(3),Vembed(3),Vfread(3), Vfwrite(3)
V3newim(3),V3embed(3),V3fread(3), V3fwrite(3)
Vxparse(3)

AUTHOR

A. P. Reeves