Once the PGM or PPM files have been created, there are, as depicted in the bottom third of the flow chart of Fig. 1, several ways in which they can be viewed. First, the files can be viewed as individual frames (stills). Many graphics viewers directly support the PNM formats and any of these could be used to view the individual frames. Alternatively, the files can be ``strung together'' to make animations of the field. Some graphics packages that are typically used to view still images also provide rudimentary animation capability. In addition, there is public domain software that will convert a sequence of frames into an MPEG file.
As an example of how single frames can be viewed on X Windows systems, the xli program can be used to view frame 39 with a command such as xli frame.39.ppm (assuming the base name is frame and color output was generated). A series of frames can be viewed by using the built-in filename expansion provided by Unix shells. For example, to view frames 30 to 49, the following command would be used
xli frame.[34]?.ppm(Please refer to the appropriate shell documentation for the specifics concerning command-line file name substitution.) In xli, the n or f keys are used to cycle through the frames. A rudimentary animation can be constructed using xli by specifying that displayed image should change after a given delay. For example,
xli -delay 1 frame.?.ppm frame.??.ppm frame.???.ppmwill cycle through the files (starting with files with a single digit, then two digit files, then three digit files) with a one second delay between each.
Besides xli, there are many utilities that can be used to view images on X Windows systems. For instance, the popular image display utility xv directly supports PNM files and can be used for simple animations. The viewer display is available as part of the public-domain ImageMagick routines and can be used to automatically cycle through all the frames of the animation.
As a last resort, if one can display GIF files, the PGM and PPM files can be converted to GIF by using the ppmtogif routine provided in the pbmplus package mentioned earlier. GIF files have the advantage of being compressed and hence are much smaller than the corresponding PNM file. However, they have the disadvantage of being precompressed to eight-bit color and thus could obscure important details in certain images.
As an alternative to the low-level animation capability provided by routines such as display, xli, and xv, a better animation utility is distributed with the ImageMagick routines. This animation utility, called animate, works directly with a wide range of file formats, including PGM, PPM, and GIF. Some advantages of using this routine over the others is that it is less likely to cause color map ``flashing'' as it cycles through the frames, and the speed and direction of the animation are much easier to control.
The animate utility is relatively powerful and easy to use and thus is quite convenient to use on an X Windows workstation. However, in many instances it is desirable to share an animation with colleagues or to make it available via the Web. In these instances, one cannot rely upon a one-size-fits-all utility and it may not be practical to make all the underlying frames of an animation available. Instead, MPEG files provide a concise and portable means to distribute and playback animations.
MPEG (an acronym for Moving Pictures Expert Group) is a specification for the architecture and file formats of an encoder and a decoder for image sequences. The MPEG format has emerged as a standard format for image sequences transmitted over computer networks or retrieved from CD-ROMs or other media. Among its attractive features is the ability to trade off file size against the quality of the compression. For the purposes of this discussion the MPEG encoder can be viewed as a black box into which the PNM files are fed, compressed, and written to the output file which can then be transmitted and/or replayed on demand. It is not difficult to obtain compression rates of 90% or better on image sequences with substantial coherence between adjacent frames (such as those in our application), without sacrificing visual quality of the display.
In order to construct an MPEG file from the individual frame files, one can use the mpeg_encode utility that is available via anonymous ftp from mm-ftp.cs.berkeley.edu. This utility comes with documentation and examples so that it is relatively easy to use. The basic procedure is to write a ``parameter'' file that tells the encoder the type of compression desired, the name and number of files, etc. The name of the parameter file is given as an argument to the mpeg_encode utility. For example, if the parameter file were named params, the command mpeg_encode params would generate an MPEG file in accordance with the instructions contained within the file params. The following is a typical parameter file that would be used to construct an output MPEG file named animation.mpg from the 100 image files frame.1.ppm, frame.2.ppm, ... frame.100.ppm.
IQSCALE 4 PQSCALE 7 BQSCALE 7 PSEARCH_ALG TWOLEVEL BSEARCH_ALG SIMPLE GOP_SIZE 16 SLICES_PER_FRAME 1 PIXEL HALF RANGE 12 PATTERN IBBPBBPBBPBBPBBP FORCE_ENCODE_LAST_FRAME INPUT_DIR . INPUT frame.*.ppm [1-100] END_INPUT BASE_FILE_FORMAT PPM INPUT_CONVERT * REFERENCE_FRAME DECODED OUTPUT animation.mpg
Please refer to the documentation that accompanies mpeg_encode for more information about the items in the parameter file. Additional examples of the use of mpeg_encode can be found at the previously mentioned Animations Web site. If one does not have access to an MPEG viewer, one can also be obtained from the Berkeley ftp site. (It should be noted that several options are also available when running the viewer. These options can also affect the speed and quality of the playback of an MPEG file!)