Mã nén
Trang 2Dictionary 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
Trang 3Dictionary-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
Trang 4Dictionary-based methods: History
Trang 5Sử dụng một con trỏ dịch chuyển trên xâu kí tự
đầu vào Ban đầu con trỏ trỏ vào vị trí 1
Qui ước: từ con trỏ trở về trước được gọi là quá
khứ, còn từ con trỏ trở về sau được gọi là tương lai Tránh trường hợp quá khứ dài vô tận người ta
đặt kích thước của cửa sổ quá khứ là w bằng số kí
tự dài nhất có thể trùng khớp với các kí tự trong tương lai
Trang 6Output - thể hiện trong dạng (i, j) C:
(i,j) thể hiện vị trí so khớp và độ dài xâu tương
ứng
C kí tự rõ trong buffer
Trang 7sir_sid_eastman_ea ⇒ (0,0,’r’) sir_sid_eastman_eas ⇒ (0,0,’_’) sir_sid_eastman_easi ⇒ (4,2,’d’)
Trang 99LZ77: Example 2
Trang 10LZ77: Example 3
Trang 1111LZ77: Example 4
Trang 12 Cặp (i,j) vị trí so khớp và độ dài xâu so khớp
Kí tự vừa đọc được hoặc xâu so khớp nhưng có độ dài nhỏ hơn MIN_LENGTH
Trang 1313LZSS: Example 1
Trang 14• 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
Trang 15LZ78- Thuật toán nén
Trang 16LZ78-Thuật toán giải nén
Trang 17LZ78-Example 1
Trang 18LZW: Encoding algorithm
Initialize Dictionary with alphabet
STRING = get input character
WHILE there are still input characters DO
CHAR = get input character
IF STRING+CHAR is in the Dictionary THEN
STRING = STRING+CHAR ELSE
output the code for STRING add STRING+CHAR to Dictionary STRING=CHAR
ENDIF END of WHILE
Trang 21output the code for STRING: 0 add STRING+CHAR=ab to Dictionary STRING=CHAR=b
ENDIF
Trang 22output the code for STRING: 1 add STRING+CHAR=ba to Dictionary
Trang 23ELSE output the code for STRING add STRING+CHAR to Dictionary STRING=CHAR
ENDIF
Trang 24output the code for STRING: 2 add STRING+CHAR=aba to Dictionary
Trang 25ELSE output the code for STRING add STRING+CHAR to Dictionary STRING=CHAR
ENDIF
Trang 26ELSE output the code for STRING add STRING+CHAR to Dictionary
Trang 27output the code for STRING: 4 add STRING+CHAR=abab to Dictionary STRING=CHAR= b
ENDIF
Trang 28ELSE output the code for STRING add STRING+CHAR to Dictionary
Trang 30LZW: 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
Trang 32Decode code c to w=a
Output decoded string w=a
Put w?=a? in Dictionary
Trang 33Decode the 1st symbol s1=b of the code c=1
Complete the previous Dictionary entry with s1=b
Trang 34b) Finish decoding the remainder of the code c=1
Output decoded string w=b
Put put w?=b? in Dictionary
Trang 35Decode the 1st symbol s1=a of the code c=2
Complete the previous Dictionary entry with s1=a
Trang 36a) Finish decoding the remainder of the code c=2
Output decoded string w=ab
Put put w?=ab? in Dictionary
Trang 37⇒ Decode the 1st symbol s 1 =a of the code c=4
Complete the previous Dictionary entry with s1=a
Trang 38LZW: Example (4a) step 2
Decode the 1st symbol s1=a of the code c=4
⇒ Complete the previous Dictionary entry with s 1 =a
Trang 39b) Finish decoding the remainder of the code c=4
Output decoded string w=aba
Put put w?=aba? in Dictionary
Trang 40Decode the 1st symbol s1=b of the code c=3
Complete the previous Dictionary entry with s1=b
Trang 41b) Finish decoding the remainder of the code c=3
Output decoded string w=ba
Put put w?=ba? in Dictionary
Trang 42LZW: Example (6a) step 1
⇒ Decode the 1st symbol s 1 =b of the code c=6
Complete the previous Dictionary entry with s =b
Trang 43Decode the 1st symbol s1=b of the code c=6
⇒ Complete the previous Dictionary entry with s 1 =b
Trang 44a) Finish decoding the remainder of the code c=6
Output decoded string w=bab