/*********************************************************************/ /* vbmean Compute local 3x3x3 mean using buffer method */ /*********************************************************************/ #include "VisXV4.h" /* VisionX structure include file */ #include "Vutil.h" /* VisionX utility header files */ VXparam_t par[] = /* command line structure */ { { "if=", 0, " input file vbmean: compute local mean"}, { "of=", 0, " output file "}, { 0, 0, 0} }; #define IVAL par[0].val #define OVAL par[1].val int main(argc, argv) int argc; char *argv[]; { V3fstruct (im); V3fstruct (tm); int x,y; /* index counters */ int xx,yy,zz; /* window index counters */ int sum; VXparse(&argc, &argv, par); /* parse the command line */ while (Vbfread( &im, IVAL, 3)) { if ( im.type != VX_PBYTE || im.chan != 1) { /* check format */ fprintf (stderr, "image not byte type\n"); exit (1); } V3fembed(&tm, &im, 1,1,1,1,0,0); /* temp image with border */ for (y = im.ylo; y <= im.yhi; y++) { for (x = im.xlo; x <= im.xhi; x++) { sum = 0; for (zz = tm.zlo; zz <= tm.zhi; zz++) {/* compute the function */ for (yy = -1; yy <= 1; yy++) { for (xx = -1; xx <= 1; xx++) { sum = sum + tm.u[z + zz][y + yy][x + xx]; } } } im.u[0][y][x] = sum/9; } } V3fwrite (&im, OVAL); } exit(0); }