COS 323: Code for Image Processing
Downloading code
This code provides the basic functions for reading and writing images in
ppm format. Click here for a man page for the
PPM format.
-
Click here for ppm.c, C source code for reading
and writing PPM images.
-
Click here for ppm.h, the header file.
-
Click here for a test program called try.c.
-
Click here for a Makefile. WARNING: If the makefile fails on you, remove the ^M's using emacs!
-
Click here for all of the above code
without the ^M's.
If you download ppm.c, ppm.h, try.c and the
Makefile, typing "make try" should get you an executable try
which when run will create two small test images, try1.ppm and
try2.ppm. Use xv to display those images.
This source code reads and writes only the PPM "raw" format. You can
use xv 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 jpeg.
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. (And
be sure they are in the public domain!) You may also want to take
your own digital photographs using the cameras in the MECA lab to process
them.
Acknowledgement
This code and the Matisse image was graciously provided by Prof. Adam Finkelstein,
and he has our warmest thanks.
Back to Assignment 5
Precept Week 11 page for Additional Details and Tips