Anda di halaman 1dari 7

TP4113 – Kompresi Data 5-Metode Dictionary Kompresi Data

Dictionary-Based Compression
METODE DICTIONARY „ Algoritma ini menggunakan suatu tabel referensi
untuk menyimpan simbol yang akan dikodekan.
KOMPRESI DATA „ Contoh: menggunakan Random House
TP4113 Dictionary of the English Language, 2nd Ed,
Unabridged.
‘Contoh yg baik suatu dictionary based compression….’

1/1 822/3 674/4 1343/60 928/75 550/32 173/46 421/2

no no item dalam
halaman suatu halaman
Restyandito,
Restyandito, S.Kom, MSIS
Metode Dictionary Kompresi Data Restyandito - 2

Dictionary Based Compression Dictionary-Based Compression


„ Pengkodean static dictionary : „ Beberapa teknik Dictionary-
Dictionary-based compression
A={a,b,c,d,r} Untuk mengkodekan yg saat ini banyak digunakan dalam kompresi
abracadabra. code data yang bersifat lossles yaitu:
entry
„ Winzip
000 a
„ Winarj
001 b
010 c
011 d
100 r
String output yg dihasilkan 101 ab
101100110111101100000. 110 ac
111 ad

Metode Dictionary Kompresi Data Restyandito - 3 Metode Dictionary Kompresi Data Restyandito - 4

Lempel-Ziv Coding Lempel-Ziv Coding


„ Algoritma ini tidak mengkodekan sebuah simbol „ Dlm kamus terdapat sekitar 31.500 kata, dan
sebagai bit streams, ttp mengkodekan beberapa menurut formula information content Shannon,
variabel sebagai sebuah token. sebuah kata dapat dikodekan dengan 18 buah
bits.
„ Masing-
Masing-masing token disimpan dalam sebuah „ Dengan menggunakan LZ compression, berapa
tabel yang dimiliki oleh encoder maupun digit diperlukan untuk mengkodekan seluruh
decoder kata dalam kamus?
„ Berapa rasio kompresi jika akan dikodekan kata
MULTIMEDIA ?

Metode Dictionary Kompresi Data Restyandito - 5 Metode Dictionary Kompresi Data Restyandito - 6

Restyandito, S.Kom,MSIS
1
TP4113 – Kompresi Data 5-Metode Dictionary Kompresi Data

Lempel-Ziv Coding Static vs. Adaptive Dictionary


LATIHAN
„ Suatu file teks akan dikompres. Jika rata-
rata-rata „ Pendekatan Static
jumlah karakter per kata adalah 6, dan „ Kamus dibuat sebelum pengkodean.
dictionary yang digunakan berisi 4096 buah kata, „ Dibutuhkan pengetahuan yang memadai
berapakah rasio kompresi yang diperoleh jika mengenai source
digunakan algoritma LZ.
„ Pendekatan Adaptive
„ Kamus dibuat pada saat proses pengkodean.

Metode Dictionary Kompresi Data Restyandito - 7 Metode Dictionary Kompresi Data Restyandito - 8

Lempel-Ziv-Welsh Coding Lempel-Ziv-Welsh Coding


„ Algoritma LZW mengkodekan suatu teks secara
dinamis. „ Contoh: (dictionary index = 8 bit) NUL

SOH
0

„ Sebagai inisialisasi, dictionary berisi set karakter teknik kompresi LZW itu gampang : :

yang digunakan untuk membuat suatu teks (mis DEL 127

teknik 128

ASCII) kompresi 129

„ Selanjutnya dictionary diisi secara dinamis LZW 130

berdasarkan kata-
kata-kata yang ada dalam teks.
itu 131

gampang 132

255

Metode Dictionary Kompresi Data Restyandito - 9 Metode Dictionary Kompresi Data Restyandito - 10

LZ77 LZ77
„ “ A Universal Algorithm for Sequential Data A; for(i=0; i <MAX-1; i ++)\ r for(j =i +1 ; j <MAX ; j++
Compression,” diterbitkan dalam IEEE
Compression,” ^ ^ ^ ^ ^ ^ ^

Transactions on Information Theory , 1977


Text window Look-ahead buffer
„ Sliding Windows Compression 40 chars 10 chars
„ Struktur data berupa text windows yang dibagi
menjadi 2 bagian, terdiri dari teks yang sudah „ Frasa dalam teks inputan diganti dengan sebuah
dikodekan, dan bagian dari teks yang akan pointer yang ada pada dicitionary
dikodekan (look ahead buffer)
„ Ukuran normal text window : Beberapa ribu chr
Ukuran normal look-
look-ahead buffer : 10 ~100 chr

Metode Dictionary Kompresi Data Restyandito - 11 Metode Dictionary Kompresi Data Restyandito - 12

Restyandito, S.Kom,MSIS
2
TP4113 – Kompresi Data 5-Metode Dictionary Kompresi Data

LZ77 LZ77
A; for(i=0; i <MAX-1; i ++)\ r for(j =i +1 ; j <MAX ; j++ A; for(i=0; i <MAX-1; i ++)\ r for(j =i +1 ; j <MAX ; j++
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^

Token :
r(i=0; i<M AX-1; i++)\r for(j=i+1; j<M AX ; j++)\r a[i]
„ ^ ^ ^ ^ ^ ^ ^

„ an offset to a phrase in the text window


„ the length of the phrase ; and
„ Geser token ke dalam text windows (5 karakter)
„ the first symbol in the look-
look-ahead buffer that follows „ Masukkan 5 simbol baru ke dalam look-
look-ahead
the phrase. buffer
„ “<MAX^”
<MAX^” dikodekan sebagai ( 14, 4,”
4,”^”) „ Token berikutnya adalah (33, 3, +)
(The Data Compression Book - Mark Nelson ) „ Jika dalam text windows tidak ada yang match,
maka token = (0,0,karakter)
Metode Dictionary Kompresi Data Restyandito - 13 Metode Dictionary Kompresi Data Restyandito - 14

LZ77 LZ77
„ Untuk men-
men-decode hasil kompresi cukup „ Men-
Men-decode token ( 14, 4,”
4,”^”)
sederhana: Text window
1. reads in a token
2. outputs the indicated phrase A; f or (i=0 ; i <MAX -1 ; i++) \r for (j=i +1 ; j
^ ^ ^ ^ ^
<MAX
^

3. shifts 14
4. repeats
„ Men-
Men-decode token ( 33, 3,”
3,”+”)
; j+
r(i= 0 ; i< M A X -1 ; i+ + )\r fo r(j= i+ 1 ; j< M A X ^
^ ^ ^ ^

33

Metode Dictionary Kompresi Data Restyandito - 15 Metode Dictionary Kompresi Data Restyandito - 16

LZ77 LZ77
„ (Data Compression: The Complete Reference – David Salomon)
Salomon) „ Contoh: CODING
„ Token : kuku-
kuku-kuku kaki kakak kakekku kaku-
kaku-kaku kok.
„ an offset to a phrase in the text window (dari kanan kuku–kuku^kaki^kakak^kakekku^ka (11, 3,”e”)
ke kiri)
–kuku^kaki^kakak^kakekku^kaku–k (20, 1,”k”)
„ the length of the phrase; and
(19, 5,”u”)
„ the first symbol in the look-
look-ahead buffer that follows uku^kaki^kakak^kakekku^kaku–kak
the phrase. ki^kakak^kakekku^kaku–kaku^kok. ( 0, 0,”k”)

„ Latihan
Kodekan kalimat di atas menggunakan LZ77 (Salomon)
dimulai dengan huruf pertama!

Metode Dictionary Kompresi Data Restyandito - 17 Metode Dictionary Kompresi Data Restyandito - 18

Restyandito, S.Kom,MSIS
3
TP4113 – Kompresi Data 5-Metode Dictionary Kompresi Data

LZ77 LZ77
„ Contoh: DECODE „ Circular Queue
„ struktur data dasar
(11, 3,”e”) kuku–kuku^kaki^kakak^ „ Larik berisi karakter yg ditambahkan diakhir
(20, 1,”k”) –kuku^kaki^kakak^kake „ Jika larik penuh, karakter pertama dihapus
(19, 5,”u”) uku^kaki^kakak^kakekk „ Contoh: (CQ 16 bytes)
( 0, 0,”k”) ki^kakak^kakekku^kaku kuku–ku

kuku–kuku^kaki^k
„ Algoritma ini cocok untuk kasus-
kasus-kasus dimana
auku–kuku^kaki^k
suatu file dikompres sekali tetapi di-
di-dekompres
berkali-
berkali-kali kakakkuku^kaki^k

Metode Dictionary Kompresi Data Restyandito - 19 Metode Dictionary Kompresi Data Restyandito - 20

LZSS LZSS
„ Dikembangkan oleh Storer dan Szymanski „ Contoh binary tree
„ Memperbaiki LZ77 dalam hal: aku

„ menyimpan look-
look-ahead-
ahead-buffer dalam suatu circular gula
cincin

queue energi

„ menyimpan search buffer (dictionary) dalam binary cincin kamar gula

search tree aku energi indah mandi


harimau

indah
„ membuat token dnegan dua buah field saja kamar
harimau pakaian

mandi

pakaian

rahasia

Metode Dictionary Kompresi Data Restyandito - 21 Metode Dictionary Kompresi Data Restyandito - 22

LZSS LZSS
„ Contoh: search buffer (16B), look-
look-ahead-
ahead-buffer (5B) „ Contoh: search buffer (16B), look-
look-ahead-
ahead-buffer (5B)

aku^memakai^pakaian^di^kamar^mandi aku^memakai^pakaian^di^kamar^mandi

encoder membuat tree yang terdiri dari 5 karakter ku^m emakai^pakaian^di^kamar^mandi

aku^m offset 16
ku^me 15 ian^d „ Pohon diupdate dengan menghapus 1 string
u^mem 14
^mema 13 aku^m offset 16
memak 12 (6, 1)
emakai
m aka i
11
10 dan menambah 1 string baru
a k a i ^ 9
k a i ^ p 8 pa k ai 5
a i ^pak 7
i ^p aka 6
^p a k a 5

Metode Dictionary Kompresi Data Restyandito - 23 Metode Dictionary Kompresi Data Restyandito - 24

Restyandito, S.Kom,MSIS
4
TP4113 – Kompresi Data 5-Metode Dictionary Kompresi Data

LZSS LZSS
„ Contoh: LZSS is better than LZ77
isi dari
text window
„ LZSS uses a single bit as a prefix to every output
token to indicate whether it is an offset/ length
"LZSS^"
pair or a single symbol for output.
"^is^b" "ZSS^i"
„ Matched phrase (0,position, length, character)
" ^bett" "is^be" "SS^is" „ Non-
Non-matched phrase (1,character)
"bette" "S^is^" "tter^" „ If the text window size is 4096 characters, look-
look-
"^than" "etter" "s^bet" "ter^t" ahead buffer size is 16 characters,
"^LZ77" "an^LZ" "er^th" "han^L" "r^tha" "than^" „ Matched token needs 1+12+4+8=25 bits
"n^LZ7"
„ Non-
Non-matched token needs 1+8=9 bits
Isi dari setiap
simpul adalah
pointer ke text
window
Metode Dictionary Kompresi Data Restyandito - 25 Metode Dictionary Kompresi Data Restyandito - 26

LZSS LZSS
„ Greedy vs. Optimal
„ Baik LZ77 maupun LZSS disebut algoritma first longest possible as greedy
〝 Go T〞
^
: 25
greedy” :Keduanya tidak menganalisa input
“greedy” 〝 o S〞 : 25
stream untuk mencari kombinasi terbaik dari
^
〝 tat〞 : 25
indeks dan karakter. : 75

„ Contoh: dictionary frasa yang dikodekan best match as optimized 〝 Go〞 : 25


Go^T Go To Statement 〝 T〞 : 9
o^S
: 0
tat “o”
^Stat 〝 Stat〞 : 25
: 68
Aturan: 25 bits utk index/offset pair
9 bits utk sebuah character

Metode Dictionary Kompresi Data Restyandito - 27 Metode Dictionary Kompresi Data Restyandito - 28

LZSS DISKUSI
Apakah besar text-
text-windows dan look-
look-up-
up-
• In the world of data compression, a few good table ada pengaruhnya terhadap hasil
heuristics are often more respected than a
provably superior algorithm.
kompresi?
• The greedy heuristics in this case is definitely the
choice of most compression programmers. Contoh:
sir_sid_eastman_easily_teases_sea_sick_seals

Metode Dictionary Kompresi Data Restyandito - 29 Metode Dictionary Kompresi Data Restyandito - 30

Restyandito, S.Kom,MSIS
5
TP4113 – Kompresi Data 5-Metode Dictionary Kompresi Data

LZ78 LZ78
„ Kelemahan algoritma LZ77 „ Token berisikan:
„ Keterbatasan text windows mengakibatkan banyak „ suatu code yg memilih suatu frasa yang
frasa yang terbuang.
diberikan
„ Ukuran frasa yang cocok terbatas sesuai dengan
look- „ sebuah karakter yg mengikuti frasa tersebut
look-ahead buffer yang digunakan.
„ LZ88 tidak menggunakan konsep text windows „ Langkah-
Langkah-langkah
„ LZ77: dictionary ditentukan oleh text windows dari „ Mulai dengan sebuah null string pada posisi nol
teks yang dibaca/dikodekan sebelumnya. „ Simbol yg dikodekan dimasukkan ke dalam tabel
„ LZ78: dictionary berupa daftar yg tak terbatas dari secara urut
frasa yang dilihat sebelumnya „ Jika tabel telah berisi, dicari simbol yang sama,
„ suatu code yg memilih suatu frasa yg diberikan jika ditemukan masukkan offset dan simbol.
„ Sebuah karakter yg mengikuti frasa tersebut
Metode Dictionary Kompresi Data Restyandito - 31 Metode Dictionary Kompresi Data Restyandito - 32

LZ78 LZ78
„ Contoh: sir_sid_eastman_easily_teases_sea_sick_seals „ Contoh: sir_sid_eastman_easily_teases_sea_sick_seals

Metode Dictionary Kompresi Data Restyandito - 33 Metode Dictionary Kompresi Data Restyandito - 34

LZ78 LZP
„ Latihan: kuku-
kuku-kuku kaki kakakku kaku-
kaku-kaku „ Charles Bloom: Prinsip prediksi konteks
S = String : simbol yg akan dikodekan
C = Context : string yg biasanya mengikuti S
N : panjang C

Metode Dictionary Kompresi Data Restyandito - 35 Metode Dictionary Kompresi Data Restyandito - 36

Restyandito, S.Kom,MSIS
6
TP4113 – Kompresi Data 5-Metode Dictionary Kompresi Data

LZP LZP
„ Algoritma
1. It saves P and replace it in the index table with a
fresh pointer Q pointing to S in the look-
look-ahead
buffer. L is set to zero.
2. If P is not a null pointer, it compares the string
pointed by P to S, set L to the match length.
3. If L = 0, the buffer is slid to the right one position
and the first symbol of string S is written to the
compressed stream as a raw ASCII code
4. If L > 0, the buffer is slid to the rigth L positions
and the value of L is written on the compressed
streams.
Metode Dictionary Kompresi Data Restyandito - 37 Metode Dictionary Kompresi Data Restyandito - 38

LZY
BUKU ACUAN

„ Hallsal, F, 2001, Multimedia Communications –


Applications, Networks, Protocols and Standards,
Standards,
Addison-
Addison-Wesley (p. 136-
136-140)

„ Salomon, D, 2000, Data Compression, The Complete


Reference, 2nd edition,
edition, Springer (p. 165-
165-245)

Metode Dictionary Kompresi Data Restyandito - 39 Metode Dictionary Kompresi Data Restyandito - 40

TERIMAKASIH

Restyandito, S.Kom,MSIS
7

Anda mungkin juga menyukai