Summary | Source files | Compilation | Precompiled | References


Given a matrix of floating-point numbers stored in a regular ASCII text file, the EpsImg program creates a grey-scale Encapsulated PostScript (EPS) image of the matrix using its elements as specification of the brightness of the corresponding pixels in the image. For an extensive description of the algorithms used in the program, supported command-line options and syntax, as well as the full documentation of the source, see epsimg.pdf. [193 kB, 28 pages].

Summary of the program

As for this program, I do by no means claim to have optimized the generated Encapsulated PostScript. The output images are in many cases large, and could in many cases be considerably reduced in size, in particular for binary or few-level grayscale images for which run-length encoding easily can be applied. (In run-length encoding a long row of identical pixels is parametrized as a loop, without the need of individual specification of each pixel.) However, for my purposes it works fine, since I often only is concerned with the evaluation of gray-scale images, generated by mathematical means and often with no a priori specification of the number of intensity levels.

Of course, there are other ways of generating Encapsulated PostScript images of sampled of simulated data, as for example using the image() function of MATLAB. However, an advantage with using a stand-alone program is that it is easily incorporated in scripts for batch processing. In addition, the EpsImg program is provided free of charge.


Figure 1. Example of application of the EpsImg program, in this particular case for the visualization of a two-dimensional artificially generated interference pattern. The numerical data for the image was generated by an AWK script and stored in an ASCII file example1.dat. The Encapsulated PostScript image was then generated by a call of the EpsImg program, with command-line parameters of the form epsimg -i example1.dat -o example1.eps, to leave the image file example1.eps.

Extract of Makefile for the generation of Fig. 1:

# Example 1: In the following example, a simple interference
#            pattern from two point sources is generated with
#            the help of a AWK script, and the generated data
#            (example.dat) are visualized as an Encapsulated
#            PostScript image (file example.eps), created by a
#            single call to the EPSIMG program.
#                  To compare the generated images with those
#            generated by the MATLAB routine `image()', execute
#            the MATLAB blocks
#                    colormap(gray);
#                    w=load('example1.dat');
#                    w=w-min(min(w));
#                    w=64*w./max(max(w));
#                    image(w);
#                    print('-deps','slask.eps');
    echo "0"|awk 'BEGIN {nr=64; nc=64; a=2.0} {\
        for (j=1;j<=nr;++j) {\
            for (k=1;k<=nc;++k) {\
         printf("%-1.3f ",f);\
    } END {}' > example1.dat
    epsimg -v --compactified_pixelcode --uncommmented_postscript \
        -i example1.dat -o example1-compact.eps
    epsimg -v --extensive_pixelcode --uncommmented_postscript \
        -i example1.dat -o example1-extensive.eps

Current revision

Revision 1.6, as of 21/02/2004. Copyright © Fredrik Jonsson 2003-2006, under GPL

Source files

epsimg.pdf [193 kB] Documentation of the EpsImg program in Portable Document Format (PDF) [2], generated from the PostScript [4] documentation.

epsimg.w [42 kB] The CWEB [1] master source code for the EpsImg program. From this master, the ANSI-C (ISO C90) source code for the program and TeX code for the documentation is extracted using the CTANGLE and CWEAVE compilers, respectively.
[ download | view source ]

epsimg.tar.gz [17 kB] Gzip:ed tape archive of the entire EpsImg program directory, including the CWEB [1] master source code source, Makefile:s and all examples needed to rebuild the program and documentation from scratch. Requires CTANGLE and CWEAVE.
[ download ]

Makefile [2 kB] The Makefile for compilation of the executable file, as well as generation of the documentation of the program. Extracts the C and TeX code from the CWEB source, and compiles the C and TeX code into binary executable and PostScript, respectively. To compile the executable and documentation, simply run 'make' in the directory containing the source files and this Makefile.
[ download | view source ]

epsimg.c [15 kB] ANSI-C (ISO C90) conforming source code, extracted from the CWEB master source code using the CTANGLE program by Donald E. Knuth.
[ download | view source ]

epsimg.tex [54 kB] Plain TeX [3] source code, extracted from the CWEB master source code using the CWEAVE program by Donald E. Knuth.
[ download | view source ] [646 kB] PostScript [4] documentation of the EpsImg program, generated from the TeX-code, which in turn is generated from the CWEB master source code.


The program is written in CWEB [1], generating ANSI C (ISO C99) conforming source code and documentation as plain TeX-source, and is to be compiled using the sequences as outlined in the enclosed Makefile, which essentially executes two major calls. First, the CTANGLE program parses the CWEB source file epsimg.w, to extract a C source file epsimg.c which may be compiled into an executable program using any ANSI C conformant compiler. The output source file epsimg.c includes #line specifications so that any debugging conveniently can be done in terms of line numbers in the original CWEB source file epsimg.w. Second, the CWEAVE program parses the same CWEB source file to extract a plain TeX file epsimg.tex which may be compiled into a PostScript [7] or PDF [6] document. The document file epsimg.tex takes appropriate care of typographic details like page layout and text formatting, and supplies extensive cross-indexing information which is gathered automatically. In addition to extracting the documentary text, CWEAVE also includes the source code in cross-referenced blocks corresponding to the descriptors as entered in the CWEB source code.

Having executed make (or gmake for the GNU enthusiast) in the same directory where the files epsimg.w, and Makefile, are located, one is left with the executable file epsimg, being the ready-to-use compiled program, and the PostScript [7] file (or PDF [6] file epsimg.pdf) which contains the full documentation of the program. Notice that on platforms running any operating system by Microsoft, the executable file will instead automatically be named epsimg.exe. This convention also applies to programs compiled under the UNIX-like environment CYGWIN.

Precompiled executables

epsimg [22 kB] Executable program compiled for Mac OS X 10.7 (Lion) using the GNU C Compiler (GCC). [Compiled Saturday 24 Dec, 2011]


[2] For information on the Portable Document Format (PDF) of Adobe, see for example the homepage of Adobe Systems Inc., at

[3] For information on the TeX typesetting system, as well as on the dvips program, see for example the website of the TeX Users Group, at

[4] For information on the PostScript programming language, see for example the PostScript area on the website of Adobe Systems Inc., at or the reference book "PostScript Language - Tutorial and Cookbook" (Adison-Wesley, Reading, Massachusetts, 1985), ISBN 0-201-10179-3.

Return to previous page

Leave a message

Your name:

Your email: (required)


Generated by ::emailform::

Last modified Wednesday 15 Feb 2023