Multichannel and Color Image Program ExampleMultichannel 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.
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. |