liveBook · Manning

Maximum

As explained in Learn Haskell by Example

The maximum sample value is the header-specified upper numeric limit for a pixel sample in a PNM graymap or pixmap.

In PNM images, the maximum is the header-specified upper numeric limit for each pixel sample. PGM grayscale samples range from 0 to this value; PPM uses the same range independently for red, green, and blue channels. PBM files do not use a maximum because their samples are only 0 or 1. section 12.1.1

The maximum appears after the image width and height in PGM and PPM headers. For example, a PGM header containing 10 14 followed by 9 permits sample values from 0 through 9, with 0 representing black and 9 representing white. section 12.1.1

When reading a PNM header, use the maximum to interpret the pixel data:

  • Read the magic number to identify the format and encoding. section 12.1.1
  • Read the width and height, then read the maximum for PGM or PPM. section 12.1.1
  • Interpret each PGM sample, or each PPM RGB channel, within the range from 0 to the maximum. section 12.1.1

A PGM maximum of 9

In a P2 image, the header can specify `10 14` for the dimensions and `9` as the maximum. A later sample such as `6` is therefore a grayscale value between black (`0`) and white (`9`). section 12.1.1

Table 12.1 Overview of the magic numbers for the PNM formats
Format
Magic numbers
Extension
Image data (for one pixel)
ASCII
Binary
Portable bitmap format (PBM)
P1
P4
.pbm
0 (white) or 1 (black)
Portable graymap format (PGM)
P2
P5
.pgm
From 0 to maximum value (grayscale), where the maximum value is given in the header
Portable pixmap format (PPM)
P3
P6
.ppm
From 0 to maximum value for each RGB channel, where the maximum value is given in the header

Compare how PBM omits a maximum while PGM and PPM use it to define their sample ranges. section 12.1.1

How Learn Haskell by Example covers it

How deep it goes
Explains the header position and sample ranges, but stops short of describing numeric scaling or image-processing algorithms.
Examples
Uses a PGM header with dimensions 10 by 14, maximum 9, and grayscale samples ranging from 0 to 9.
What it assumes
Assumes familiarity with pixels and image dimensions while identifying the header fields and sample ranges directly.
What you can do after
Evaluate/understand PGM and PPM sample values by reading their header-specified upper limit.
How it connects
Connects the maximum to PNM, PGM, PPM, PBM, image headers, grayscale samples, and RGB channels.

Also explained in

Compare how 4 books explain maximum →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.