IP 02 · What do you lose with fewer pixels, and what with fewer gray levels?
BeginnerImages as ArraysImage lab
Description
Keep every s-th pixel and fewer gray levels of a real photo and of a synthetic zone plate, and see false patterns (aliasing) appear unless you filter first.
Try this: Set the stride to 1 and the bits to 3 (8 gray levels): the photo shows bands, yet its PSNR is higher than with stride 4 at 8 bits, and even higher than with stride 2. Which loss does PSNR punish more? Then set the bits back to 8 and compare the zone plate at strides 2, 4 and 8: where do the false rings begin, and how does that radius shrink with the stride? Finally turn the Gaussian prefilter on.
Hints
The chapter section that uses this lab:
Explanation
Answer the prediction first, or open the explanation when you are ready.
Show the explanation
Point sampling keeps one pixel and ignores the other fifteen in its block, so fine detail is not removed but misread as a coarse pattern. A Gaussian with σ = 2 first replaces each pixel by a local average, which is a better guess for the whole block. On the photo the PSNR rises from 19.6 to 21.6 dB, on the zone plate from 6.4 to 9.2 dB, and the contrast of the false rings (beyond radius 45 px, where the true pattern is finer than a stride-4 grid can show) falls from 0.35 to 0.02. Honest limits: the blur restores no detail, so the zone plate is still poor, and the picture is softer. Across strides 2 to 8 and 2 to 8 bits the prefilter raised PSNR on both images in every case; only at 1 bit did it lower the PSNR of the zone plate slightly.
Lab · IP 02 · What do you lose with fewer pixels, and what with fewer gray levels?
Loading image…
Try this: Set the stride to 1 and the bits to 3 (8 gray levels): the photo shows bands, yet its PSNR is higher than with stride 4 at 8 bits, and even higher than with stride 2. Which loss does PSNR punish more? Then set the bits back to 8 and compare the zone plate at strides 2, 4 and 8: where do the false rings begin, and how does that radius shrink with the stride? Finally turn the Gaussian prefilter on.
Photo: the camera test image, 256 × 256. Zone plate: synthetic, 256 × 256, I(r) = 0.5 + 0.5 cos(k r²) with r the distance from the centre and k = π / (2 r_max), so its local frequency rises linearly to 0.5 cycles per pixel at the corner. Sampling keeps pixel (0, 0) of every stride × stride block (a[::s, ::s]); gray levels use the chapter’s rule of rounding to the centre of one of 2^bits bins; the result is enlarged by pixel replication (nearest neighbour) so single samples stay visible. The optional prefilter is a Gaussian with σ = stride / 2 applied before sampling. PSNR compares the enlarged result with the original 8-bit image (peak 255). False-pattern contrast is the standard deviation of the kept zone-plate samples that lie beyond radius π / (2 · stride · k), where the true pattern is finer than the coarse grid can show; a faithful result is flat gray there, so a large value means false rings. PSNR cannot tell a false pattern from honest blur, which is why both numbers are shown.
Method and image sources
- Rafael C. Gonzalez & Richard E. Woods, Digital Image Processing, 4th ed., Pearson, 2018, Chapter 2 (sampling and quantization)
- scikit-image test images (skimage.data): camera is CC0 by Lav Varshney; coins is from the Brooklyn Museum collection, no known copyright restrictions; astronaut is a NASA photograph in the public domain