You are on page 1of 5

Idea of Transform Coding

1) Transform the input pixels x0,x2,...,xN-1 into


CSE 592 coefficients c0,c1,...,cN-1 (real values):
– The coefficients should have the property that most of
Data Compression them are near zero.
Fall 2006 – Therefore most of the “energy” is compacted into a few
coefficients.
Lecture 14: 2) Scalar quantize the coefficient:
Transform Coding – This is bit allocation!
JPEG – Important coefficients should have more quantization
levels (== represented with more accuracy).
3) Entropy encode the quantized values.
3

Decoding Block Diagram of Transform Coding

1) Entropy decode the quantized values. Encoder


input coefficients symbols
bit stream
x c s b
2) Compute approximate coefficients c’0,c’1,...,c’N-1 quantization entropy
transform bit allocation coding
from the quantized values.

3) Inverse transform c’0,c’1,...,c’N-1 to x’0,x’1,...,x’N-1


which is (we hope) a good approximation of the symbols coefficients output
original x0,x1,...,xN-1. entropy s decode c’ inverse x’
decoding symbols transform

Decoder
4 5

Mathematical Properties of Transforms Why Coefficients?


A c=x
T

• Linear Transformation:  a 00 L a N -1,0   c 0   x 0 


 
M   M  =  M 
– Defined by a real N x N matrix A = (aij)
 M
 a 00 L a 0,N-1   x 0   c 0   a 0,N -1 L a N -1, N -1  c N -1   x N -1 
 
 M M   M  =  M   a 00   a N -1,0   x0 
     
aN-1,0 L aN-1,N-1   xN-1  c N-1   M c
 0 + L +  M =
 N −1  M 
c
 a 0,N -1  a N -1,N -1   x N -1 
• Orthonormality: A −1 = A T (transpose)

basis vectors coefficients


6 7

1
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Why Orthonomality? Example (with Compaction)
1 1 1 
• The energy of the data equals the energy of A=  
the coefficients:
2 1 − 1
A 2 = I ⇒ A −1 = A
N−1

∑c
i=0
i
2
= c T c = (Ax)T (Ax) A T = A = A −1 orthonormal

N−1
= (x T A T )(Ax) = x T (A T A)x = x T x = ∑ x i 1 1 1  b  2b
2

   =   compaction
i =0
2 1 − 1 b  0 
8 9

Discrete Cosine Transform (1D) Basis Vectors (1D)


 1 1 1

 i=0
aij =  N 0.5 0.5

 2 (2 j + 1)iπ 0 0
cos i >0 0 1 2 3 0 1 2 3
 N 2N -0.5 -0.5

-1 -1

row 0 row 1
N = 4:
1 1
 .5 .5 .5 .5 
 .65328 .270598 - .270598 - .65328  0.5 0.5

A=  0 0
 .5 - .5 - .5 .5  0 1 2 3 0 1 2 3
  -0.5 -0.5
.270598 - .65328 .65328 - .270598 -1 -1

row 2 row 3
10 11

Decomposition in Terms of Basis


Block Transform
Vectors

.5  .653281   .5   .270598   x0  Image


Each 8x8 block is
.5  .270598  −.5  - .653281   individually coded
 c +  c +  c +  c =  x1 
.5 0
− .270598 1
−.5 2
 .653281  3
 x2 
         
.5
   - .653281 .5
  − .270598  x3 

DC coefficient AC coefficients

12 13

2
CuuDuongThanCong.com https://fb.com/tailieudientucntt
2-Dimensional Block Transform 8x8 DCT Basis Vectors

Block of pixels X Transform

x00 x01 x02 x03 a00 a01 a02 a03 


a a11 a12 a13 
x10 x11 x12 x13
A= 
10

x20 x21 x22 x23 a20 a21 a22 a23 


 
x30 x31 x32 x33 a30 a31 a32 a33 

N−1
Transform rows rij = ∑ a kj xik
k =0
N −1 N−1 N−1 N −1 N −1
Transform columns c ij = ∑ aimrmj = ∑ a im ∑ akj x mk = ∑ ∑a a x mk
im kj
m= 0 m =0 k =0 m= 0 k = 0

Summary: C = AXA T

14 15

Importance of Coefficients Quantization Tables


• The DC coefficient is (in general) the most important.
• The AC coefficients (in general) become less • For an nxn block we construct an nxn matrix Q:
important as they are farther from the DC coefficient.
– Qij indicates how large the quantization interval is for
• One example bit allocation (bits per coefficient):
coefficient cij.
8 7 5 3 2 1 0 0 • Encode cij with the label:
7 5 3 2 1 0 0 0 compression
 c ij 
5 3 2 1 0 0 0 0 55 bits for 64
pixels = .86 bpp
sij =  + 0.5
3 2 1 0 0 0 0 0  Qij 
• Decode sij to:
2 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0 c'ij = sijQij.
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
16 17

Example Quantization Example Quantization Table (JPEG)


16 11 10 16 24 40 51 61
• c = 54.2, Q = 24 s =  54.2 + 0.5 = 2 12 12 14 19 26 58 60 55
 24 
14 13 16 24 40 57 69 56
c' = 2 ⋅ 24 = 48
14 17 22 29 51 87 80 62
• c = 54.2, Q = 12  54.2  18 33 37 56 68 109 103 77
s= + 0.5 = 5
 12  24 35 55 64 81 104 113 92
c' = 5 ⋅12 = 60 49 64 78 87 103 121 120 101
72 92 95 98 112 100 103 99
• c= 54.2, Q = 6  54.2 
s= + 0.5 = 9
 6  Increase the bit rate = halve the size of quantization intervals.
c' = 9 ⋅ 6 = 54 Decrease the bit rate = double the size of quantization intervals.

18 19

3
CuuDuongThanCong.com https://fb.com/tailieudientucntt
JPEG (1987) Block Transmission

• Let P = [pij], 0 < i,j < N be an image with 0 < pij < 256. • DC coefficient:
• Center the pixels around zero: – DC coefficients don’t change much from block to
– xij = pij - 128 neighboring block. Hence, their labels change
• Code 8x8 blocks of X using the DCT. even less.
• Choose a quantization table: – Predictive coding with differences is used to code
– The table depends on the desired bit rate and is built into the DC label.
JPEG.
• AC coefficients:
• Quantize the coefficients according to the quantization
– Do a zig-zag coding.
table:
– The quantization symbols can be positive or negative.
• Transmit the labels (in a coded way) for each block.

20 21

Zig-Zag Coding Example Block of Labels

• AC labels are coded in zig-zag order:


2 0 0 0 0 0 0
– Usually use a special entropy coding to take advantage of
the ordering of the bit allocation (quantization). -8 0 0 0 0 0 0 0
3 1 1 0 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
0 0 0 0 0 0 0 0

Coding order of AC labels


2 –8 3 0 0 0 0 1 1 0 0 1 0 0 .....

22 23

Coding Labels Coding AC Label Sequence

• Categories of labels • A symbol has three parts (Z,C,B)


– 1 {0} – Z for number of zeros preceding a label 0 < Z < 15
– 2 {-1, 1} – C for the category of the of the label
– 3 {-3,-2,2,3} – B for a C-1 bit number for the actual label
– 4 {-7,-6,-5,-4,4,5 6 7} • End of Block symbol (EOB) means the rest of
• Label is indicated by two numbers Cat,B the block is zeros. EOB = (0,0,-)
• Examples label C,B • Example: 2 –8 3 0 0 0 0 1 1 0 0 1 0 0 .....
0 1
2 3, 2 (0,3,2)(0,5,7)(0,3,3)(4,2,1)(0,2,1)(2,2,1)(0,0,-)
-4 4, 3
24 25

4
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Coding AC Label Sequence Notes on Transform Coding

• Z,C have a prefix code Partial prefix • Video Coding:


• B is a C-1 bit number code table – MPEG uses DCT.
C – H.263 and H.261 use DCT.
0 1 2 3
0 1010 00 01 100 • Audio Coding:
1 1100 11011 11110001
– MP3 = MPEG 1 Layer 3 uses DCT.
Z 2 1110 11111001 1111110111
3 111010 111110111 111111110101 • Alternative Transforms:
– Lapped transforms remove some of the blocking
(0,3,2) (0,5,7) (0,3,3) (4,2,1) (0,2,1) (2,2,1) (0,0,-) artifacts.
100 10 11010 0111 100 11 1111111000 1 01 1 11111001 1 1010 – Wavelet transforms do not need to use blocks at
all.
46 bits representing 64 pixels = .72 bpp
26 27

5
CuuDuongThanCong.com https://fb.com/tailieudientucntt

You might also like