Lec4 Arith Compression
Lec4 Arith Compression
Lecture 4
Arithmetic COMPRISSION AND
DECOMPRISSION Method
Arithmetic Coding History
The idea of arithmetic coding was suggested by
Rissanen [1975] from the theory of enumerative
coding by Pasco [1976].
The material of this notes is based on the most
popular implementation of arithmetic coding by
Witten, etc., published in Communications of the
Association for Computing Machinery (1987).
Moffat, etc (1998) also proposed some
improvements upon the 1987 paper; however, the
basic idea remains same.
Arithmetic (or Range) Coding
(addresses coding redundancy)
α1 α2 α 3 α3 α4
0 1
A sub-interval of [0,1) is chosen to encode the first symbol α1 in the
sequence (based on P(α1)).
0 1
r = input_code
repeat
search c such that r falls in its range ;
output(c) ;
r = r - low_range(c) ;
r = r/(high_range(c) - low_range(c));
until r equal 0
Example 1
Example 1
Example 1
Example 1
Example 1
Example 1
Arithmetic Coding Example (2)
Character probability Range
^(space) 1/10 0.00 r 0.10
A 1/10 0.10 r 0.20
B 1/10 0.20 r 0.30
E 1/10 0.30 r 0.40
G 1/10 0.40 r 0.50
I 1/10 0.50 r 0.60
L 2/10 0.60 r 0.80
S 1/10 0.80 r 0.90
T 1/10 0.90 r 1.00
1
1
0.7712 0.773504
0.80 2 2
0.82 0.656 0.77408
3 3
1.00 0.77408 0.773504
0.80 0.80
Arithmetic Coding Example (3)
Encoding:
0.7712 0.773504
Tx (1312) 0.772352
2
Arithmetic Coding Example (3)
Decoding:
0.4 1 0 0.8
Arithmetic Coding – Example 4
Subdivide [0,1)
based on P(αi)
Encode
α1 α2 α3 α3 α 4
0.4 0.08
arithmetic code: 0.068
0.2 0.04
(can choose any number
within the final sub-interval)
Huffman Code:
0100011001 (10 bits)
Decode 0.572
α3 α3 α3 α3 α3
M[1] = a,
LOW = 0.0
27
Example 5
Alphabet {a, b, c, d , e, f }
M = [a, b, a, a, a, e, a, a, b, a]
P = [0.67, 0.11, 0.07, 0.06, 0.05, 0.04].
PC = [0.0, 0.67, 0.78, 0.85, 0.91, 0.96, 1.00]
M[2] = b,
LOW = LOW + PC[b] * RANGE = 0.0 + 0.67 * 0.67 =
0.44890000000000
28
Example 5
Alphabet {a, b, c, d , e, f }
M = [a, b, a, a, a, e, a, a, b, a]
P = [0.67, 0.11, 0.07, 0.06, 0.05, 0.04].
PC = [0.0, 0.67, 0.78, 0.85, 0.91, 0.96, 1.00]
M[3] = a,
29
Example 5
Alphabet {a, b, c, d , e, f }
M = [a, b, a, a, a, e, a, a, b, a]
P = [0.67, 0.11, 0.07, 0.06, 0.05, 0.04].
PC = [0.0, 0.67, 0.78, 0.85, 0.91, 0.96, 1.00]
LOW = 0.469404611259293
RANGE = 0.00003666730521220415
OUTPUT 0.46942
30
Decode the Message
--- Example 5
Alphabet {a, b, c, d , e, f }
|M| = 10
P = [0.67, 0.11, 0.07, 0.06, 0.05, 0.04].
PC = [0.0, 0.67, 0.78, 0.85, 0.91, 0.96, 1.00]
V = 0.46942
31
Decode the Message
--- Example 5 (continued)
Alphabet {a, b, c, d, e, f }
|M| = 10
P = [0.67, 0.11, 0.07, 0.06, 0.05, 0.04].
PC = [0.0, 0.67, 0.78, 0.85, 0.91, 0.96, 1.00]
32
Decode the Message
--- Example 5 (continued)
Alphabet {a, b, c, d , e, f }
|M| = 10
P = [0.67, 0.11, 0.07, 0.06, 0.05, 0.04].
PC = [0.0, 0.67, 0.78, 0.85, 0.91, 0.96, 1.00]
A 0.1 [0.0,0.1)
E 0.2 [0.1,0.3)
I 0.3 [0.3,0.6)
O 0.1 [0.6,0.7)
U 0.2 [0.7,0.9)
! 0.1 [0.9,1.0)
For message 0.23355 For message 0.23355
Starting=0.3-0.1=0.2 Starting=0.232-0.234=0.002
0.1+0.1 x 0.2=0.12 0.232+0.1 x 0.002=0.2322
0.12+0.2x0.2=0.16 0.2322+0.2x0.002=0.2326
0.16+0.3x0.2=0.22 0.2326+0.3x0.002=0.2332
0.22+0.1x0.2=0.24 0.2332+0.1x0.002=0.2334
0.24+0.2x0.2=0.28 0.2334+0.2x0.002=0.2338
0.28+0.1x0.2=0.3 0.2338+0.1x0.002=0.234