created: 06/23/2005; revised 01/19/2007, 08/03/2012, 04/24/15


Image Puzzles — Introduction

These pages use the PGM (Portable Gray Map) and PPM (Portable Pixel Map) image formats. These are simple image formats that are easy to work with but take up much more space than GIF or JPEG image files because the image data is not compressed. Since there is no compression, you can easily see what your programs are doing. You loose nothing by using these easy formats. Any image you create can be converted into any popular format by IrfanView, and any image you might want to work with can be converted into an easy format by IrfanView.

1. Download and Install IrfanView

The PGM and PPM image formats are common on Solaris, Unix, and Linux systems, but are rare on Windows systems. Unix and Linux systems usually have image viewers that work with these formats. Look for the program xv.

Most image viewers that work under Windows do not handle PGM and PPM formats. You will need to download and install an image viewer that handles them. These notes use IrfanView, a free image viewer written by Irfan Skiljan. Get it by going to http://www.irfanview.com/ and follow the downloading and installing directions.

IrfanView works with very many image formats. Once you have installed it, test it by starting it and then browsing to any image you have on your system.

2. Create a Directory to work in

Create a subdirectory on your disk to work in, perhaps C:\PuzzleFolder.

3. Put some Images into the Directory

Put some images (of common formats) into the subdirectory.

The easiest way to get PGM and PPM images is to convert GIF or JPEG images to those formats. Here is an image:

Kernighan
kernighan.jpg, 200x257pixels

With typical web browsers, right-click on an image, and then in the context menu that pops up, select Save Picture As:

In the panel that pops up, navigate to your subdirectory C:\PuzzleFolder and save the image as a jpeg (for example, kernighan.jpg).

Directory

Put some other GIF or JPEG images in the directory if you want.

4. Convert Images to PPM and PGM

PPM images are color images, PGM images are gray-level images. IrfanView can convert an image of nearly any format to these formats. Of course, color information is lost when you convert a color image to PGM.

Start IrfanView and browse to an image, say kernighan.jpg.

Viewing Image

Now click File, Save as.. and scroll down the list of type to find PPM.

Save As

Make sure that the "binary" option is checked:

PPM Options

Click on "save" (in the "save picture as..." panel). You will now have a PPM version of the image. Repeat the procedure, but now save the file as type PGM. (There is also a PBM type, for images that are just two levels, total black and total white. We won't use this format.) After doing this you will have three versions of each image:

File List

Convert some additional images, if you want. You should now have a directory with some PGM images in it. In the next section of notes you will play with these images.


Contents — Return to the main contents page