Multichannel and Color Image Program Example

Multichannel images in Visionx are implemented by overloading the x-dimension of the image array structure. Multichannel images are identified by the x-range of the index being set to an exact multiple of the x-range in the bounding box.

A VisionX image may have any number of channels depending upon the application. Typical examples are three for color images and two for complex numbers.

vcmean.c

/*********************************************************************/
/* vcmean  Compute channel mean                                      */
/*********************************************************************/

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

VXparam_t par[] =      /* command line structure               */
{
{    "if=",    0, " input file  vthresh: threshold images"},
{    "of=",    0, " output file "},
{     0,       0,    0}
};
#define  INIMAGE   par[0].val
#define  OUTIMAGE  par[1].val

int main(int argc, char** argv)
{
Vfstruct (im);
Vfstruct (om);
int x, y, c;
int thresh;
int chan, sum;

VXparse(&argc, &argv, par);  /* parse the command line         */
 
while ( Vfread( &im, INIMAGE) ) {
    if ( im.type != VX_PBYTE ) {
           fprintf (stderr, "error: image not byte type\n");
           exit (1);
    }
    Vfnewim (&om, VX_PBYTE, im.bbx, 1);
    for ( y = om.ylo; y <= om.yhi; y++) {
       for ( x = om.xlo; x <= om.xhi; x++) {
          sum = 0;
          for ( c = 0; c < im.chan; c++) { 
               sum = sum + im.u[y][x * im.chan + c];
	     }
	     om.u[y][x] = sum / im.chan;
       }
    }
    Vfwrite( &im, OUTIMAGE);
  }
exit(0);
}

Notes.
  1. The program in example 5 will average the multi-channel values into a single channel image.
  2. The program is limited to images of type unsigned byte.
  3. The program loop limits are based on the output structure rather than the input structure
  4. All parameters are the same for a multichannel image except for chan which is set to the number of channels and xlo and xhi, which are multiplied by the number of channels.
For a 3-channel image, imm, with xlo = 0 we have that:
imm.u[0][0] corresponds to the first channel of the first pixel
imm.u[0][1] corresponds to the second channel of the first pixel.
imm.u[0][3] corresponds to the first channel of the second pixel.