Specifically, how many have had a course on information theory?
How many know how to correlate information content to entropy?
Example: dictionary reference. 7 bits for word-on-page, 9 bits for page number, 16 bits for each English word.
This compression is lossless if algorithm can handle words that are not in the dictionary (plural, third-person verbs, past tense, slang, acronyms, made-up words, etc). Otherwise it is lossy ("I went and bought Nikes" becomes "I go and buy sneaker").
If lossy, what do you lose?
Compression ratio.
Example: data (24 bits) is
RLE is lossless.
RLE is good for compressing images with large uniform areas (scanned text: 8-to-1 compression).
Example: data (24 bits) is
DCPM is like RLE, but allows small variations in the data (e.g. real-world images).
DPCM good for reducing the dynamic range of pixel values (adjacent pixels are usually similar).
The table must be shared between compression and decompression: either
("encrypt-compress") has been used for encryption, but is inefficient since the shared secret (the dictionary) is large. Also, this is subject to frequency analysis.
("included-table") has the advantage that the dictionary can be customized to the data.
Example: Liv-Zemple (LZ) compression.
Encode less-frequently-occurring bit strings with longer code words, or with themselves.
(One of many possible algorithms).
7f45 4c46 0102 0100 0000 0000 0000 0000 0002 0002 0000 0001 0001 3644 0000 0034 0014 3f38 0000 0000 0034 0020 0005 0028Dictionary:
word | frequency | code |
0000 | 8 | 0 |
0001 | 2 | 100 |
0002 | 2 | 101 |
0034 | 2 | 110 |
others | 1 | 111+word |
This example assumes we have decided to encode 16-bit "words". Other possibilities include shorter words, longer words, or variable-length words.
7f45 4c46 0102 0100 0000 0000 0000 0000 0002 0002 0000 0001 0001 3644 0000 0034 0014 3f38 0000 0000 0034 0020 0005 0028Dictionary (89 bits) -- note mixed notation:
01.0.0000 11.100.0001 11.101.0002 11.110.0034 00.11.111Encoding (216 bits) -- note mixed notation:
111.7f45 111.4c46 111.0102 111.0100 0 0 0 0 101 101 0 100 100 111.3644 0 110 111.0014 111.3f38 0 0 110 111.0020 111.0005 111.0028Compression ratio is (384 - 216 - 89) / 384 = 21%.
JPEG standard lets the compression quality be traded against image quality and viceversa.
DCT computes spatial frequencies for a data set (for JPEG, for an 8 * 8 block).
Except for quantization errors, the spatial frequencies can be converted (using inverse DCT) back into the data set, so DCT is not lossy.
Intuition: spatial frequency (0, 0) is the "DC", "constant", or "offset" for the entire block (how light or dark the entire block is). Higher frequencies correspond to variations in the image: highest frequencies are the sharpest edges.
JPEG uses more bits for the low spatial frequency components. Only the more significant bits of higher spatial frequency components are retained.
The exact algorithm is to divide each spatial frequency (the result of the DCT phase) by a corresponding coefficient stored in a table. The table has small coefficients for low frequencies and large coefficients for high frequencies.
For example, the coefficient for (0,0) might be 4, so only the 2 least significant bits are lost. The coefficient for (7,7) might be 32, so the 5 least significant bits are lost.
JPEG specifies a set of quantization tables.
The variant is that only the length of runs of zero values are encoded -- all other values are encoded as themselves. Since many of the higher-frequency components have been divided by large coefficients, they are likely to be zero.
Also, the DC coefficient is likely to be the same as in the previous block, and is encoded using DPCM.