3D Program ExampleThe 3D program strucutre is simliar to the 2D example but using 3D versions of the programming tools. Also there is only one 3D image per file.v3mean.c
/*********************************************************************/
/* v3mean Compute 3x3x3 3D mean filter on byte images */
/*********************************************************************/
#include "VisXV4.h" /* VisionX structure include file */
#include "Vutil.h" /* VisionX utility header files */
VXparam_t par[] = /* command line structure */
{
{ "if=", 0, " input file v3mean: 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,z; /* index counters */
int xx,yy,zz; /* window index counters */
int sum;
VXparse(&argc, &argv, par); /* parse the command line */
V3fread( &im, IVAL); /* read 3D image */
if ( im.type != VX_PBYTE || im.chan != 1) { /* check format */
fprintf (stderr, "image not byte type or single channel\n");
exit (1);
}
V3fembed(&tm, &im, 1,1,1,1,1,1); /* temp image copy with border */
for (z = im.zlo; z <= im.zhi; z++) {/* for all pixels */
for (y = im.ylo; y <= im.yhi; y++) {
for (x = im.xlo; x <= im.xhi; x++) {
sum = 0;
for (zz = -1; zz <= 1; 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[z][y][x] = sum/27;
}
}
}
V3fwrite (&im, OVAL);
exit(0);
}
Notes:
The 3D image structure has two additional elements for indexing in the z dimension as shown below. The base pixel types are the same as for 2D structures. Critical members of the V3fstruct that you must know:
|