Lecture
Lecture
Mei-Chen Yeh
2010/03/16
Announcements (1)
• Assignment formats:
– A word or a pdf file
– Subject (主旨):
Multimedia System Design-Assignment #X-your
student id-your name
Multimedia System Design-Assgnment #2-697470731-游宗毅
– File name (檔名)
Assignment #X-your student id-your name
Assignment #2-697470731-游宗毅.doc
Announcements (2)
• For the assignment#2…
• If you did not use either a pdf or a doc file, please re-send
your report to TA using the format.
• Due 03/16 (today)
…and based on TA’s clock
Announcements (3)
• The reading list is finally released!
• Sources:
– Proceedings of ACM MM 2008
– Proceedings of ACM MM 2009
– The best paper in MM 2006 and MM 2007
• Interesting papers not on the list? Let me
know!
Announcements (4)
• So you need to…
– Browse the papers
– Discuss with your partners about the paper choice
– …and do it as soon as possible! I love that paper!
• Google search
Next week in class
• Bidding papers! (論文競標)
• Each team will get a ticket, where you put
your points.
Ticket # 7
Team name: 夜遊隊
Team members: 葉梅珍 游宗毅
-------------------------------------------------------------------
paper1 paper2 paper3 paper4 … paper 25
50 10 15 20 5
Total : 100 points
Bidding rules
• The team with the most points gets the paper.
• Every team gets one paper.
• When a tie happens…
Questions
Multimedia Compression (1)
Outline
• Introduction
• Information theory
• Entropy (熵) coding
– Huffman coding
– Arithmetic coding
Why data compression?
• Transmission and storage
Compression Reconstruction
• Lossy
– Involves loss of information
Example: image codec Lossy!
Encoder Decoder
Lossless?
source Not necessarily true!
Performance Measures
How do we say a method is good or bad?
Encoder
Fewer bits!
• Modeling
– Discover the structure in the data
– Extract information about any redundancy
• Coding
– Describe the model and the residual (how the
data differ from the model)
Example (1)
n
xˆn n 8 n 1,2,...
Example: Coding
Original data xn
Model xˆn n 8 10 11 12 13 14 15 16 17 18 19 20
Residual en xn xˆn 0 1 0 -1 1 -1 0 1 -1 -1 1 1
• {-1, 0, 1}
• 2 bits * 12 samples = 24 bits (compared with
60 bits before compression)
We use the model to predict the value, then encode the residual!
Another Example
• Morse Code (1838)
letter
_ codeword
alphabet code
Prefix code
instantaneous
Coding (3)
• Example of not uniquely decodable code
Letters Code
a1 0
a2 1 a2 a3 => 100
a3 00 a2 a1 a1 => 100
a4 11
back
Coding (4)
• Not instantaneous, but uniquely decodable
code
a2
Oops!
a2 a3 a3 a3 a3 a3 a3 a3 a3
Prefix Codes
• No codeword is a prefix to another codeword
• Uniquely decodable
Huffman Coding
• Basic algorithm
• Extended form
• Adaptive coding
Huffman Coding
• Observations of prefix codes
0 (1) (1)
0
a’1(0.6) 1
0
a’2(0.6)
a’3(0.4)
1 1
1 1
0 a’4(0.2) 0 a’4(0.2) a’1(0.4)
0 1 0 1 0 1
a3(0.2) a4(0.1) a5(0.1) a1 (0.2) a2 (0.4) a2 (0.4) a4(0.1) a5(0.1) a1(0.2) a3(0.2)
000 0010 0011 01 1 00 010 011 10 11
H = 0.816 bits/symbol
= 1.2 bits/symbol
1
H (S ) l H (S )
blk size
H = 1.6315 bits/block = 0.816 bits/symbol
= 1.7228 / 2 = 0.8614 bits/symbol
Adaptive Huffman Coding (1)
• No initial knowledge of source distribution
• One-pass procedure
• Based on statistics of encountered symbols
Id: 1 2 3 4 5 6 7 8 9 10 11
w: 2 3 5 5 5 6 10 11 11 21 32
Non-decreasing!
Adaptive Huffman Coding (3)
• NYT (not yet transmitted) code
– w(NYT) = 0
– Transmitted when seeing
a new letter
– Smallest id in the tree
• Uncompressed code
(ex: m letters)
Adaptive Huffman Coding: Encode (1)
Input: [a a r d v a r k] (Alphabet: 26 lowercase letters)
Initial tree
a a NYT r
00000 1 0 10001
3 3 2
Swap 47 and 48
Adaptive Huffman Coding: Encode (4)
Tree update
5
3 2
49 50
48
47
45 46
Swap 49 and 50
43 44
Adaptive Huffman Coding: Decode (1)
Input: 0000010100010000011001011…
Initial tree
0000 00000 1
Not in the uncompressed code
Get one more bit
a a
Output: a a
Adaptive Huffman Coding: Decode (2)
Input: 0000010100010000011001011…
0 1000 10001 00
NYT Not in the uncompressed code r NYT
Get one more bit
Output: aa r ……
Arithmetic Coding
• Basic algorithm
• Implementation
Cases where Huffman Coding doesn’t work well
a1 a1 a1 a1
a1 a1 a1
a1 a2 a3
l(1) = 0.0 l(2) = 0.0+(0.7-0.0)*0.7=0.49 l(3) = 0.7+(0.8-0.7)*0.8
u(1) = 0.7 u(2) = 0.0+(0.7-0.0)*0.8=0.56 u(3) = 0.7 +(0.8-0.7)*1.0
One more example
• A = {a1, a2, a3}, P(a1) = 0.8, P(a2) = 0.02, P(a3) = 0.18
Encode a1, a3, a2, a1
a1 a1 a1 a1 (0.7712+0.773504)/2
= 0.772352
(0.772352-0.0)/(0.8-0.0) (0.772352-0.656)*(0.8-0.656)
= 0.96544 = 0.808
a1 a1 a1 a1
a1 a1 a3 send 1 send 1
a2
0.8 a2
0.82
1.0
a3 send 0
a1
0.7734375
send 1 =(.1100011)2
How to stop?
1.Send the stream size
2.Use EOF (00…0)
Implementation: Decode (1)
Input: 11000110…0
Find the smallest interval (0.82-0.8=0.02) => 6 bits
(2-6 < 0.02) 11000110…0
11000110…0
11000110…0
.110001=0.765625 11000110…0
decode a1
11000110…0
11000110…0
.100011=0.546875
update code: update code:
(0.765625-0)/(0.8-0) (0.546875-0.312)/0.6-0.312
11000110…0
=0.957 =0.8155
decode a3 decode a2
Implementation: Decode (2)
11000110…0
.10=0.5
update code:
(0.5-0.3568)/(0.54112-0.3568)
=0.7769
decode a1
Enhancement (optional)
• One more mapping:
– E3: [0.25, 0.75) -> [0, 1); E3(x) = 2(x-0.25)
0.25 0.375
1.0 0.75
• E3E2 0.0 0.25
0.25 0.375
1.0 0.75
E3 mapping
• E3…E3E1 [¼, ½): 01 [¼+⅛, ½): 011 [¼+⅛+…, ½): 011…1
0.0 0.25 0.375 m
m
0.25 0.375 0.4375
Send 0 1 1 … 1
• E3…E3E2 Send 1 0 0 … 0
m
E3 mapping: Encode
a2
a1 a1 a3 send 1
0.8 a2
send 0
0.82
a3
1.0
send 0
E1: [0, 0.5) -> [0, 1); E1(x) = 2x m=1
E2: [0.5, 1) -> [0, 1); E2(x) = 2(x-0.5)
E3: [0.25, 0.75) -> [0, 1); E3(x) = 2(x-0.25)
E3 mapping: Encode
a1
send 1
Use 0.5
send 10…0
Output:
m=1
11000110…0
E3 mapping: Decode
Input: 11000110…0
Find the smallest interval (0.82-0.8=0.02) => 6 bits
(2-6 < 0.02)
11000110…0 m = 0
11000110…0 11000110…0
11000110…0
.110001=0.765625
decode a1
11000110…0
m=1
11000110…0
update code:
.100011=0.546875
(0.765625-0)/(0.8-0)
2*(0.546875-0.25)=0.5938 m=1
=0.957
update code:
decode a3
(0.5938-0.124)/(0.7-0.124)
=0.8155 decode a2
E3 mapping: Decode
m=1
. 10…0 = 0.5
2*(0.5-0.25)=0.5
update code:
(0.5-0.2136)/(0.58224-0.2136)
=0.7769 decode a1
Output:
a1 a3 a2 a1
Next week
• In-class paper bidding
• Decide how you distribute your points with
your partners before coming to the class!