Time Buffereing Program example
The time-buffer programming model is for situations such as movies where
you want to do some temporal processing; i. e., compute a function on
several image frames. The 3D model could address this problem if the file
was small enough to read into memory. However movies may be too large
to fit into memory. Furthermore, in real time applications you would
like to process the first frames of the movie while data acquisition
for later frames is still in progress. The buffer processing mode
provides support for this application. It provides a buffer of the
most recent image frames; then when a Vbfread operation is performed
the oldest frame is discarded and a new frame is read in. That is,
the Vrfbuf operation maintains a time ordered buffer of the most
recent image frames in a 3D image structure where z=0 is the z index
value of the oldest frame and z=n-1 is the index of the most recent frame.
The example program performs a 3x3x3 mean filter operation similar to the
example 3D mean filter.
vbmean.c
/*********************************************************************/
/* 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[zz][y + yy][x + xx];
}
}
}
im.u[0][y][x] = sum/9;
}
}
V3fwrite (&im, OVAL);
}
exit(0);
}
Notes:
-
Vbfread is used for reading data instead of V3fread. The first time
Vbfread is called it reads n (=3) images; Subsequent calls read one new
image and discard the oldest image.
-
With a buffer size of 3 the oldest frame has z index 0 and the most
recent frame has z index 2.
-
The oldest image (z=0) may be used as a buffer to hold the current
output. (since this image will be discarded on
the next read operation).
-
V3fwrite may be used to write out just the oldest index frame (index
0). This operation is different to that when V3fread is used to read a
3D image, in that case the whole 3D image is written.
-
The function section of the program is modeled after the 3D mean eample
program. In
this case the 3D image contains just 3 frames and we are computing the
function corresponding to just the center frame (z index 1).
-
There is no need to buffer tm in the z direction
-
The first read reads n frames and the program loops until
there are no more image in the file generating a result frame for each
loop. Therefore, if the file has M image frames then only M – n + 1
image frames will be generated. For this example mean filter program the
result will contain M-2 frames. In this way the operation of the buffer
filter program differs from that of example 3D program. The first
and last frames (where computation overlaps the border of the 3D image)
will not be generated; however, the remaining frames should contain the
same values for each program.
|