1. Menu utama (main_form.vb) - Aplikasi Watermarking Sebagai Teknik Penyembunyian Label Hak Cipta Pada Citra Digital Dengan Metode Randomly Sequenced Pulse Position Modulated Code

  1. Menu utama (main_form.vb)

  Public Class main_form 'deklarasi class main_form 'toolstripmenuitem : control component menu Private Sub EkstraksiToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EkstraksiToolStripMenuItem.Click Ekstraksi.Show() 'membuka form Ekstraksi End Sub Private Sub WatermarkingToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WatermarkingToolStripMenuItem.Click rsppmc.Show() 'membuka form watermarking rsppmc End Sub Private Sub DokumentasiToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DokumentasiToolStripMenuItem.Click help.Show() 'membuka form help End Sub Private Sub AboutMeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutMeToolStripMenuItem.Click About.Show() 'membuka form about End Sub Private Sub KeluarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KeluarToolStripMenuItem.Click End 'menghentikan/menutup program aplikasi End Sub Private Sub WatermarkjngToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WatermarkjngToolStripMenuItem.Click laporan.Show() 'membuka form laporan hasil watermarking End Sub Private Sub EkstraksiToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EkstraksiToolStripMenuItem1.Click lap_ekstraksi.Show() 'membuka form laporan hasil Ekstraksi End Sub End Class 'akhir dari tag class

  2. Watermarking (rsppmc.vb)

  Imports System.IO Imports System.Text

  Public Class rsppmc Dim bmap, bmap_label, bmap_dct As Bitmap Dim str2ascii(), arrKey(,) As String Dim ranDom() As Integer Dim matRed(,,), matGren(,,), matBlue(,,), arrGray(,), matBin(,,) As Integer Dim matDct(,,), matTransform(,,), matTranspose(,,), matD(,,), matModif(,,), matInvers(,,), matHasil(,,) As Single Private Function asc2Biner(ByVal ascii As String) Dim nAsc As Integer nAsc = CInt(ascii) If nAsc >= 0 And nAsc <= 255 Then Dim i, x, arrBin() As Integer x = 7 For i = 0 To 7 If nAsc > 1 Then arrBin(x) = nAsc Mod 2 nAsc = Int(nAsc / 2) ElseIf nAsc = 1 Then arrBin(x) = nAsc nAsc = 0 Else arrBin(x) = 0 End If x = x - 1 Next ascii = "" For i = 0 To 7 ascii = ascii + CStr(arrBin(i)) Next End If Return ascii End Function Private Sub citraHost() Dim Red, gren, blue As Integer Dim host As New Bitmap(PictureBox1.Image) If host.Width Mod 8 <> 0 And host.Height Mod 8 <> 0 Then Dim lebar, tinggi As Integer lebar = host.Width - (host.Width Mod 8) tinggi = host.Height - (host.Height Mod 8) bmap = New Bitmap(PictureBox1.Image, lebar, tinggi) Else bmap = New Bitmap(PictureBox1.Image) End If PictureBox1.Image = bmap Dim tempbmap As New Bitmap(PictureBox1.Image) 'tempbmap = bmap '========================= '=========================

  With tempbmap Dim X, Y As Integer ReDim matRed((.Width / 8) * (.Height / 8), 8, 8) ReDim matGren((.Width / 8) * (.Height / 8), 8, 8) ReDim matBlue((.Width / 8) * (.Height / 8), 8, 8) Dim mTemp, m, bar, kol As Integer progresBarStatus.Width = PictureBox1.Width progresBarStatus.Visible = True mTemp = 1 bar = 1 kol = 1 m = 1 For Y = 0 To .Height - 1 Application.DoEvents() For X = 0 To .Width - 1 Red = CInt(.GetPixel(X, Y).R) gren = CInt(.GetPixel(X, Y).G) blue = CInt(.GetPixel(X, Y).B) matRed(m, bar, kol) = Red matGren(m, bar, kol) = gren matBlue(m, bar, kol) = blue If kol = 8 And X <> (.Width - 1) Then kol = 1 m = m + 1 ElseIf kol = 8 And X = (.Width - 1) Then kol = 1 m = mTemp Else kol = kol + 1 End If blue = 10 bmap.SetPixel(X, Y, Color.FromArgb(Red, gren, blue)) Next If (Y + 1) Mod 8 = 0 And Y <> (.Height - 1) Then mTemp = mTemp + (.Width / 8) m = mTemp Else m = mTemp End If If bar = 8 Then bar = 1 Else bar = bar + 1 End If If (Y + 1) Mod 8 = 0 Then PictureBox1.Invalidate() Me.Text = "Proses Citra Host : " & Int(100 * Y / (bmap.Height - 1)).ToString & "%" progresBarStatus.Value = Int(100 * Y / (bmap.Height - 1)) End If PictureBox1.Refresh() Next End With Me.Text = "Proses Citra Host Berhasil" progresBarStatus.Visible = False End Sub Private Sub citraLabel() Dim Red, gren, blue, tMin, tMax, tHold As Integer 'bmap_label = New Bitmap(PictureBox2.Image) Dim Label As New Bitmap(PictureBox2.Image) If Label.Width <> bmap.Width / 8 And Label.Height <> bmap.Height / 8 Then bmap_label = New Bitmap(PictureBox2.Image, bmap.Width / 8, bmap.Height / 8) Else bmap_label = New Bitmap(PictureBox2.Image) End If PictureBox2.Image = bmap_label Dim tempbmap As New Bitmap(PictureBox2.Image) With tempbmap Dim X, Y As Integer ReDim arrGray(.Width, .Height) progresBarStatus.Width = PictureBox2.Width progresBarStatus.Visible = True tMin = 0 tMax = 0 For Y = 0 To tempbmap.Height - 1 Application.DoEvents() For X = 0 To tempbmap.Width - 1 Red = CInt(.GetPixel(X, Y).R) gren = CInt(.GetPixel(X, Y).G) blue = CInt(.GetPixel(X, Y).B) arrGray(X, Y) = CInt((Red + gren + blue) / 3) bmap_label.SetPixel(X, Y, Color.FromArgb(arrGray(X, Y), arrGray(X, Y), arrGray(X, Y))) 'cari nilai grey Min dan Max If tMin = 0 And tMax = 0 Then tMin = arrGray(X, Y) tMax = arrGray(X, Y) ElseIf arrGray(X, Y) > tMax Then tMax = arrGray(X, Y) ElseIf arrGray(X, Y) < tMin Then tMin = arrGray(X, Y) End If Next If (Y + 1) Mod 8 = 0 Then

  PictureBox1.Invalidate() Me.Text = "Proses Citra Label : " & Int(100 * Y / (bmap_label.Height - 1)).ToString & "%" progresBarStatus.Value = Int(100 * Y / (bmap_label.Height - 1)) End If PictureBox2.Refresh() Next tHold = (tMax + tMin) / 2 'hitung nilai treshold progresBarStatus.Width = PictureBox2.Width progresBarStatus.Visible = True ReDim matBin(.Width * .Height, 1, 1) Dim m As Integer Dim binLabel, grey As Integer X = 0 Y = 0 m = 1 For Y = 0 To .Height - 1 For X = 0 To .Width - 1 grey = CInt(.GetPixel(X, Y).R) 'cari nilai grey Min dan Max If grey > tHold Then grey = 255 'nilai 255 mewakili 1 binLabel = 1 Else grey = 0 binLabel = -1 End If matBin(m, 1, 1) = binLabel m = m + 1 bmap_label.SetPixel(X, Y, Color.FromArgb(grey, grey, grey)) 'simpan warna baru pada pixel(Y,X) Next If (Y + 1) Mod 8 = 0 Then PictureBox1.Invalidate() Me.Text = "Proses Citra Label : " & Int(100 * Y / (bmap_label.Height - 1)).ToString & "%" progresBarStatus.Value = Int(100 * Y / (bmap_label.Height - 1)) End If PictureBox2.Refresh() Next Me.Text = "Progres Citra Biner Berhasil" progresBarStatus.Visible = False End With End Sub Private Sub matHasilBlue(ByVal m As Integer) Dim X, Y, lst As Integer lst = 0 ListView3.Items.Clear() For X = 1 To 8 For Y = 1 To 8 'list.Show()

  ListView3.Items.Add(X & "," & Y) ListView3.Items(lst).SubItems.Add(matBlue(ranDom(m), X, Y)) ListView3.Items(lst).SubItems.Add(matModif(ranDom(m), X, Y)) ListView3.Items(lst).SubItems.Add(matD(ranDom(m), X, Y)) ListView3.Items(lst).SubItems.Add(Int(matHasil(ranDom(m), X, Y))) lst = lst + 1 Next Next End Sub Dim X, Y As Integer Dim def, akar As Single ReDim matDct(1, 8, 8) For X = 1 To 8 For Y = 1 To 8 If X - 1 = 0 Then akar = 1 / Math.Sqrt(8) Else def = (((2 * (Y - 1)) + 1) * ((X - 1) * Math.PI)) / 16 akar = Math.Sqrt(2 / 8) * Math.Cos(def) End If 'insert nilai koefisien DCT pada array DCT matDct(1, X, Y) = akar Next Next End Sub Private Sub binerLabel() Dim m, X, Y, lst As Integer lst = 0 ListView2.Items.Clear() m = 0 For X = 1 To bmap_label.Height For Y = 1 To bmap_label.Width m = m + 1 'list.Show() ListView2.Items.Add(m) ListView2.Items(lst).SubItems.Add(matBin(m, 1, 1)) lst = lst + 1 Next Next End Sub Private Sub sisipKey() Dim arrK() As String Dim arrC As Char() ReDim arrKey(8, 8) ReDim arrK(7) For i = 0 To 7 arrK(i) = asc2Biner(str2ascii(i)) Next For bar = 1 To 8 For kol = 1 To 8 arrC = arrK(bar - 1).ToCharArray arrKey(bar, kol) = arrC(kol - 1) Next Next End Sub Private Sub perkalianMatrik() 'sisipKey() Dim mat, x, y As Integer ReDim matTransform((bmap.Width / 8) * (bmap.Height / 8), 8, 8) ReDim matD((bmap.Width / 8) * (bmap.Height / 8), 8, 8) 'inisialisasi nilai matrik transpose For barM = 1 To 8 For kolM = 1 To 8 matTranspose(1, kolM, barM) = matDct(1, barM, kolM) Next Next 'perkalian matrik dct dengan matrik gray x = 1 For mat = 1 To (bmap.Width / 8) * (bmap.Height / 8) For barM = 1 To 8 For y = 1 To 8 matTransform(mat, x, y) = 0 For kolM = 1 To 8 matTransform(mat, x, y) = matTransform(mat, x, y) + (matDct(1, barM, kolM) * matBlue(mat, kolM, y)) Next Next x = x + 1 Next x = 1 Next ReDim matModif((bmap.Height / 8) * (bmap.Width / 8), 8, 8) x = 1 For mat = 1 To (bmap.Width / 8) * (bmap.Height / 8) For barM = 1 To 8 For y = 1 To 8 matD(mat, x, y) = 0 For kolM = 1 To 8 matD(mat, x, y) = matD(mat, x, y) + (matTransform(mat, barM, kolM) * matTranspose(1, kolM, y)) Next matModif(mat, x, y) = matD(mat, x, y) Next x = x + 1 Next x = 1 Next

  'cari rata2 key watermarking Dim rataKey As Integer rataKey = 0 For i = 0 To 7 rataKey = rataKey + str2ascii(i) Next rataKey = rataKey / 8 randomGen(rataKey) 'inisialisasi nilai tertinggi tiap baris masing2 matrik D Dim maxBar, kolH, matrix, barH As Integer For mat = 1 To (bmap.Height / 8) * (bmap.Width / 8) maxBar = 0 For kolM = 1 To 8 If barM = 1 And kolM = 1 Then matrix = 0 matD(ranDom(mat), barM, kolM) = matD(ranDom(mat), barM, kolM) + (1 + (2 * matBin(mat, 1, 1))) Else matrix = matD(ranDom(mat), barM, kolM) matrix = Math.Abs(matD(ranDom(mat), barM, kolM)) End If If matrix > maxBar Then maxBar = matrix kolH = kolM barH = barM End If Next If mat <= bmap_label.Height * bmap_label.Width Then matD(ranDom(mat), barH, kolH) = matD(ranDom(mat), barH, kolH) + (3.14 * (2 * matBin(mat, 1, 1))) End If Next Next ReDim matInvers((bmap.Width / 8) * (bmap.Height / 8), 8, 8) ReDim matHasil((bmap.Width / 8) * (bmap.Height / 8), 8, 8) x = 1 For mat = 1 To (bmap.Width / 8) * (bmap.Height / 8) For barM = 1 To 8 For y = 1 To 8 matInvers(mat, x, y) = 0 For kolM = 1 To 8 matInvers(mat, x, y) = matInvers(mat, x, y) + (matTranspose(1, barM, kolM) * matD(mat, kolM, y)) Next Next x = x + 1 Next x = 1 Next x = 1

  For mat = 1 To (bmap.Width / 8) * (bmap.Height / 8) For barM = 1 To 8 For y = 1 To 8 matHasil(mat, x, y) = 0 For kolM = 1 To 8 matHasil(mat, x, y) = matHasil(mat, x, y) + (matInvers(mat, barM, kolM) * matDct(1, kolM, y)) Next Next x = x + 1 Next x = 1 Next End Sub Private Sub citraDct() Dim m, mTemp, bar, kol, Red, gren, blue As Integer Dim tempbmap As New Bitmap(PictureBox3.Image) mTemp = 1 bar = 1 kol = 1 m = 1 With tempbmap Dim X, Y As Integer sisipKey() progresBarStatus.Width = PictureBox1.Width progresBarStatus.Visible = True For Y = 0 To .Height - 1 Application.DoEvents() For X = 0 To .Width - 1 Red = matRed(m, bar, kol) gren = matGren(m, bar, kol) If m = (bmap_label.Width * (bmap_label.Height / 2)) - (bmap_label.Width / 2) Then 'mencari posisi tengah citra If arrKey(bar, kol) = 0 Then matHasil(m, bar, kol) = arrKey(bar, kol) Else matHasil(m, bar, kol) = 255 End If End If blue = Int(matHasil(m, bar, kol)) If blue > 255 Then blue = 255 ElseIf blue < 0 Then blue = 0 End If bmap.SetPixel(X, Y, Color.FromArgb(Red, gren, blue)) If kol = 8 And X <> (.Width - 1) Then kol = 1 m = m + 1 ElseIf kol = 8 And X = (.Width - 1) Then kol = 1 m = mTemp Else kol = kol + 1 End If Next PictureBox3.Refresh() If (Y + 1) Mod 8 = 0 And Y <> .Height - 1 Then mTemp = mTemp + (.Width / 8) m = mTemp m = mTemp End If If bar = 8 Then bar = 1 Else bar = bar + 1 End If If (Y + 1) Mod 8 = 0 Then PictureBox3.Invalidate() Me.Text = "Proses Citra Watermarking : " & Int(100 * Y / (bmap.Height - 1)).ToString & "%" progresBarStatus.Value = Int(100 * Y / (bmap.Height - 1)) End If Next End With progresBarStatus.Visible = False Me.Text = "Proses Citra Watermarking Berhasil" bmap_dct = New Bitmap(PictureBox3.Image) PictureBox3.Image = bmap_dct End Sub Private Sub randomGen(ByVal nRan As Integer) Dim b, c, d, e, ar As Integer b = (bmap.Width / 8) * (bmap.Height / 8) c = nRan If c Mod 2 = 0 Then d = c - 4 e = d Else d = c - 3 e = d End If ReDim ranDom(b) For ar = 1 To b ranDom(ar) = d If d Mod 2 <> 0 Then d = d + 2

  End If If d - 2 = e Then d = 1 End If If d = 2 Then d = b ElseIf d Mod 2 = 0 Then d = d - 2 End If Next End Sub Public Sub setBaris(ByVal path As String, ByVal content As Dim fileWriter As StreamWriter = File.AppendText(path) Dim i As Integer i = 0 Try fileWriter.WriteLine(content) fileWriter.Close() Catch x As Exception MsgBox(x.Message) End Try End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged Dim str As String Dim x As Integer str = TextBox1.Text Dim charArray As Char() = str.ToCharArray ReDim str2ascii(str.Length) TextBox2.Clear() For x = 0 To str.Length - 1 str2ascii(x) = Asc(charArray(x)) If TextBox2.Text <> "" Then TextBox2.Text = TextBox2.Text + " " + str2ascii(x) Else TextBox2.Text = str2ascii(x) End If Next If TextBox1.TextLength = 8 Then Button4.Enabled = True End If End Sub Public Function hitungBaris(ByVal FullPath As String) Dim fileReader As StreamReader Dim content As String = "" Dim i As Integer i = 0

  Try fileReader = New StreamReader(FullPath) Do Until (fileReader.EndOfStream) i = i + 1 content = fileReader.ReadLine() Loop fileReader.Close() Catch x As Exception MsgBox(x.Message) End Try Return i End Function As System.EventArgs) Handles Button1.Click OpenFileDialog1.Filter = "Images|*.JPG;*.BMP" OpenFileDialog1.InitialDirectory = Application.StartupPath + "\Watermarking\Asli\" OpenFileDialog1.ShowDialog() PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName) Dim fileCopy As String Dim num As String num = hitungBaris(Application.StartupPath + "\Watermarking\Asli\laporan.txt") + 1 fileCopy = Application.StartupPath + "\Watermarking\Asli\citra_asli-" + num + ".jpg" If File.Exists(fileCopy) = False Then File.Copy(OpenFileDialog1.FileName, fileCopy) End If setBaris(Application.StartupPath + "\Watermarking\Asli\laporan.txt", "\Watermarking\Asli\citra_asli-" + num + ".jpg") Button7.Enabled = True End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click OpenFileDialog1.Filter = "Images|*.JPG;*.BMP" OpenFileDialog1.InitialDirectory = Application.StartupPath + "\Watermarking\Hasil\" OpenFileDialog1.ShowDialog() PictureBox2.Image = Image.FromFile(OpenFileDialog1.FileName) citraLabel() binerLabel() Dim fileCopy1, fileCopy2 As String Dim num As String num = hitungBaris(Application.StartupPath + "\Watermarking\Penyisip\laporan.txt") + 1 fileCopy1 = Application.StartupPath + "\Watermarking\Penyisip\citra_penyisip-" + num + ".jpg" fileCopy2 = Application.StartupPath + "\Watermarking\Biner\citra_biner-" + num + ".jpg" If File.Exists(fileCopy1) = False Then

  File.Copy(OpenFileDialog1.FileName, fileCopy1) End If If File.Exists(fileCopy2) = False Then bmap_label.Save(fileCopy2) End If setBaris(Application.StartupPath + "\Watermarking\Penyisip\laporan.txt", "\Watermarking\Penyisip\citra_penyisip-" + num + ".jpg") setBaris(Application.StartupPath + "\Watermarking\Biner\laporan.txt", "\Watermarking\Biner\citra_biner-"

  • num + ".jpg") Button2.Enabled = True End Sub As System.EventArgs) Handles Button2.Click If TextBox1.Text.Length < 8 Then MsgBox("masukan key watermarking 8 Karater", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Information") TextBox1.Text = "" TextBox1.Focus()

  Exit Sub End If perkalianMatrik() citraDct() Button8.Enabled = True End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim num As String num = hitungBaris(Application.StartupPath + "\Watermarking\Hasil\laporan.txt") + 1 bmap_dct.Save(Application.StartupPath + "\Watermarking\Hasil\citra_hasil-" + num + ".jpg") setBaris(Application.StartupPath + "\Watermarking\Hasil\laporan.txt", "\Watermarking\Hasil\citra_hasil-"

  • num + ".jpg") MsgBox("Citra Hasil Watermarking Berhasil disimpan", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Information") End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click matHasilBlue(1) Label3.Text = 1

  neks.Enabled = True Button3.Enabled = True End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click citraHost() koeDct() Button4.Enabled = True

  PictureBox3.Image = PictureBox1.Image End Sub Private Sub neks_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles neks.Click Label3.Text = Label3.Text + 1 If Label3.Text > (bmap.Height / 8) * (bmap.Width / 8) Then Label3.Text = (bmap.Height / 8) * (bmap.Width / 8) neks.Enabled = False End If matHasilBlue(Label3.Text) If Label3.Text > 1 Then End If End Sub Private Sub prev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles prev.Click Label3.Text = Label3.Text - 1 If Label3.Text = 1 Then Label3.Text = 1 prev.Enabled = False End If matHasilBlue(Label3.Text) If Label3.Text < (bmap.Height / 8) * (bmap.Width / 8) Then neks.Enabled = True End If End Sub End Class

  Imports System.IO Imports System.Text Public Class Ekstraksi 'dim adalah deklarasi variabel dengan [as] sebagai penugasannya. mis: as integer berarti variabel 'yang dideklarasikan adalah sebagai data integer.

  Dim bmap, bmap_watermark, bmap_dct As Bitmap 'variabel yang menggunakan kurung dan koma di dalamnya adalah pendeklarasian variabel array. 'mis a() -> array satu dimensi, a(,) -> array dua dimensi, dan a(,,) -> array tiga dimensi Dim matRed(,,), matGren(,,), matBlue(,,), arrGray(,), matBin(,,), matCitraAsli(,,), matCitraWatermark(,,) As Integer Dim matDct(,,), matTransform(,,), matTranspose(,,), matD(,,), matModif(,,), matInvers(,,), matHasil(,,) As Single Dim matTransformW(,,), matDW(,,), matModifW(,,), matInversW(,,), matHasilW(,,) As Single Dim str2ascii(), arrKey(,), keyCitra(,), arrKeyCitra(,) As String

  Dim ranDom() As Integer Private Sub citraAsli() Dim Red, gren, blue As Integer Dim host As New Bitmap(PictureBox1.Image) If host.Width Mod 8 <> 0 And host.Height Mod 8 <> 0 Then Dim lebar, tinggi As Integer lebar = host.Width - (host.Width Mod 8) tinggi = host.Height - (host.Height Mod 8) bmap = New Bitmap(PictureBox1.Image, lebar, tinggi) Else bmap = New Bitmap(PictureBox1.Image) End If 'bmap = New Bitmap(PictureBox1.Image) PictureBox1.Image = bmap Dim tempbmap As New Bitmap(PictureBox1.Image) 'tempbmap = bmap With tempbmap Dim X, Y As Integer ReDim matRed((.Width / 8) * (.Height / 8), 8, 8) ReDim matGren((.Width / 8) * (.Height / 8), 8, 8) ReDim matBlue((.Width / 8) * (.Height / 8), 8, 8) ReDim matCitraAsli((.Width / 8) * (.Height / 8), 8, 8) Dim mTemp, m, bar, kol As Integer progresBarStatus.Width = PictureBox1.Width progresBarStatus.Visible = True mTemp = 1 bar = 1 kol = 1 m = 1 For Y = 0 To .Height - 1 Application.DoEvents() For X = 0 To .Width - 1 Red = CInt(.GetPixel(X, Y).R) gren = CInt(.GetPixel(X, Y).G) blue = CInt(.GetPixel(X, Y).B) matCitraAsli(m, bar, kol) = blue If kol = 8 And X <> (.Width - 1) Then kol = 1 m = m + 1 ElseIf kol = 8 And X = (.Width - 1) Then kol = 1 m = mTemp Else kol = kol + 1 End If blue = (Red + gren + blue) / 3 bmap.SetPixel(X, Y, Color.FromArgb(blue, blue, blue))

  Next If (Y + 1) Mod 8 = 0 And Y <> (.Height - 1) Then mTemp = mTemp + (.Width / 8) m = mTemp Else m = mTemp End If If bar = 8 Then bar = 1 Else bar = bar + 1 End If PictureBox1.Invalidate() Me.Text = "Proses Citra Asli : " & Int(100 * Y / (bmap.Height - 1)).ToString & "%" progresBarStatus.Value = Int(100 * Y / (bmap.Height - 1)) End If PictureBox1.Refresh() Next Me.Text = "Proses Citra Asli Berhasil >> Input Citra Terwatermarking" End With progresBarStatus.Visible = False End Sub Private Sub citraWatermarking() Dim Red, gren, blue As Integer bmap_watermark = New Bitmap(PictureBox2.Image) PictureBox2.Image = bmap_watermark Dim tempbmap As New Bitmap(PictureBox2.Image) 'tempbmap = bmap With tempbmap Dim X, Y As Integer ReDim matRed((.Width / 8) * (.Height / 8), 8, 8) ReDim matGren((.Width / 8) * (.Height / 8), 8, 8) ReDim matBlue((.Width / 8) * (.Height / 8), 8, 8) ReDim matCitraWatermark((.Width / 8) * (.Height / 8), 8, 8) Dim mTemp, m, bar, kol As Integer progresBarStatus.Width = PictureBox2.Width progresBarStatus.Visible = True mTemp = 1 bar = 1 kol = 1 m = 1 For Y = 0 To .Height - 1 Application.DoEvents() For X = 0 To .Width - 1 Red = CInt(.GetPixel(X, Y).R) gren = CInt(.GetPixel(X, Y).G) blue = CInt(.GetPixel(X, Y).B) matCitraWatermark(m, bar, kol) = blue If kol = 8 And X <> (.Width - 1) Then kol = 1 m = m + 1 ElseIf kol = 8 And X = (.Width - 1) Then kol = 1 m = mTemp Else kol = kol + 1 End If bmap_watermark.SetPixel(X, Y, Color.FromArgb(blue, blue, blue)) Next If (Y + 1) Mod 8 = 0 And Y <> (.Height - 1) Then mTemp = mTemp + (.Width / 8) m = mTemp Else m = mTemp End If If bar = 8 Then bar = 1 Else bar = bar + 1 End If If (Y + 1) Mod 8 = 0 Then PictureBox1.Invalidate() Me.Text = "Proses Citra Watermarking : " & Int(100 * Y / (bmap.Height - 1)).ToString & "%" progresBarStatus.Value = Int(100 * Y / (bmap.Height - 1)) End If PictureBox2.Refresh() Next Me.Text = "Proses Citra Watermarking Berhasil >> Input Key Watermarking" End With progresBarStatus.Visible = False End Sub Private Sub randomGen(ByVal nRan As Integer) Dim b, c, d, e, ar As Integer b = (bmap.Width / 8) * (bmap.Height / 8) c = nRan If c Mod 2 = 0 Then d = c - 4 e = d Else d = c - 3 e = d

  End If ReDim ranDom(b) For ar = 1 To b ranDom(ar) = d If d Mod 2 <> 0 Then d = d + 2 End If If d - 2 = e Then d = 1 End If d = b ElseIf d Mod 2 = 0 Then d = d - 2 End If Next End Sub Private Function asc2Biner(ByVal ascii As String) Dim nAsc As Integer nAsc = CInt(ascii) If nAsc >= 0 And nAsc <= 255 Then Dim i, x, arrBin() As Integer ReDim arrBin(7) x = 7 For i = 0 To 7 If nAsc > 1 Then arrBin(x) = nAsc Mod 2 nAsc = Int(nAsc / 2) ElseIf nAsc = 1 Then arrBin(x) = nAsc nAsc = 0 Else arrBin(x) = 0 End If x = x - 1 Next ascii = "" For i = 0 To 7 ascii = ascii + CStr(arrBin(i)) Next End If Return ascii End Function Private Sub sisipKey() Dim arrK() As String Dim arrC As Char() ReDim arrKey(8, 8) ReDim arrK(7) For i = 0 To 7 arrK(i) = asc2Biner(str2ascii(i)) Next

  For bar = 1 To 8 For kol = 1 To 8 arrC = arrK(bar - 1).ToCharArray arrKey(bar, kol) = arrC(kol - 1) Next Next End Sub Private Sub koeDctAsli() 'sisipKey() Dim X, Y As Integer Dim def, akar As Single ReDim matDct(1, 8, 8) For X = 1 To 8 For Y = 1 To 8 If X - 1 = 0 Then akar = 1 / Math.Sqrt(8) Else def = (((2 * (Y - 1)) + 1) * ((X - 1) * Math.PI)) / 16 akar = Math.Sqrt(2 / 8) * Math.Cos(def) End If matDct(1, X, Y) = akar Next Next End Sub Private Sub koeDctWatermarking() Dim X, Y, lst As Integer ReDim matDct(1, 8, 8) lst = 0 ListView2.Items.Clear() ListView1.Items.Clear() For X = 1 To 8 For Y = 1 To 8 'list.Show() ListView1.Items.Add(X & "," & Y) ListView2.Items.Add(X & "," & Y) ListView1.Items(lst).SubItems.Add(matD(1, X, Y)) ListView1.Items(lst).SubItems.Add(matCitraAsli(1, X, Y)) ListView2.Items(lst).SubItems.Add(matDW(1, X, Y)) ListView2.Items(lst).SubItems.Add(matCitraWatermark(1, X, Y)) lst = lst + 1 Next Next End Sub Private Sub perkalianMatrik() Dim mat, x, y As Integer ReDim matTranspose(1, 8, 8) ReDim matTransform((bmap.Width / 8) * (bmap.Height / 8), 8, 8)

  ReDim matTransformW((bmap.Width / 8) * (bmap.Height / 8), 8, 8) ReDim matD((bmap.Width / 8) * (bmap.Height / 8), 8, 8) ReDim matDW((bmap.Width / 8) * (bmap.Height / 8), 8, 8) 'inisialisasi nilai matrik transpose 'For mat = 1 To (bmap.Width / 8) * (bmap.Height / 8) For barM = 1 To 8 For kolM = 1 To 8 matTranspose(1, kolM, barM) = matDct(1, barM, kolM) Next Next 'Next 'perkalian matrik dct dengan matrik gray For mat = 1 To (bmap.Width / 8) * (bmap.Height / 8) For barM = 1 To 8 For y = 1 To 8 matTransform(mat, x, y) = 0 matTransformW(mat, x, y) = 0 For kolM = 1 To 8 matTransform(mat, x, y) = matTransform(mat, x, y) + (matDct(1, barM, kolM) * matCitraAsli(mat, kolM, y)) matTransformW(mat, x, y) = matTransformW(mat, x, y) + (matDct(1, barM, kolM) * matCitraWatermark(mat, kolM, y)) Next Next x = x + 1 Next x = 1 Next x = 1 For mat = 1 To (bmap.Width / 8) * (bmap.Height / 8) For barM = 1 To 8 For y = 1 To 8 matD(mat, x, y) = 0 matDW(mat, x, y) = 0 For kolM = 1 To 8 matD(mat, x, y) = matD(mat, x, y) + (matTransform(mat, barM, kolM) * matTranspose(1, kolM, y)) matDW(mat, x, y) = matDW(mat, x, y) + (matTransformW(mat, barM, kolM) * matTranspose(1, kolM, y)) Next Next x = x + 1 Next x = 1 Next Dim rataKey As Integer rataKey = 0 For i = 0 To 7 rataKey = rataKey + str2ascii(i) Next rataKey = rataKey / 8 randomGen(rataKey)

  Me.Text = "Pengolahan Citra : Proses berhasil, lanjutkan ke Proses Ekstraksi" End Sub Private Sub citraHasil() bmap_dct = New Bitmap(PictureBox1.Image, (bmap.Width / 8), (bmap.Height / 8)) PictureBox3.Image = bmap_dct With bmap_dct Dim X, Y, mat As Integer mat = 1 For Y = 0 To .Height - 1 Application.DoEvents() bmap_dct.SetPixel(X, Y, Color.FromArgb(matBin(mat, 1, 1), matBin(mat, 1, 1), matBin(mat, 1, 1))) mat = mat + 1 Next PictureBox3.Refresh() Next End With Me.Text = "Proses Ekstraksi Berhasil" PictureBox3.Image = bmap_dct End Sub Private Sub getKey() Dim x, y, m, bar, kol, mTemp As Integer ReDim keyCitra(8, 8) mTemp = 1 m = 1 bar = 1 kol = 1 For y = 0 To bmap_watermark.Height - 1 Application.DoEvents() For x = 0 To bmap_watermark.Width - 1 If m = (bmap_watermark.Width / 8) * ((bmap_watermark.Height / 8) / 2) - ((bmap_watermark.Width / 8) / 2) Then If matCitraWatermark(m, bar, kol) = 0 Then keyCitra(bar, kol) = "0" Else keyCitra(bar, kol) = "1" End If End If If kol = 8 And x <> (bmap_watermark.Width - 1) Then kol = 1 m = m + 1 ElseIf kol = 8 And x = (bmap_watermark.Width - 1) Then kol = 1 m = mTemp Else kol = kol + 1 End If Next

  If (y + 1) Mod 8 = 0 And y <> (bmap_watermark.Height - 1) Then mTemp = mTemp + (bmap_watermark.Width / 8) m = mTemp Else m = mTemp End If If bar = 8 Then bar = 1 Else bar = bar + 1 End If End Sub Public Sub setBaris(ByVal path As String, ByVal content As String) Dim fileWriter As StreamWriter = File.AppendText(path) Dim i As Integer i = 0 Try fileWriter.WriteLine(content) fileWriter.Close() Catch x As Exception MsgBox(x.Message) End Try End Sub Public Function hitungBaris(ByVal FullPath As String) Dim fileReader As StreamReader Dim content As String = "" Dim i As Integer i = 0 Try fileReader = New StreamReader(FullPath) Do Until (fileReader.EndOfStream) i = i + 1 content = fileReader.ReadLine() Loop fileReader.Close() Catch x As Exception MsgBox(x.Message) End Try Return i End Function '======================================================= Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click OpenFileDialog1.Filter = "Images|*.JPG;*.BMP" OpenFileDialog1.InitialDirectory = Application.StartupPath + "\Watermarking\Asli\" OpenFileDialog1.ShowDialog()

  PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName) citraAsli() Dim fileCopy As String fileCopy = Application.StartupPath + "\Ekstraksi\Asli\" + OpenFileDialog1.SafeFileName If File.Exists(fileCopy) = False Then File.Copy(OpenFileDialog1.FileName, fileCopy) End If setBaris(Application.StartupPath + "\Ekstraksi\Asli\lap_citra_asli.txt", "\Ekstraksi\Asli\" + OpenFileDialog1.SafeFileName) Button3.Enabled = True End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click OpenFileDialog1.Filter = "Images|*.JPG;*.BMP" OpenFileDialog1.InitialDirectory = Application.StartupPath + "\Watermarking\Hasil\" OpenFileDialog1.ShowDialog() PictureBox2.Image = Image.FromFile(OpenFileDialog1.FileName) citraWatermarking() getKey() PictureBox3.Image = PictureBox2.Image Dim fileCopy As String fileCopy = Application.StartupPath + "\Ekstraksi\Watermark\"

  • OpenFileDialog1.SafeFileName If File.Exists(fileCopy) = False Then File.Copy(OpenFileDialog1.FileName, fileCopy) End If setBaris(Application.StartupPath + "\Ekstraksi\Watermark\lap_citra_watermark.txt", "\Ekstraksi\Watermark\" + OpenFileDialog1.SafeFileName) TextBox1.Enabled = True

  End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click koeDctAsli() perkalianMatrik() Button4.Enabled = True koeDctWatermarking() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim mat, bar, kol, rAsli, rWatermark As Integer ReDim matBin((bmap.Width / 8) * (bmap.Height / 8), 1, 1) rAsli = 0 rWatermark = 0 For mat = 1 To ((bmap.Width / 8) * (bmap.Height / 8))

  For bar = 1 To 8 For kol = 1 To 8 rWatermark = rWatermark + matDW(ranDom(mat), bar, kol) rAsli = rAsli + matD(ranDom(mat), bar, kol) Next Next rAsli = rAsli / 64 rWatermark = rWatermark / 64 If rWatermark < rAsli Then matBin(mat, 1, 1) = 0 Else matBin(mat, 1, 1) = 255 End If citraHasil() Button2.Enabled = True End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged Button5.Enabled = False GroupBox3.Text = "Your Key is not Valid" Dim str As String Dim x As Integer str = TextBox1.Text Dim charArray As Char() = str.ToCharArray ReDim str2ascii(str.Length) TextBox2.Clear() For x = 0 To str.Length - 1 str2ascii(x) = Asc(charArray(x)) If TextBox2.Text <> "" Then TextBox2.Text = TextBox2.Text + " " + str2ascii(x) Else TextBox2.Text = str2ascii(x) End If Next If TextBox1.TextLength = 8 Then Dim validKey As Boolean sisipKey() validKey = True For bar = 1 To 8 For kol = 1 To 8 If arrKey(bar, kol) <> keyCitra(bar, kol) Then validKey = False End If Next Next If validKey = True Then Button5.Enabled = True GroupBox3.Text = "Your Key is Valid"

  Me.Text = "Klik Get Matrik untuk mendapatkan nilai pixel Citra" Else Button5.Enabled = False GroupBox3.Text = "Your Key is not Valid" End If End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim num As String "\Ekstraksi\Hasil\lap_ekstraksi.txt") + 1 bmap_dct.Save(Application.StartupPath + "\Ekstraksi\Hasil\citra_ekstraksi-" + num + ".jpg") setBaris(Application.StartupPath + "\Ekstraksi\Hasil\lap_ekstraksi.txt", "\Ekstraksi\Hasil\citra_ekstraksi-" + num + ".jpg") MsgBox("Citra Hasil Ekstraksi Berhasil disimpan", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Information") End Sub End Class

  Public Class About 'deklarasikan prosedur form about pada saat form diload Private Sub About_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'deklarasi variabel i sebagai integer dan diisi dengan fungsi freeFile Dim i As Integer = FreeFile() 'memanggil fungsi open file dengan parameter : number file, lokasi file, mode open FileOpen(i, Application.StartupPath + "\support\about_application.txt", OpenMode.Input) 'mengisi properties text pada textbox2 dengan fungsi inputString TextBox2.Text = InputString(i, LOF(i)) 'tutup file i FileClose(i) FileOpen(i, Application.StartupPath + "\support\about_me.txt", OpenMode.Input) TextBox1.Text = InputString(i, LOF(i)) FileClose(i) End Sub End Class

  Public Class help Private Sub help_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim i As Integer = FreeFile() FileOpen(i, Application.StartupPath + "\support\help_watermarking.txt", OpenMode.Input) TextBox1.Text = InputString(i, LOF(i)) FileClose(i) FileOpen(i, Application.StartupPath + "\support\help_ekstraksi.txt", OpenMode.Input) TextBox2.Text = InputString(i, LOF(i)) FileClose(i) End Sub End Class