Title: VIII. Data Compression (B)
1VIII. Data Compression (B)
? 8-A Lossless Coding
?????????????????
Example
direct coding method Huffman coding Arithmetic
coding ShannonFano Coding, Golomb coding,
LempelZiv, .....
2256
? 8-B Differential Coding for DC Terms,
Zigzag for AC Terms
?????? JPEG Huffman coding ?????
Differential Coding (????)
If the DC term of the (i, j)th block is denoted
by DCi, j, then
encode DCi, j DCi, j-1
Instead of DCi, j
(???? space domain ?????)
3257
Zigzag scanning
? 2D ? 8x8 DCT outputs ?? 1D ???
??? zigzag ??? (??????????)
n 0, 1, 2, 3, 4, 5, 6, 7
m 0, 1, 2, 3,
4, 5, 6, 7
8x8 DCT output Cm, n m 0, 1, , 7 n 0, 1,
, 7
??
??
(???? frequency domain ?????)
4258
? 8-C Lossless Coding Huffman Coding
? Huffman Coding ????? (Greedy Algorithm)
(1) ?????? Coding Tree ???,???????
(???????????) (2) ?????, code length ???????,
code length ?? (3)?? Sa ?? L ?? node,Sb?? L1 ??
node ? P(Sa) ? P(Sb)
???? ???????????
5259
??????? ? data ? M ?????,?? k ?????, ??????????
floor(logkM) ? ceil(logkM) ? bits ???
floor ?????
ceil ?????
Example
?? 8 ?????,?2??????,?? 3 ? bits
?? 10 ?????,?3??????,?? 2 ?? 3 ? bits
6260
Example
? ? ? ? ?
832700 801000 114000 7700 4390
? ? ? ? ?
3920 11700 11700 3130 36500
?? 3???Huffman Code ????
7261
????????
1826740
0
1
2
59900
1747700
19140
2
0
1
0
1
2
2
0
1
36500
11700
11700
7050
832700
801000
114000
7700
4390
10
11
12
00
01
02
20
21
?
?
0
1
exchange
3920
3130
average code length 2.004
220
221
8262
1826740
0
1
2
59900
934140
832700
?
2
0
1
2
0
1
2
19140
36500
11700
11700
801000
114000
01
02
10
11
12
?
0
1
2
7050
7700
4390
000
001
1
0
3920
3130
0020
0021
9263
1826740
832700
801000
193040
?
?
59900
114000
19140
36500
11700
11700
7050
7700
4390
3920
3130
10264
1826740
0
2
1
193040
801000
832700
1
2
?
?
0
2
1
36500
42540
114000
00
02
0
1
2
11700
11700
19140
012
011
2
0
1
average code length 1.143
7050
7700
4390
0100
0101
1
0
3920
3130
01020
01021
11265
?? ????????????? ?????????????????
?????????????? ??? Huffman
coding ????????
12266
? 8-D Entropy and Coding Length
? Entropy ??? (Information Theory)
??? log ? ln ? log10 ??
P probability
P(S0) 1, entropy 0 P(S0) P(S1)
0.5, entropy 0.6931 P(S0) P(S1) P(S2)
P(S3) P(S4) 1/5, entropy 1.6094 P(S0)
P(S1) P(S2) P(S3) 0.1, P(S4) 0.6, entropy
1.2275
???? 5 ???,???????,????
13267
? Huffman Coding ?????
P(Sj) Sj ?????, L(Sj) Sj ?????
? Shannon ????
??? k ?????
? Huffman Coding ? total coding length
N data length
?? entropy ?????
14268
Entropy ?? coding length ?????
15269
? 8-E Arithmetic Coding
? Arithmetic Coding (????)
Huffman coding ??????????? Arithmetic coding
???????????,??????? Huffman coding
??,?????????????? arithmetic coding
K. Sayood, Introduction to Data Compression,
Chapter 4 Arithmetic coding, 3rd ed., Amsterdam,
Elsevier, 2006
16270
??
? data X ? M ????? (Xi 1, 2, , or M),?? k
?????,?
???? data X ???,?? length(X) N
Algorithm for arithmetic encoding
initiation
for i 2 N
(continue)
end
17271
Suppose that
where C and b are integers (b is as small as
possible), then the data X can be encoded by
where means that using k-ary (k ??) and
b bits to express C.
(? Arithmetic coding ?????????,?????????????
range encoding ???)
18272
Example
???? X ????? (k 2) ??? ????????,Xi a ????
0.8, Xi b ???? 0.2 ?????????? X a a a b
a a
Initiation (X1 a)
When i 2 (X2 a)
When i 3 (X3 a)
When i 4 (X4 b)
When i 5 (X5 a)
When i 6 (X6 a)
19273
??
0.4375
0.46875
????????
2 ??
5 ? bits
20274
1
b
0.8
ab
0.64
aab
0.512
0.49152
aaab
0.475136
a
aa
aaaba
aaabaa
aaa
0.4096
aaaa
0
21275
??
???????? Y, length(Y) b
?????,??? (see page 270) ??
Algorithm for arithmetic decoding
initiation
for i 1 N loop 1
check 1
while check 1 loop 2
if there exists an n such that lower
(upper-lower)Sn-1 ? lower 1 and lower
(upper-lower)Sn ? upper 1 are both
satisfied, then X(i) n
check 0
(continue).
22276
else
j j1
end
end end of loop 2
end end of
loop 1
23277
Coding Length for Arithmetic Coding
??
???? Xi n ???
????? Xi n ???
(????,? length(X) N, X ???? ? elements
?? n)
?
????
????,?? (from page 271)
???,???
24278
??????????????,
Total coding length b ????
Arithmetic coding ? total coding length ????
Huffman coding ??
25279
? 8-F MPEG
MPEG ??????????? ?? Moving Picture Experts
Group MPEG standard http//www.iso.org/iso/prod
s-services/popstds/mpeg.html MPEG ????
http//mpeg.chiariglione.org/
??????? 1/24 second
??????,??? 30?? 60???
26 ?? Pepsi ??? Size 160 ? 120 Time
29 sec ?? 30 ??? ????? 160
? 120 ? 29 ? 30 ? 3 50112000 47.79 M bytes?
?? MPEG?? 1140740 1.09 M bytes?
????? 2.276?
27281
? Flowchart of MPEG Compression
JPEG ???
I ??
MPEGfile
???
????
Video
P ??
????
????
B ??
JPEG ???
??
28282
I ?? (Intra-coded picture) ??????? P ??
(Predictive-coded picture) ?????????? B ??
(Bi-directionally predictive-coded picture)
?????????????
??
P ??
I ??
??
??
I ??
B ??
I ?? or P ??
29283
? ???????
??????,??? pixel ?????????? ???????
objects ?? motion vector
? ???? (Motion Compensation)
???????,?????????
frame n
frame n1
frame n2
30284
Fm, n, t ??? t??? ??? Fm, n,
t, Fm, n, t? ??? Fm, n, t2?? (1)
???? Vx(m, n), Vy(m, n) (2) ??
Fm, n, t2? Fpm, n,
t2? Fm - Vx(m, n), n - Vx(m, n), t?
(3) ?? ?????? Em, n,
t2? Fm, n, t2? ? Fpm, n, t2?
????? Em, n, t2? ? DCT ??
31285
? 8-G Data Compression ???????
Two important issues
- Q1 How to further improve the compression rate
- Q2 How to develop a compression algorithm whose
compression rate is acceptable and the
buffer size / hardware cost is limited
32286
???????????????????
??????
?????
TP
FN
FP
TN
TP (true positive) ?????,???????????????
FN (false negative) ?????,???????????????
FP (false positive) ??????,??????????????
TN (true negative) ??????,?????????????????
33287
??????,TP ???????????,FP??????????,FN
???????????,TN ???????????
??????,???????
recall ?,? precision ?
??????,???????
precision ?,? recall ?
34288
Accuracy
Detection error rate
F-score
General form of the F-score