Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1 Li & Drew
Fundamentals of Multimedia, Chapter 7
7.1 Introduction
Compress methods are key enabling
techniques for multimedia applications.
Raw media takes much storage and bandwidth
A raw video with 30 frame/sec, resolution of
640x480, 24bit color
One second of video 30 * 640 * 480 * 3 =
27.6480 Mbytes
One hour video is about 100Gbytes
2 Li & Drew
Fundamentals of Multimedia, Chapter 7
7.1 Introduction
Compression: the process of coding that will
effectively reduce the total number of bits
needed to represent certain information.
3 Li & Drew
Fundamentals of Multimedia, Chapter 7
Introduction (contd)
If the compression and decompression processes
induce no information loss, then the compression
scheme is lossless; otherwise, it is lossy.
Compression ratio:
B0
compression ratio (7.1)
B1
5 Li & Drew
Fundamentals of Multimedia, Chapter 7
when receiving a 1 is
log_2 (1/0.75) = 0.4150 bit .
6 Li & Drew
Fundamentals of Multimedia, Chapter 7
8 Li & Drew
Fundamentals of Multimedia, Chapter 7
log2256 = 8 (7.4)
Fig. 7.2(b) shows the histogram of an image with two possible values. Its
entropy is 0.92.
10 Li & Drew
Fundamentals of Multimedia, Chapter 7
l (7.5)
11 Li & Drew
Fundamentals of Multimedia, Chapter 7
H = [-P(a)log_2P(a)] + [-P(b)log_2P(b)] +
[-P(c)log_2P(c)] + [-P(d)log_2P(d)]
= 1.95bits
12 Li & Drew
Fundamentals of Multimedia, Chapter 7
Coding scheme
A = {s1, s2, s3, s4}
P(s1) = 0.125
P(s2) = 0.125 Its entropy H = 1.75
P(s3) = 0.25
P(s4) = 0.5
s1 10 s1 01 s1 110
s2 11 s2 11 s2 111
s3 0 s3 1 s3 10
s4 0 s4 0 s4 0
Not uniquely decodeable Good codewords and
achieves lower bound
Fundamentals of Multimedia, Chapter 7
14 Li & Drew
Fundamentals of Multimedia, Chapter 7
15 Li & Drew
Fundamentals of Multimedia, Chapter 7
16 Li & Drew
Fundamentals of Multimedia, Chapter 7
17 Li & Drew
Fundamentals of Multimedia, Chapter 7
20 Li & Drew
Fundamentals of Multimedia, Chapter 7
21 Li & Drew
Fundamentals of Multimedia, Chapter 7
22 Li & Drew
Fundamentals of Multimedia, Chapter 7
Huffman Coding
ALGORITHM 7.1 Huffman Coding Algorithm a bottom-up approach
1. Initialization: Put all symbols on a list sorted according to their frequency counts.
(1) From the list pick two symbols with the lowest frequency counts. Form a Huffman subtree
that has these two symbols as child nodes and create a parent node.
(2) Assign the sum of the childrens frequency counts to the parent and insert it into the list such
that the order is maintained.
3. Assign a codeword for each leaf based on the path from the root.
23 Li & Drew
Fundamentals of Multimedia, Chapter 7
Fig. 7.5: Coding Tree for HELLO using the Huffman Algorithm.
24 Li & Drew
Fundamentals of Multimedia, Chapter 7
After initialization: L H E O
After iteration (a): L P1 H
After iteration (b): L P2
After iteration (c): P3
25 Li & Drew
Fundamentals of Multimedia, Chapter 7
The two least frequent symbols will have the same length for their Huffman
codes, differing only at the last bit.
Symbols that occur more frequently will have shorter Huffman codes than
symbols that occur less frequently.
The average code length for an information source S is strictly less than + 1.
Combined with Eq. (7.5), we have:
l 1 (7.6)
26 Li & Drew
Fundamentals of Multimedia, Chapter 7
27 Li & Drew
Fundamentals of Multimedia, Chapter 7
(7.7)
l 1
k
An improvement over the original Huffman coding, but
not much.
28 Li & Drew
Fundamentals of Multimedia, Chapter 7
ENCODER DECODER
------- -------
Initial_code(); Initial_code();
29 Li & Drew
Fundamentals of Multimedia, Chapter 7
(a) increments the frequency counts for the symbols (including any
new ones).
(b) updates the configuration of the tree.
The encoder and decoder must use exactly the same initial_code and
update_tree routines.
30 Li & Drew
Fundamentals of Multimedia, Chapter 7
The tree must always maintain its sibling property, i.e., all nodes
(internal and leaf) are arranged in the order of increasing counts.
31 Li & Drew
Fundamentals of Multimedia, Chapter 7
32 Li & Drew
Fundamentals of Multimedia, Chapter 7
34 Li & Drew
Fundamentals of Multimedia, Chapter 7
35 Li & Drew
Fundamentals of Multimedia, Chapter 7
36 Li & Drew
Fundamentals of Multimedia, Chapter 7
37 Li & Drew
Fundamentals of Multimedia, Chapter 7
39 Li & Drew
Fundamentals of Multimedia, Chapter 7
40 Li & Drew
Fundamentals of Multimedia, Chapter 7
1 A
2 B
3 C
A B 1 4 AB
B A 2 5 BA
A B
AB B 4 6 ABB
B A
BA B 5 7 BAB
B C 2 8 BC
C A 3 9 CA
A B
AB A 4 10 ABA
A B
AB B
ABB A 6 11 ABBA
A EOF 1
41 Li & Drew
Fundamentals of Multimedia, Chapter 7
42 Li & Drew
Fundamentals of Multimedia, Chapter 7
43 Li & Drew
Fundamentals of Multimedia, Chapter 7
45 Li & Drew
Fundamentals of Multimedia, Chapter 7
BEGIN
low = 0.0; high = 1.0; range = 1.0;
46 Li & Drew
Fundamentals of Multimedia, Chapter 7
47 Li & Drew
Fundamentals of Multimedia, Chapter 7
48 Li & Drew
Fundamentals of Multimedia, Chapter 7
49 Li & Drew
Fundamentals of Multimedia, Chapter 7
BEGIN
code = 0;
k = 1;
while (value(code) < low)
{
assign 1 to the kth binary fraction bit
if (value(code) > high)
replace the kth bit by 0
k = k + 1;
}
END
50 Li & Drew
Fundamentals of Multimedia, Chapter 7
BEGIN
get binary code and convert to
decimal value = value(code);
Do
{
find a symbol s so that
Range_low(s) <= value < Range_high(s);
output s;
low = Rang_low(s);
high = Range_high(s);
range = high - low;
value = [value - low] / range;
}
Until symbol s is a terminator
END
51 Li & Drew
Fundamentals of Multimedia, Chapter 7
52 Li & Drew
Fundamentals of Multimedia, Chapter 7
53 Li & Drew
Fundamentals of Multimedia, Chapter 7
Fig. 7.9: Distributions for Original versus Derivative Images. (a,b): Original
gray-level image and its partial derivative image; (c,d): Histograms for original
and derivative images.
54 Li & Drew
Fundamentals of Multimedia, Chapter 7
Lossless JPEG
Lossless JPEG: A special case of the JPEG image compression.
55 Li & Drew
Fundamentals of Multimedia, Chapter 7
56 Li & Drew
Fundamentals of Multimedia, Chapter 7
57 Li & Drew
Fundamentals of Multimedia, Chapter 7
Example with P1
- - -
+ + +
+ + +
59 Li & Drew