Plotting & Viewing Tools
Sampling & Quantization Review
What I called "spatial quantization", the
book calls "sampling". I like their term
better. What I called "gray level quantization",
the book just calls quantization. I'll try
to use book terms from now on.
Re-Quantization Example
Quantization Change Images
16 gray levels |
4 gray levels |
|
|
Note: the above images are greatly enlarged. A 5 x 5 pixel
image wouldn't be visible on the web page.
Re-Sampling Example
Sampling Change Images
6 x 6 |
3 x 3 |
|
|

Same sized pixels after resampling.

CAT 256 X 256

CAT 128 X 128

CAT 64 X 64

CAT 32 X 32

CAT Reenlarged

CAT 256 gray levels

CAT 128 gray levels

CAT 64 gray levels

CAT 32 gray levels

CAT 16 gray levels

CAT 8 gray levels

CAT 4 gray levels

CAT 2 gray levels
Other Quantization Examples
- cat image,
- continuous,
- sampled,
- Low Freq. image, high sample
rate,
- Low Freq. image, medium sample
rate,
- Low Freq. image, low sample
rate,
- Low Freq. image, really
low sample rate,
- High Freq. image, high
sample rate,
- High Freq. image, medium
sample rate,
- High Freq. image, low sample
rate,
and
- High Freq. image, really
low sample rate.
- Cat image:
512 x 512,
256 x 256,
128 x 128,
64 x 64,
32 x 32, and
16 x 16 spatial
quantization.
- A sample plug-in:
mybump.c
PGM File Format

Programming Fall Back Position
This is a very simple and portable
graphics file format. It was designed
to be as compact as possible.
There are six separate formats. Each
format is identified by the first two
ascii letters in the file as per the
following:
- P1 : PBM ASCII Black & White (2 gray levels)
- P2 : PGM ASCII Grayscale
- P3 : PPM ASCII Color
- P4 : PBM RAW Black & White (2 gray levels)
- P5 : PGM RAW Grayscale
- P6 : PBM RAW Color
We will use mostly P5 with some use of P2.
PGM: Black & White is for binary images like text
where you can get by with only two gray levels (black
and white).
PGM: Grayscale is for normal monochrome images with
more than two gray levels. Typically the number of
gray levels is a multiple of 2: (4, 8, 16, 32, 64, 128,
or 256).
PPM: Color has three values for each pixel. If the
number of color levels per color is less than or
equal to 256, then you can use three bytes (1 for
red, 1 for green, 1 for blue).
ASCII is readable by a text editor. This is useful
for hand generating an image, but quickly gets
tedious.
RAW is the most compact. After the ASCII header information,
the image is a block of binary data 8 bits per pixel assuming
the maximum gray level used is less than 256.
Comments in the file are indicated by a leading # on the comment.
Sometimes tools put comments into the file. Be sure you can
skip over them when you read the file. (My program does this.)
Each additional line of comments must start with a #.
Pixel Relationships
- Neighbors
- 4-neighbors N4(p) (left, right, top, bottom)
- 4 diagonal neighbors ND(p) (upper left, upper right,
lower left, lower right)
- 8-neighbors N8(p) = N4(p) + ND(p)
- Border pixels are special cases.
-
connectivity,
N4,
N8,
ND,
M-connectivity,
NM,
sample0,
sample1, and
sample2.
- Adjacency
- Based on a set of gray levels called V(G). If
V(G)={3,4,5}, then only pixels with these gray levels
are considered for adjacency.
-
- 4-adjacency: p and q with values from V are 4-adjacent
if q is in the set N4(p).
- 8-adjacency: p and q with values from V are 8-adjacent
if q is in the set N8(p).
- m-adjacency: p and q with values from V are m-adjacent
if q is in N4(p) or q is in ND(p) AND the set N4(p) intersect N4(q)
has no pixels from V. (See Fig2.26)
- Path
A path exists from p to q if you can find
a sequence of pixels that are adjacent to each
other along the path. (4, 8, or m paths depending
on 4, 8, or m-adjacency)
- Connectivity
- Two pixels are said to be connected if there
exists a path between them. (4, 8, or m connectivity)
- Distance
- Euclidean (shortest path)
- D4 distance (city-block path)
- D8 distance (chessboard path)