The format of imagery stored on PEIPA


Pilot
European
Image
Processing
Archive


The PCCV Project:
Benchmarking Vision Systems

Overview
Tutorials
Methodology
Case studies
Test datasets
Our image file format
HATE test harness



Information
General links
Conferences
Mailing lists
Research groups
Societies

Techniques (CVonline)
Software
Image databases


Other stuff
Linux on ThinkPad

Why PEIPA uses PBMPLUS-format images

There are dozens, if not hundreds, of different image file formats in use today. As it is not feasible to store data in more than one format on PEIPA itself, it makes sense to choose a format that can easily be converted to others. Many image formats (e.g., JPEG) involve lossy compression and so are inherently unsuited for dissemination; others (e.g., GIF) involve technologies that are the subject of patent restrictions.

Hence, the choice was made some years ago to store the imagery on PEIPA in the formats provided by the PBMPLUS (and, latterly, NETPBM) packages. These packages are widely available:

  • they are a standard component of all Linux distributions;

  • they are available for MacOS;

  • they are available for Windows systems;

  • the source code is all pretty portable.

NETPBM (which contains the more up-to-date software) and PBMPLUS both allow images to be converted many other formats, including TIFF, BMP, FITS and PostScript. They also allow many other image formats to be converted into their native formats.

If you want to read PBMPLUS-format images directly into your programs, you have two options

  • Acquire the NETPBM sources. There are sets of C routines for reading and writing each of the formats which you can extract and compile into a library. (This is the approach taken by the PEIPA moderator.)

  • Using the definitions of the formats given below, write your own routines to read and write the formats. For languages other than C or C++, this is your only choice, of course. However, writing such routines hould take an experienced programmer no more than half a day.

The PBMPLUS formats

The PBMPLUS package was written by Jef Poskanzer, is freely-distributable, and is widely used in image processing circles. It started life as a simple exchange mechanism for bit-maps (representations of bi-level raster data). It has subsequently been extended to handle grey-scale and colour images. The following notation is used:

format description
PBM portable bitmap (binary)
PGM portable greymap (grey-scale)
PPM portable pixmap (colour)
PNM portable anymap (i.e., PBM, PGM, or PPM)

The actual file formats are described below, adapted from the PBMPLUS manual pages.

Portable Bitmap File Format

The portable bitmap format is a lowest common denominator monochrome file format. It was originally designed to make it reasonable to mail bitmaps between different types of machines using the typical stupid network mailers we have today. Now it serves as the common language of a large family of bitmap conversion filters. The definition is as follows:

  • A "magic number" for identifying the file type. A PBM file's magic number is the two characters P1.

  • Whitespace (blanks, TABs, CRs, LFs).

  • A width, formatted as ASCII characters in decimal.

  • Whitespace.

  • A height, again in ASCII decimal.

  • Whitespace.

  • Width × height bits, each either 1 or 0, starting at the top-left corner of the bitmap, proceeding in normal English reading order.

  • The character 1 means black, 0 means white.

  • Whitespace in the bits section is ignored.

  • Characters from a # to the next end-of-line are ignored (comments).

  • No line should be longer than 70 characters.

A small bitmap in this format is shown below. Programs that read this format should be as lenient as possible, accepting anything that looks remotely like a bitmap.

  P1
  # feep.pbm
  24 7
  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0
  0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0
  0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 1 0
  0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0
  0 1 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 0 0 0 0
  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

There is also a variant on the format, available in the programs that comprise the PBMPLUS package, by setting the RAWBITS option at compile time. This variant is different in the following ways:

  • The "magic number" is P4 instead of P1.

  • The bits are stored eight per byte, high bit first and the low bit last.

  • No whitespace is allowed in the bits section, and only a single character of whitespace (typically a newline) is allowed after the height.

  • The files are eight times smaller and many times faster to read and write.

Portable Graymap File Format

The portable graymap format is a lowest common denominator grayscale file format. The definition is as follows:

  • A "magic number" for identifying the file type. A PGM file's magic number is the two characters P2.

  • Whitespace (blanks, TABs, CRs, LFs).

  • A width, formatted as ASCII characters in decimal.

  • Whitespace.

  • A height, again in ASCII decimal.

  • Whitespace.

  • The maximum gray value (maxval), again in ASCII decimal.

  • Whitespace.

  • Width × height gray values, each in ASCII decimal, between 0 and the specified maximum value, separated by whitespace, starting at the top-left corner of the graymap, proceeding in normal English reading order. A value of 0 means black, and the maximum value means white.

  • Characters from a # to the next end-of-line are ignored (comments).

  • No line should be longer than 70 characters.

An example of a small graymap in this format is shown below. Programs that read this format should be as lenient as possible, accepting anything that looks remotely like a graymap.

  P2
  # feep.pgm
  24 7
  15
  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
  0  3  3  3  3  0  0  7  7  7  7  0  0 11 11 11 11  0  0 15 15 15 15  0
  0  3  0  0  0  0  0  7  0  0  0  0  0 11  0  0  0  0  0 15  0  0 15  0
  0  3  3  3  0  0  0  7  7  7  0  0  0 11 11 11  0  0  0 15 15 15 15  0
  0  3  0  0  0  0  0  7  0  0  0  0  0 11  0  0  0  0  0 15  0  0  0  0
  0  3  0  0  0  0  0  7  7  7  7  0  0 11 11 11 11  0  0 15  0  0  0  0
  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0

There is also a variant on the format, available in the programs that comprise the PBMPLUS package, by setting the RAWBITS option at compile time. This variant is different in the following ways:

  • The "magic number" is P5 instead of P2.

  • The gray values are stored as plain bytes, instead of ASCII decimal.

  • No whitespace is allowed in the grays section, and only a single character of whitespace (typically a newline) is allowed after the maxval.

  • The files are smaller and many times faster to read and write.

Note that this raw format can only be used for maxvals less than or equal to 255. If you use the PGM library and try to write a file with a larger maxval, it will automatically fall back on the slower but more general plain format.

Portable Pixmap File Format

The portable pixmap format is a lowest common denominator colour image file format. The definition is as follows:

  • A "magic number" for identifying the file type. A PPM file's magic number is the two characters P3.

  • Whitespace (blanks, TABs, CRs, LFs).

  • A width, formatted as ASCII characters in decimal.

  • Whitespace.

  • A height, again in ASCII decimal.

  • Whitespace.

  • The maximum colour-component value (maxval), again in ASCII decimal.

  • Whitespace.

  • Width × height pixels, each three ASCII decimal values between `0' and the specified maximum value, starting at the top-left corner of the pixmap, proceeding in normal English reading order. The three values for each pixel represent red, green, and blue, respectively; a value of 0 means that colour is off, and the maximum value means that colour is saturated.

  • Characters from a # to the next end-of-line are ignored (comments).

  • No line should be longer than 70 characters.

An example of a small pixmap in this format is shown below. Programs that read this format should be as lenient as possible, accepting anything that looks remotely like a pixmap.

  P3
  # feep.ppm
  4 4
  15
   0  0  0    0  0  0    0  0  0   15  0 15
   0  0  0    0 15  7    0  0  0    0  0  0
   0  0  0    0  0  0    0 15  7    0  0  0
  15  0 15    0  0  0    0  0  0    0  0  0

There is also a variant on the format, available in the programs that comprise the PBMPLUS package, by setting the RAWBITS option at compile time. This variant is different in the following ways:

  • The "magic number" is P6 instead of P3.

  • The pixel values are stored as plain bytes, instead of ASCII decimal.

  • Whitespace is not allowed in the pixels area, and only a single character of whitespace (typically a newline) is allowed after the maxval.

  • The files are smaller and many times faster to read and write.

Note that this raw format can only be used for maxvals less than or equal to 255. If you use the PPM library and try to write a file with a larger maxval, it will automatically fall back on the slower but more general plain format.

Portable Anymap File Format

The PNM programs operate on portable bitmaps, graymaps, and pixmaps, produced by the PBM, PGM, and PPM segments. There is no file format associated with PNM itself.


Last updated 2012-06-21 11:13:08 by Adrian F. Clark. [Accessibility information.]