Variable bit-rate coding reduces average storage by assigning short codes to frequent symbols and longer codes to rare symbols. Its benefit depends on the symbol distribution: skewed frequencies compress well, while equally probable symbols may not. section 6.2
A four-color image
For an image containing 12 green, 2 red, 1 blue, and 1 yellow pixels, use G = 0, R = 10, B = 110, and Y = 111. The image requires 22 bits, or 1.375 bits per pixel, instead of 32 bits with fixed two-bit codes. With four colors occurring equally often, the same variable codes require 36 bits, so fixed-length coding performs better. section 6.2
| G(reen) = 0 |
Use the code table to see how prefix-free assignments give the most probable color the shortest representation. section 6.2
Table 6.3 Entropy computation for the pair of images in figure 6.1. The right-hand image has lower entropy and can be compressed more.
| Left image |
Right image |
|---|---|
| x1 = G, p(x1) = 4/16 = 0.25 |
x1 = G, p(x1) = 12/16 = 0.75 |
| x2 = R , p(x2) = 4/16 = 0.25 |
x2 = R , p(x2) = 2/16 = 0.125 |
| x3 = B, p(x3) = 4/16 = 0.25 |
x3 = B, p(x3) = 1/16 = 0.0625 |
| x4 = Y, p(x4) = 4/16 = 0.25 |
x4 = Y, p(x4) = 1/16 = 0.0625 |
| ℍ = −(0.25 log(0.25)+0.25 log(0.25) + |
ℍ = −(0.75 log(0.75)+0.125 log(0.125) + |
Compare symbol probabilities and entropy: the image dominated by green has lower entropy and supports stronger compression. section 6.2
