0% found this document useful (0 votes)
50 views10 pages

Kompresi Huffman

The document describes an algorithm for Huffman compression. It includes the following steps: 1. It counts the frequency of each symbol in an image and sorts them in descending order of frequency. 2. It constructs a Huffman tree by recursively combining the two least frequent nodes into a new internal node until there is only one node left. 3. It traverses the Huffman tree to assign a unique binary code to each symbol, with more frequent symbols getting shorter codes. 4. It replaces the symbols in the original data with their Huffman codes to compress the data. The compression ratio achieved depends on the distribution of frequencies.

Uploaded by

DIAH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views10 pages

Kompresi Huffman

The document describes an algorithm for Huffman compression. It includes the following steps: 1. It counts the frequency of each symbol in an image and sorts them in descending order of frequency. 2. It constructs a Huffman tree by recursively combining the two least frequent nodes into a new internal node until there is only one node left. 3. It traverses the Huffman tree to assign a unique binary code to each symbol, with more frequent symbols getting shorter codes. 4. It replaces the symbols in the original data with their Huffman codes to compress the data. The compression ratio achieved depends on the distribution of frequencies.

Uploaded by

DIAH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Kompresi Huffman

Buatlah design sbb


• Pada button Huffman Compression, copy script berikut:
Dim temp, tm As Integer
If PictureBox1.Image Is Nothing Then
MsgBox("warning :no picture in picture box")
Exit Sub
End If
For i = 1 To 256
h(i) = 0
Next i
Dim picture As New Bitmap(PictureBox1.Image)
Dim x, y, warna As Integer
For x = 0 To picture.Width - 1
For y = 0 To picture.Height - 1
Dim p = picture.GetPixel(x, y)
warna = CInt(p.R * 0.3 + p.G * 0.59 + p.B * 0.11)
h(warna + 1) = h(warna + 1) + 1
h1(warna + 1) = h1(warna + 1) + 1
picture.SetPixel(x, y, Color.FromArgb(warna, warna, warna))
Next y
Next x
TextBox1.Text = "Frekuensi Data" & vbCrLf & vbCrLf
For i = 1 To 256
TextBox1.Text = TextBox1.Text & i - 1 & " ==> " & h(i) & vbCrLf
Next i
For i = 1 To 256
h2(i) = i
Next i
For n = 1 To 255
For m = 2 To 256
If h1(m) > h1(m - 1) Then
temp = h1(m)
tm = h2(m)
h1(m) = h1(m - 1)
h2(m) = h2(m - 1)
h1(m - 1) = temp
h2(m - 1) = tm
End If
Next
Next
TextBox2.Text = "Shorting Frekuensi Data" & vbCrLf & vbCrLf
For i = 1 To 256
TextBox2.Text = TextBox2.Text & h2(i) - 1 & " ==> " & h1(i) &
vbCrLf
Next i
Sub bagi(ByVal t As Integer)
Dim diff1, diff2, pem, bat, dat, temp11, h, l As Integer
Dim arr1, arr2, arrtt, karak As String
bat = t
arrtt = Text3.Text
h = Len(Text3.Text)
h=h-1
diff1 = 0
diff2 = 0
arr1 = ""
For i = 0 To bat
karak = Strings.Right(Strings.Left(arrtt, i + 1), 1)
arr1 = arr1 & karak
temp11 = Asc(karak)
diff1 = diff1 + hist(temp11)
Next i
arr2 = ""
For i = bat + 1 To h
karak = Strings.Right(Strings.Left(arrtt, i + 1), 1)
arr2 = arr2 & karak
temp11 = Asc(karak)
diff2 = diff2 + hist(temp11)
Next i
If (diff1 = 0) And (diff2 = 0) Then Exit Sub
pem = l
If (diff2 > diff1) Or (diff2 = diff1) Or (bat = pem) Then
Text4.Text = Text4.Text & "Step" & vbCrLf
Text4.Text = Text4.Text & arr1 & " " & arr2 & vbCrLf
Text4.Text = Text4.Text & diff1 & " " & diff2 & vbCrLf
On Error Resume Next
ListBox1.Items.RemoveAt(0)
Text3.Text = ""
biner(penunjuk) = arr1
biner1(penunjuk) = "0"
penunjuk = penunjuk + 1
biner(penunjuk) = arr2
biner1(penunjuk) = "1"
penunjuk = penunjuk + 1
If Len(arr1) > 1 Then
ListBox1.Items.Add(arr1)
End If
If Len(arr2) > 1 Then
ListBox1.Items.Add(arr2)
End If
Text3.Text = ""
Text3.Text = ListBox1.Items(0)
If Text3.Text = "" Then Exit Sub
dat = Len(Text3.Text)
dat = dat - 2
bagi(dat)
End If
bat = bat - 1
bagi(bat)
End Sub
Sub bagidua()
Dim dat As Integer
Text3.Text = ListBox1.Items(0)
Text4.Text = "String hasil Shorting " & vbCrLf & ListBox1.Items(0)
Text4.Text = Text4.Text & vbCrLf & vbCrLf & "Frekuensi " & vbCrLf
For i = 0 To 101
If frek(i) > 0 Then
Text4.Text = Text4.Text & bobot(i) & " = " & Chr(bobot(i)) & " ==> " &
frek(i) & vbCrLf
End If
Next i
Text4.Text= Text4.Text & vbCrLf & vbCrLf & "Make Huffman Tree" & vbCrLf &
vbCrLf
dat = Len(Text3.Text)
origin = Text3.Text
dat = dat - 2
If Text3.Text <> "" Then
bagi(dat)
make_Huffman()
End If
End Sub
Sub make_Huffman()
Dim k, j As Integer
Dim kara As String
For i = 0 To 121
If biner(i) <> "" Then
End If
Next i
k = Len(origin)
For i = 1 To k
kara = Strings.Right(Strings.Left(origin, i), 1)
hasil_Huffman(i) = kara
For j = 0 To 121
If biner(j) <> "" Then
On Error Resume Next
If biner(j) Like "*" & kara & "*" Then
biner_Huffman(i) = biner_Huffman(i) & biner1(j)
End If
End If
Next j
Next i
Text4.Text = Text4.Text & vbCrLf & "Hasil Biner" & vbCrLf & vbCrLf
For i = 1 To 12
Form1.char_Huffman(i) = "x"
Form1.bin_Huffman(i) = "x"
Next
k = Len(origin)
Form1.pjng_pohon = k
For i = 1 To k
Text4.Text = Text4.Text & hasil_Huffman(i) & " = " & biner_Huffman(i) &
vbCrLf
Form1.char_Huffman(i) = hasil_Huffman(i)
Form1.bin_Huffman(i) = biner_Huffman(i)
Next i
Sub replace_bit()
Dim k, batas, dlbyte As Integer
Dim karakter As String
batas = Len(TextBox1.Text)
k = Len(origin)
Text4.Text = Text4.Text & vbCrLf & vbCrLf
For j = 1 To batas
karakter = Strings.Right(Strings.Left(TextBox1.Text, j), 1)
For i = 1 To k
If karakter = hasil_Huffman(i) Then
Text6.Text = Text6.Text & biner_Huffman(i)
End If
Next i
Next j
dlbyte = Len(Text6.Text) / 8
Label1.Text = Len(Text6.Text) & " bit = " & dlbyte & " Bytes"
lbl_Byte_Encrypt.Text = Len(TextBox1.Text) & " Bytes"
End Sub

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy