# How to determine a quantization table for image compression with DCT?

The quantization table is given on the JPEG Wiki page. How was this table derived? I'm currently doing a project where I have to come up with custom quantization table for an image, but I don't know how to begin. I figure if I learn how the JPEG table was derived, I might come up with a semi-original idea.

The standard JPEG quantization table is a actually an 8 x 8 matrix of weights whose elements divide the corresponding elements of the 2D-DCT coefficient matrix of an 8 x 8 image block.

The division effectively reduces the magnitude of the DCT coefficients and most of them are forced to be zero, due to the integer divison rounding.

The standard table is determined to yield a minimum distortion under maximum compression applied to the most typical image (i.e., exhaustive average of large image data set) and typical viewer visual characteristics.

As a result of this quantization, high frequency coefficients are reduced as much as possible.

Note that the JPEG quality parameter provides a means of scaling the standard quantization table weights, but no control over individual elements.

You can also design and use a specific quantization table for your needs, according to the rate-distortion criteria you have in your mind. But this requires you to embed Q table information within the compressed data bitstream.

• could I somehow perform an analysis of the 8x8 DCT coefficients so I can see which pixels in any 8x8 block exhibit the most variance and then create a quantization table based on the calculated variance? Nov 26 '18 at 0:08
• yes (probably) you could something similar. But then you should also embed that specific quantization table into the JPEG bit stream and hence lose the very means of compression refficiency... Nov 26 '18 at 0:13
• Is is possible to optimize the quantization table to the whole image. It will cause the overhead of storing the quantization table on the header, but I usually leads to good results. That is the approach done by the JPEG encoder Guetzli created by Google. See: github.com/google/guetzli
– LEo
Aug 23 '19 at 17:16
• @LEo yes you can design a whole image optimized quantization table and transmit this (or embed) with the compressed picture data. Aug 23 '19 at 21:57