Documente Academic
Documente Profesional
Documente Cultură
PREPARED BY .,
SIZEU
SIZEC
image compression
Code 0 10 110
# of bits used 1 2 3
2.32
111
TOTAL # of bits:
3
10
image compression
Arithmetic Coding
Arithmetic coding is a more modern coding method that usually out-performs Huffman coding. Huffman coding assigns each symbol a codeword which has an integral bit length. Arithmetic coding can treat the whole message as one unit. A message is represented by a half-open interval [a, b) where a and b are real numbers between 0 and 1. Initially, the interval is [0, 1). When the message becomes longer, the length of the interval shortens and the number of bits needed to represent the interval increases.
image compression
Find the probability for each pixel Divide the initial subinterval based on the distribution The first pixel value is coded by extracting the subinterval corresponding to it, and subdivide again based on the same relative distribution Repeat step (3) for each pixel value until a final interval is determined Any value within this subinterval can be used to represent the sequence of gray-level values
image compression
END
image compression
END
image compression
10
image compression
11
- if the table already contains the string, the corresponding code for that string is put into the compressed file
- uses code words with more bits than the original data
- the table consists of the original 2n entries (corresponding to the original n-bit data) and allows another 2n-k - 2n entries for string codes
image compression
12
Dictionary-based Coding
LZW uses fixed-length codewords to represent variable-length strings of symbols/characters that commonly occur together, e.g., words in English text. The LZW encoder and decoder build up the same dictionary dynamically while receiving the data.
LZW places longer and longer repeated entries into a dictionary, and then emits the code for an element, rather than the string itself, if the element has already been placed in the dictionary.
image compression
13
Let's start with a very simple dictionary (also referred to as a string table), initially containing only 3 characters, with codes as follows: code ------1 2 3 string -------A B C
Now if the input string is ABABBABCABABBA, the LZW compression algorithm works as follows:
image compression
14
image compression
15
ABABBABCABABBA
s c
output
image compression
16
ABABBABCABABBA
s code string 1 A 2 B 3 C --------------------------------------------------------------------------------A B 1 4 AB B c output
Check s+c s+c (AB) is not in the Dic. --- output the code for s A => 1 --- insert AB in Dic. --- s=c
image compression
17
ABABBABCABABBA
s code string 1 A 2 B 3 C --------------------------------------------------------------------------------A B 1 4 AB B A c output
image compression
18
ABABBABCABABBA
s code string 1 A 2 B 3 C --------------------------------------------------------------------------------A B 1 4 AB B A 2 5 BA A c output
Check s+c s+c (BA) is not in the Dic. --- output the code for s B => 2 --- insert BA in Dic. --- s=c
image compression
19
ABABBABCABABBA
s code string 1 A 2 B 3 C --------------------------------------------------------------------------------A B 1 4 AB B A 2 5 BA A B c output
image compression
20
ABABBABCABABBA
s code string 1 A 2 B 3 C --------------------------------------------------------------------------------A B 1 4 AB B A 2 5 BA A B AB c output
Check s+c s+c (AB) is in the Dic. --- s=s+c
image compression
21
ABABBABCABABBA
s code string 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 The output codes are: 1 2 4 5 2 3 4 6 1. Instead of sending 14 characters, only 9 codes need to be sent (compression ratio = 14/9 = 1.56).
image compression 22
output
BEGIN s = NIL; while not EOF { k = next input code; entry = dictionary entry for k; output entry; if (s != NIL) add string s + entry[0] to dictionary with a new code; s = entry; } END
image compression 23
124523461
The LZW decompression algorithm then works as follows: S k entry/output code string ---------------------------------------------------------------------1 A 2 B 3 C ----------------------------------------------------------------------NIL 1
S=nil K=1
image compression
24
124523461
The LZW decompression algorithm then works as follows: S k entry/output code string ---------------------------------------------------------------------1 A 2 B 3 C ----------------------------------------------------------------------NIL 1 A
Entry = A Output = A
image compression
25
124523461
The LZW decompression algorithm then works as follows: S k entry/output code string ---------------------------------------------------------------------1 A 2 B 3 C ----------------------------------------------------------------------NIL 1 A
image compression
26
124523461
The LZW decompression algorithm then works as follows: S k entry/output code string ---------------------------------------------------------------------1 A 2 B 3 C ----------------------------------------------------------------------NIL 1 A A
S= entry
image compression
27
124523461
The LZW decompression algorithm then works as follows: S k entry/output code string ---------------------------------------------------------------------1 A 2 B 3 C ----------------------------------------------------------------------NIL 1 A A 2
K = next input
image compression
28
124523461
The LZW decompression algorithm then works as follows: S k entry/output code string ---------------------------------------------------------------------1 A 2 B 3 C ----------------------------------------------------------------------NIL 1 A A 2 B
Entry = B Output = B
image compression
29
124523461
The LZW decompression algorithm then works as follows: S k entry/output code string ---------------------------------------------------------------------1 A 2 B 3 C ----------------------------------------------------------------------NIL 1 A A 2 B 4 AB
image compression
30
124523461
The LZW decompression algorithm then works as follows: S k entry/output code string ---------------------------------------------------------------------1 A 2 B 3 C ----------------------------------------------------------------------NIL 1 A A 2 B 4 AB B
S= entry
image compression
31
124523461
The LZW decompression algorithm then works as follows: S k entry/output code string ---------------------------------------------------------------------1 A 2 B 3 C ----------------------------------------------------------------------NIL 1 A A 2 B 4 AB B 4 AB 5 BA AB 5 BA 6 ABB BA 2 B 7 BAB B 3 C 8 BC C 4 AB 9 CA AB 6 ABB 10 ABA ABB 1 A 11 ABBA A EOF
Apparently, the output string is ABABBABCABABBA, a truly image compression lossless result!
S + entry[0]
32
THANK U FRIENDS
image compression
33