Additional material: Visualization and code

Downloading code

This code provides the basic functions for reading and writing images in ppm (portable pixmap) file format. Click here for a man page for the ppm format. If you download ppm.c, ppm.h, try.c and the Makefile, typing "make try" should get you an executable try that, when run, will create two small test images, try1.ppm and try2.ppm.

Displaying and converting images in ppm format

If you're working on a Solaris machine (or, more generally, using UNIX and X Windows), you're golden. The application xv will display ppm images directly. You can also convert to other formats by saving from xv and choosing from the pulldown list. (See also mogrify and convert on Solaris machines. Their man pages have more information on conversion and manipulation of different image formats than a normal human being will ever need.)

It turns out that PCs are particularly unfriendly to ppm images, hardly acknowledging their existence. If you're working with C on a PC, the application CONV.exe should do the trick. Just download it from here and run it from a DOS window, using something like this:
C:\> CONV try1.ppm try1.bmp
to convert ppm to bmp (bitmap) format. Once a file is in bmp format, you should be able to get into anything else using Photoshop or similar applications.

Note:   I've provided a minimal set of tools you need to generate and process pictures in C and view them anywhere. But there must be a billion ways to go about this. Please send me suggestions and I'll post the good ones.

The utilities

This source code reads and writes only the ppm "raw" format. You can use xv (on a Solaris) to convert many other common image formats to ppm raw. Just display the image using xv and save in ppm raw mode. This source code is intended to get you started reading and writing image files without fussing over the mechanics. The functions provided are

Image *ImageCreate(int width, int height);
Image *ImageRead(char *filename);
void   ImageWrite(Image *image, char *filename);
int    ImageWidth(Image *image);
int    ImageHeight(Image *image);
void   ImageClear(Image *image, u_char red, u_char green, u_char blue);
void   ImageSetPixel(Image *image, int x, int y, int chan, u_char val);
u_char ImageGetPixel(Image *image, int x, int y, int chan);
with obvious (I hope) meaning. Image is a struct defined in ppm.h. You should be able to write similar functions for your own use by analogy.

FFT

Click here for testfft.c, an FFT function and a main test program.

Sample images (ppm format)

Here are some images to get started. What you see are thumbnails in jpg. Click on them to get full-size images in ppm raw format, which can be downloaded by right-clicking in the image area. All of them fit in within a 256x256 frame, which is important when you take the FFT. The first is a small version of an image from Prof. Finkelstein, a painting by Matisse called LaMusique. The second is an oil portrait of Nikolai Gogal by F. A. Moller, 1841, which hangs in the Tretyakovskaya Galleria, Moscow. The third is a detail of a biker from the 1996-97 Princeton University catalog cover.
     

It's more fun if you download your own images from the web. Be sure to reduce their sizes and convert to ppm raw format, using xv.

It's even more fun to take your own pictures, either with a digital camera, or by scanning prints from a film camera. Once you get jpg, for example, you're home free: just convert to ppm with xv and use your C programs.

A few other suggestions for extra credit


Acknowledgements:   This ppm utility code and the Matisse image were provided by Prof. Adam Finkelstein, and CONV.exe by Prof. Tom Funkhauser. Thanks also to Prof. David Dobkin, who pointed us to mogrify and convert.

Hide Oki, 7/21/98
Ken Steiglitz, 8/14/02