Thursday, October 09, 2008

Quantization

Quantization is where the actual data compression occurs, by a shortening of the transformed data wordlength. The transform is invertible, so that no data compression actually occurs there. A quantizer is a nonliner, zero-memory device that choose representative values for ranges of input data coming from the transform one-at-a-time, called scalar quantization, or several-at-a-time, called vector quantization. The quantization operation is one of truncation or rounding.  x->Q(.)->x'
          r1 -- d_1  < x < d_1
Q(x) = ri -- d_i-1 < x < d_i
          rj -- d_j-1 < x < d_j
quantizatioin_example

A quantization matrix is used in combination with a DCT coefficient matrix. Quantization matrices are often specifically designed to keep certain frequencies in the source to avoid losing image quality. An example DCT coefficient matrix:

\begin{bmatrix}
 -415 & -33 & -58 &  35 &  58 & -51 & -15 & -12 \\
    5 & -34 &  49 &  18 &  27 &   1 &  -5 &   3 \\
  -46 &  14 &  80 & -35 & -50 &  19 &   7 & -18 \\
  -53 &  21 &  34 & -20 &   2 &  34 &  36 &  12 \\
    9 &  -2 &   9 &  -5 & -32 & -15 &  45 &  37 \\
   -8 &  15 & -16 &   7 &  -8 &  11 &   4 &   7 \\
   19 & -28 &  -2 & -26 &  -2 &   7 & -44 & -21 \\
   18 &  25 & -12 & -44 &  35 &  48 & -37 & -3
\end{bmatrix}

A common quantization matrix is:

\begin{bmatrix}
 16 & 11 & 10 & 16 & 24 & 40 & 51 & 61 \\
 12 & 12 & 14 & 19 & 26 & 58 & 60 & 55 \\
 14 & 13 & 16 & 24 & 40 & 57 & 69 & 56 \\
 14 & 17 & 22 & 29 & 51 & 87 & 80 & 62 \\
 18 & 22 & 37 & 56 & 68 & 109 & 103 & 77 \\
 24 & 35 & 55 & 64 & 81 & 104 & 113 & 92 \\
 49 & 64 & 78 & 87 & 103 & 121 & 120 & 101 \\
 72 & 92 & 95 & 98 & 112 & 100 & 103 & 99
\end{bmatrix}

Using this quantization matrix with the DCT coefficient matrix:

\begin{bmatrix}
 -26 & -3 & -6 &  2 &  2 & -1 & 0 & 0 \\
   0 & -3 & 4 &  1 &  1 &  0 & 0 & 0 \\
  -3 &  1 &  5 & -1 & -1 &  0 & 0 & 0 \\
  -4 &  1 &  2 & -1 &  0 &  0 & 0 & 0 \\
   1 &  0 &  0 &  0 &  0 &  0 & 0 & 0 \\
   0 &  0 &  0 &  0 &  0 &  0 & 0 & 0 \\
   0 &  0 &  0 &  0 &  0 &  0 & 0 & 0 \\
   0 &  0 &  0 &  0 &  0 &  0 & 0 & 0
\end{bmatrix}

For example, using −415 (the DC coefficient) and rounding to the nearest integer

\mathrm{round}
\left(
 \frac{-415}{16}
\right)
=
\mathrm{round}
\left(
 -25.9375
\right)
=
-26

Former post 1, post 2.

No comments:

Post a Comment