Image Compression - PowerPoint PPT Presentation

1 / 39
About This Presentation
Title:

Image Compression

Description:

Statistical compression methods use a statistical model ... Bring me my chariot of fire! Milton. The known part of the text is used as the dictionary. ... – PowerPoint PPT presentation

Number of Views:82
Avg rating:3.0/5.0
Slides: 40
Provided by: Jus6
Category:

less

Transcript and Presenter's Notes

Title: Image Compression


1
DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF
JOENSUU JOENSUU, FINLAND
  • Image Compression
  • Lecture 19
  • Dictionary Methods
  • Alexander Kolesnikov

2
Dictionary based methods
  • Statistical compression methods use a
    statistical model
  • of the data, and the quality of compression
    they achieve
  • depends on how good that model is.
  • Dictionary-based method do not use statistical
    model
  • of data. Instead they select strings of symbols
    and
  • encode each string as a token using a
    dictionary.
  • The dictionary holds strings of symbols and it
    may be
  • static or dynamic (adaptive).
  • To encode text one can use a (static) dictionary
    of the
  • English (Finnish, etc.) language.
  • What about images?

3
Dictionary-based methods Main idea
  • Encoder As the input is processed, develop a
    dictionary
  • and transmit the index of strings found in the
    dictionary
  • Decoder As the code is processed, reconstruct
    the
  • dictionary to invert the process of encoding

4
Dictionary-based methods History
  • 1977 LZ77 Lempel, Ziv
  • 1982 LZSS Storer, Szymanski
  • LZR, LZH, etc.
  • Gzip, PKZip, LHarc, Zoo for files
  • PNG image format
  • 1978 LZ78 Lempel, Ziv
  • 1984 LZW Welch algorithm
  • GIF image format
  • V.42bis data compression standard for modems

5
LZ77 Main idea
Bring me my bow of burning gold! Bring me my
arrows of desire! Bring me my spear! O clouds
unfold! Bring me my chariot of fire!
Milton
The known part of the text is used as the
dictionary.
6
LZ77 Main idea
  • The algorithm searches the window for the
    longest
  • match with beginning of the look-ahead buffer
    and
  • outputs pointer to that match.
  • After each pointer it outputs the first
    character in the
  • look-ahead buffer after the match.
  • If there is no match, it outputs a null-pointer
    and the
  • character at the coding position

Bring me my bow of burning gold! Bring me my
arrows ...
search buffer
look-ahead buffer
7
LZ77 Algorithm
Set the coding position to the beginning of the
message REPEAT Find the last longest match
in the search buffer for look-ahead buffer
Output (P,L,C) P is pointer to the match
in the search buffer L is length of
matched string C is the first character in
the look-ahead buffer that did not match
Move current position to (L1) chars
forward UNTIL no more symbols in the message
Bring me my bow of burning gold! Bring me my
arrows ...
Bring me my bow of burning gold! Bring me my
arrows ...
(P,L,C)(21,4,g)
8
LZ77 Example
sir_sid_eastman_easily_teases_sea_sick_seals
...
search buffer
look-ahead buffer
sir_sid_eastman_ ? (0,0,s)
sir_sid_eastman_e ? (0,0,i)
sir_sid_eastman_ea ? (0,0,r)
sir_sid_eastman_eas ? (0,0,_)
sir_sid_eastman_easi ? (4,2,d)
9
LZ77 Decoding
Codes (0, 0,s) (0,0,i) (0,0,r) (0,0,_)
(4,2,d) Message 1. (0, 0,s) s 2.
(0,0,i) sisi 3. (0,0,r) sirsir 4.
(0,0,_) sir_sir_ 5. (4,2,d)
sir_sidsir_sid
Get 2 symbols si starting from position -4 and
add symbol d
10
LZSS Encoding
  • (P,L,C) ? (Pointer, Length) or (Code of new
    symbol)
  • How to define mode? Use 1 bit
  • Further improvements
  • Encode (Pointer, Length) with Huffman code.
  • Use tree stucture for string matching
  • etc.

Encoding Rather slow because of string matching
Decoding very fast
11
LZ78 Main idea
  • The algorithm does not use any search buffer,
    lookahead
  • buffer, sliding window
  • Instead there is a Dictionary of previously
    encountered
  • strings
  • This Dictionary starts (almost) empty
  • The encoder add new entries to the Dictionary
    during
  • the message encoding
  • The decoder decode codes using Dictionary and
  • add new entries to the Dictionary during
    decoding

12
LZW Encoding algorithm
Initialize Dictionary with alphabet STRING get
input character WHILE there are still input
characters DO CHAR get input character IF
STRINGCHAR is in the Dictionary THEN STRING
STRINGCHAR ELSE output the code for
STRING add STRINGCHAR to Dictionary STRINGCH
AR ENDIF END of WHILE Output code for the STRING
13
LZW Example (0)
Dictionary Message a b a b a b
a b a 0 a Codes 1 b
Initialize Dictionary with alphabet
14
LZW Example (1)
Dictionary Message a b a b a b
a b a 0 a Codes 1 b
STRINGa
STRING get input character
15
LZW Example (2)
Dictionary Message a b a b
a b a b a 0 a Codes 0 1
b 2 ab
IF STRINGCHARab is in the Dictionary No
THEN STRING STRINGCHAR ELSE
output the code for STRING 0 add
STRINGCHARab to Dictionary
STRINGCHARb ENDIF
STRINGa CHAR b STRINGCHARab ?STRINGb
16
LZW Example (3)
Dictionary Message a b a
b a b a b a 0 a Codes 0 1 1
b 2 ab 3 ba
IF STRINGCHARba is in the Dictionary No
THEN STRING STRINGCHAR ELSE
output the code for STRING 1 add
STRINGCHARba to Dictionary STRINGCHARa
ENDIF
STRINGb CHAR a STRINGCHARba ?STRINGa
17
LZW Example (4)
Dictionary Message a b ab
a b a b a 0 a Codes 0 1 1
b 2 ab 3 ba
IF STRINGCHARab is in the Dictionary Yes
THEN STRING STRINGCHARab ELSE
output the code for STRING add
STRINGCHAR to Dictionary STRINGCHAR ENDIF
STRINGa CHAR b STRINGCHARab ?STRINGab
18
LZW Example (5)
Dictionary Message a b ab
a b a b a 0 a Codes 0 1 2 1
b 2 ab 3 ba 4 aba
IF STRINGCHARaba is in the Dictionary No
THEN STRING STRINGCHAR ELSE
output the code for STRING 2 add
STRINGCHARaba to Dictionary
STRINGCHARa ENDIF
STRINGab CHAR a STRINGCHARaba ?STRINGa
19
LZW Example (6)
Dictionary Message a b ab ab a
b a 0 a Codes 0 1 2 1 b 2
ab 3 ba 4 aba
IF STRINGCHARab is in the Dictionary Yes
THEN STRING STRINGCHAR ab ELSE
output the code for STRING add
STRINGCHAR to Dictionary STRINGCHAR ENDIF
STRINGa CHAR b STRINGCHARab ?STRINGab
20
LZW Example (7)
Dictionary Message a b ab aba
b a 0 a Codes 0 1 2 1 b 2
ab 3 ba 4 aba
IF STRINGCHARaba is in the Dictionary Yes
THEN STRING STRINGCHAR aba ELSE
output the code for STRING add
STRINGCHAR to Dictionary STRINGCHAR ENDIF
STRINGab CHAR a STRINGCHARaba ?STRINGaba
21
LZW Example (8)
Dictionary Message a b ab aba
b a 0 a Codes 0 1 2 4 1 b 2
ab 3 ba 4 aba 5 abab
IF STRINGCHARabab is in the Dictionary No
THEN STRING STRINGCHAR ELSE
output the code for STRING 4 add
STRINGCHARabab to Dictionary
STRINGCHAR b ENDIF
STRINGaba CHAR b STRINGCHARabab ?STRINGb
22
LZW Example (9)
Dictionary Message a b ab aba
ba 0 a Codes 0 1 2 4 1 b 2
ab 3 ba 4 aba 5 abab
IF STRINGCHARba is in the Dictionary Yes
THEN STRING STRINGCHAR ba ELSE
output the code for STRING add
STRINGCHAR to Dictionary STRINGCHAR ENDIF
STRINGb CHAR a STRINGCHARba ?STRINGba
23
LZW Example (10)
Dictionary Message a b ab aba
ba 0 a Codes 0 1 2 4 3 1 b
2 ab 3 ba 4 aba 5 abab
STRINGb CHAR a STRINGCHARba
Output code for the STRING 3
24
LZW Decoding
Initialize Dictionary Input code c Decode code c
(index) to w Output decoded string w Put w? in
Dictionary REPEAT a) Input code c Decode
the 1st symbol s1 of the code c Complete
the previous Dictionary entry with s1 b)
Finish decoding the remainder of the code c
Output decoded string w Put put w? in
Dictionary UNTIL no more codes
25
LZW Example (0)
Dictionary Codes 012436 0 a
Message 1 b
Initialize Dictionary with alphabet
26
LZW Example (1)
Dictionary Codes 0 1 2 4 3
6 0 a Message a 1 b 2 a?
Input code c0 Decode code c to wa Output
decoded string wa Put w?a? in Dictionary
27
LZW Example (2a)
Dictionary Codes 0 1 2 4 3
6 0 a Message a b 1 b 2 ab
a) Input code c1 Decode the 1st symbol s1b
of the code c1 Complete the previous
Dictionary entry with s1b
28
LZW Example (2b)
Dictionary Codes 0 1 2 4 3
6 0 a Message a b 1 b 2 ab 3 b?
b) Finish decoding the remainder of the code c1
Output decoded string wb Put put w?b? in
Dictionary
29
LZW Example (3a)
Dictionary Codes 0 1 2 4
3 6 0 a Message a b a 1 b 2 ab 3 ba
a) Input code c2 Decode the 1st symbol s1a
of the code c2 Complete the previous
Dictionary entry with s1a
30
LZW Example (3b)
Dictionary Codes 0 1 2 4
3 6 0 a Message a b ab 1 b 2 ab 3 ba 4
ab?
a) Finish decoding the remainder of the code
c2 Output decoded string wab Put put
w?ab? in Dictionary
31
LZW Example (4a) step 1
Dictionary Codes 0 1 2 4
3 6 0 a Message a b ab a 1 b 2 ab 3
ba 4 ab?
a) Input code c4 ? Decode the 1st symbol s1a of
the code c4 Complete the previous Dictionary
entry with s1a
32
LZW Example (4a) step 2
Dictionary Codes 0 1 2 4
3 6 0 a Message a b ab a 1 b 2 ab 3
ba 4 aba
a) Input code c4 Decode the 1st symbol s1a
of the code c4 ? Complete the previous
Dictionary entry with s1a
33
LZW Example (4b)
Dictionary Codes 0 1 2
4 3 6 0 a Message a b ab aba 1 b 2 ab 3
ba 4 aba 5 aba?
b) Finish decoding the remainder of the code c4
Output decoded string waba Put put w?aba?
in Dictionary
34
LZW Example (5a)
Dictionary Codes 0 1 2
4 3 6 0 a Message a b ab aba b 1
b 2 ab 3 ba 4 aba 5 abab
a) Input code c3 Decode the 1st symbol s1b
of the code c3 Complete the previous
Dictionary entry with s1b
35
LZW Example (5b)
Dictionary Codes 0 1 2
4 3 6 0 a Message a b ab aba ba 1
b 2 ab 3 ba 4 aba 5 abab 6 ba?
b) Finish decoding the remainder of the code c3
Output decoded string wba Put put w?ba? in
Dictionary
36
LZW Example (6a) step 1
Dictionary Codes 0 1 2
4 3 6 0 a Message a b ab aba ba
b 1 b 2 ab 3 ba 4 aba 5 abab 6 ba?
a) Input code c6 ? Decode the 1st symbol s1b of
the code c6 Complete the previous Dictionary
entry with s1b
37
LZW Example (6a) step 2
Dictionary Codes 0 1 2
4 3 6 0 a Message a b ab aba ba
b 1 b 2 ab 3 ba 4 aba 5 abab 6 bab
a) Input code c6 Decode the 1st symbol s1b
of the code c6 ? Complete the previous
Dictionary entry with s1b
38
LZW Example (6b)
Dictionary Codes 0 1 2
4 3 6 0 a Message a b ab aba ba
bab 1 b 2 ab 3 ba 4 aba 5 abab 6 bab 7 bab?
a) Finish decoding the remainder of the code c6
Output decoded string wbab Put put
w?bab? in Dictionary
39
LZW Notes
  • Extremely effective when there are repeated
    patterns
  • in the data that are widely spread
  • Negatives Create entries in the dictionary that
    may
  • never be used
  • Applications GIF, TIFF, V.42 bis modem standard

Write a Comment
User Comments (0)
About PowerShow.com