Quiz: prediction, dictionaries and lossless formats

Short questions to test your understanding. Try each on paper first, then open the answer. Neighbours: a left, b up, c up-left; residual e = x - \hat x.


Q1. Why can the decoder of a predictive coder rebuild the image exactly, although it never sees the predictions \hat x?

From what is \hat x computed?

\hat x is computed only from pixels that are already decoded (left, up, up-left). The decoder has those same pixels, so it computes the same \hat x and adds the stored residual: x = \hat x + e. Nothing is rounded or thrown away.


Q2. The pixel histogram of an image is wide, the histogram of its residuals is narrow and centred at 0. Which one has the lower entropy, and what does that mean for the file size?

Fewer likely values means less information per value.

The narrow residual histogram: most residuals are a few small values, so each carries few bits. An entropy coder spends about H bits per pixel, so coding the residuals instead of the pixels makes the file smaller (in the demo’s smooth image 3.3 instead of 7.1 bits per pixel).


Q3. Where in an image are the residuals of a good predictor large?

Where do neighbours fail to predict a pixel?

At edges and fine texture (the neighbour lies on the other side of a change), and everywhere there is noise. The residual image looks like an edge map: the left-neighbour residual is a finite-difference derivative.


Q4. You add noise to an image. Does lossless compression get better or worse? Can it get worse than storing the noisy pixels without prediction?

Can a neighbour predict the noise at this pixel?

Worse: noise is new, unpredictable information at every pixel, so the residual is at least as wide as the noise. On pure noise (a flat image plus noise), prediction even makes it worse: the residual of the left predictor contains the noise of two pixels, twice the variance, about 0.5 bit more per pixel.


Q5. A vertical edge runs between c, a (left, dark) and b, x (right, bright). Which of the predictors left, up, average and MED gets x right?

Which neighbour lies on the same side of the edge as x?

b (up) is on the same side as x. Up predicts b: right. Left predicts a: wrong. Average predicts halfway: wrong. MED: c (dark) \le \min(a, b), so it predicts \max(a, b) = b: right. MED detects which side of the edge the pixel is on.


Q6. Why does PNG apply a prediction filter before DEFLATE, instead of DEFLATE alone?

What does LZ77 need to find?

LZ77 replaces exact repeats by pointers, and noisy grey values rarely repeat exactly. After prediction, smooth regions become runs of small residuals (many 0, ±1, ±2), which repeat far more often and have a narrower histogram for the Huffman stage of DEFLATE.


Q7. A 16-bit microscope image compresses losslessly by a factor of 2.3. Its owner hopes for 10. Is that realistic? What limits it?

What is the information that no lossless method can remove?

No: lossless ratios for noisy scientific images are typically 1.5–3. The camera noise is new information in every pixel; a lossless code must keep it exactly. Only removing information (lossy compression, or binning) gets to 10, and then the measurements may change (last unit of the day).


Q8. (math) The residual of a predictor has an approximately Gaussian histogram with standard deviation 4 grey levels. Estimate its entropy. How many bits do you save by halving the standard deviation?

For a Gaussian with standard deviation \sigma on integers: H \approx \log_2(\sigma\sqrt{2\pi e}).

H \approx \log_2 4 + \log_2\sqrt{2\pi e} = 2 + 2.05 = 4.05 bits. Halving \sigma subtracts \log_2 2 = 1 bit per pixel.