Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

stough 202-

Preview: JPEG Compression with Zonal Coding Quantization

DIP 8.9

In this activity we’re going to synthesize a bit of the JPEG encoding standard, specifically block transform encoding and zonal coding quantization. We will look to understand how the quantization affects the image reconstruction.

Read up in DIP 8.9 or elsewhere if needed.

Imports

We’re going to take advantage of both view_as_blocks and the Discrete Cosine transform for this.

JPEG Compression

Critically, this requires you look at and understand the block_viewing_demo. There we do some kind of processing on block-by-block, and even reconstruct.

Basically

  • Take the image in [0,255][0,255] form and subtract 128. This is to center around 0. Make sure you change the dtype when you do this, or else you won’t be able to represent negatives.

  • Transform each 8x8 block using the DCT transform matrix (see make_dct_matrix, and even see how we did this transform in the basis_decomp_64pix demo).

  • Quantize the transform coefficients according the Q matrix. This is, divide the block coefficients and store the result in integer form.

  • These quantized transform blocks represent how the compressed image would be stored or transmitted. We won’t go further than just having this representation, as the point of the exercise is to understand how this quantization affects the reconstruction.

  • Reconstruction: for each transform block, remultiply according to the Q matrix and then invert the transform process (including add back 128), to reconstruct the as-though-compressed image block.

We’ll define the Q matrix, so you don’t have to transcribe it yourself.

Exercise: Interactive Quantization Demo

Put together an interactive demo that shows the original image, its current reconstruction, and a view of the currently quantized transform coefficients. This demo should then interact with a FloatSlider that affects the multiple applied to the Q quantization matrix. This demo would show how you could increase the compression (increasing the multiple) and what that increased compression would do to the image reconstruction. You might have the slider start at 15\frac{1}{5} at the low end, maybe 5 at the high end, to provide a good range from very little quantization to a lot.