Dalam Pembuatan Program ini diperlukan :
1. Visual Basic. Net 2008
2. Dot Net Bar , agar tampilan menarik seperti diatas....
coba perhatikan textboxt digambar atas ada watermarknya, kalo textboxt biasa sulit untuk membuat watermark di textbox kalao pakai Dot Net Bar itu mudah....
sehabis dipersiapkan semuanya... ini Script koding Form Loginnya...
Public Class Login
Sub konfirm()
If user.Text = "HENDIKA" And pass.Text = "ganteng" Then
Timer1.Enabled = True
CircularProgress1.Enabled = True
CircularProgress1.Visible = True
ElseIf user.Text = "" Then
MsgBox("Sorry Username is Empty.., and try again !!", MsgBoxStyle.Critical, "Information")
user.Text = ""
pass.Text = ""
user.Focus()
ElseIf pass.Text = "" Then
MsgBox("Sorry Password is Empty.., and try again !!", MsgBoxStyle.Critical, "Information")
pass.Text = ""
pass.Focus()
ElseIf user.Text <> "HENDIKA" Then
MsgBox("Sorry Username is Wrong or Not Valid.., and try again !!", MsgBoxStyle.Critical, "Information")
user.Text = ""
pass.Text = ""
user.Focus()
ElseIf pass.Text <> "ganteng" Then
MsgBox("Sorry Password is Wrong.., and try again !!", MsgBoxStyle.Critical, "Information")
pass.Text = ""
pass.Focus()
End If
End Sub
Private Sub user_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles user.KeyDown
If e.KeyCode = Keys.Enter Then
If user.Text = "" Then
MsgBox("Sorry Username is Empty..!!", MsgBoxStyle.Critical, "Information")
user.Focus()
Else
pass.Focus()
End If
End If
End Sub
Private Sub ButtonX1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX1.Click
konfirm()
End Sub
Private Sub pass_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles pass.KeyDown
If e.KeyCode = Keys.Enter Then
konfirm()
End If
End Sub
Private Sub Login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CircularProgress1.Visible = False
Timer1.Enabled = False
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
CircularProgress1.Value = CircularProgress1.Value + 1
If CircularProgress1.Value = 100 Then
Timer1.Stop()
Form1.Show()
Me.Hide()
End If
End Sub
Private Sub user_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles user.KeyPress
'membuat textbox gede semua
e.KeyChar = Char.ToUpper(e.KeyChar)
End Sub
End Class
Setelah itu buat form baru dengan nama Form1, lalau kas
dan sketsa formnya seperti 5 gambar diatas, dan dibawah ini kodingnya....'import komponen webcam
Imports System.Runtime.InteropServices
Public Class Form1
Dim gambar As Bitmap
Dim w As Bitmap
'awal listing kamera
Const WM_CAP_START = &H400S
Const WS_CHILD = &H40000000
Const WS_VISIBLE = &H10000000
Const WM_CAP_DRIVER_CONNECT = 1034
Const WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11
Const WM_CAP_EDIT_COPY = WM_CAP_START + 30
Const WM_CAP_SEQUENCE = WM_CAP_START + 62
Const WM_CAP_FILE_SAVEAS = WM_CAP_START + 23
Const WM_CAP_SET_SCALE = WM_CAP_START + 53
Const WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52
Const WM_CAP_SET_PREVIEW = WM_CAP_START + 50
Const SWP_NOMOVE = &H2S
Const SWP_NOSIZE = 1
Const SWP_NOZORDER = &H4S
Const HWND_BOTTOM = 1
Declare Function capGetDriverDescriptionA Lib "avicap32.dll" _
(ByVal wDriverIndex As Short, _
ByVal lpszName As String, ByVal cbName As Integer, ByVal lpszVer As String, _
ByVal cbVer As Integer) As Boolean
Declare Function capCreateCaptureWindowA Lib "avicap32.dll" _
(ByVal lpszWindowName As String, ByVal dwStyle As Integer, _
ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, _
ByVal nHeight As Short, ByVal hWnd As Integer, _
ByVal nID As Integer) As Integer
Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Integer, ByVal Msg As Integer, ByVal wParam As Integer, _
<MarshalAs(UnmanagedType.AsAny)> ByVal lParam As Object) As Integer
Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" _
(ByVal hwnd As Integer, _
ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, _
ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
Declare Function DestroyWindow Lib "user32" (ByVal hndw As Integer) As Boolean
Dim VideoSource As Integer
Dim hWnd As Integer
'akhir listing pemanggilan webcam
Sub starcam()
hWnd = capCreateCaptureWindowA(hWnd, WS_VISIBLE Or WS_CHILD, 0, 0, 0, 0, picture1.Handle.ToInt32, 1034)
SendMessage(hWnd, WM_CAP_DRIVER_CONNECT, 0, 0)
SendMessage(hWnd, WM_CAP_SET_SCALE, True, 0)
SendMessage(hWnd, WM_CAP_SET_PREVIEWRATE, 30, 0)
SendMessage(hWnd, WM_CAP_SET_PREVIEW, True, 0)
SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, _
picture1.Width, picture1.Height, _
SWP_NOMOVE Or SWP_NOZORDER)
End Sub
Private Sub grayscale_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles grayscale.Click
Dim rt, pc, pb As Integer
Dim vm, vh, vb As Integer
Dim gambar2 As Bitmap
picture2.Image = picture1.Image
gambar2 = New Bitmap(picture2.Image)
For pb = 0 To gambar2.Height - 1
For pc = 0 To gambar2.Width - 1
vm = gambar2.GetPixel(pc, pb).R
vh = gambar2.GetPixel(pc, pb).G
vb = gambar2.GetPixel(pc, pb).B
rt = (vm + vh + vb) / 3
gambar2.SetPixel(pc, pb, Color.FromArgb(rt, rt, rt))
Next
Next
picture2.Image = gambar2
picture2.Refresh()
End Sub
Private Sub DefaultGambarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DefaultGambarToolStripMenuItem.Click
picture2.Image = New Bitmap(picture1.Image)
gambar = picture2.Image
End Sub
Private Sub GrayscaleToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GrayscaleToolStripMenuItem.Click
If picture2.Image Is Nothing Then
MsgBox("WARNING : Tidak ada gambar untuk di konversi!")
Exit Sub
End If
Dim pb, pc As Integer
Dim rt, vm, vh, vb As Double
With gambar
For pb = 0 To .Height - 1
For pc = 0 To .Width - 1
vm = .GetPixel(pc, pb).R
vh = .GetPixel(pc, pb).G
vb = .GetPixel(pc, pb).B
rt = (vm + vh + vb) / 3
.SetPixel(pc, pb, Color.FromArgb(rt, rt, rt))
Next
picture2.Image = gambar
picture2.Refresh()
Next
End With
End Sub
Private Sub NegatifToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NegatifToolStripMenuItem.Click
If picture2.Image Is Nothing Then
MsgBox("WARNING : Tidak ada gambar untuk di konversi!")
Exit Sub
End If
Dim pb, pc As Integer
Dim vm, vh, vb As Double
With gambar
For pb = 0 To .Height - 1
For pc = 0 To .Width - 1
vm = 255 - .GetPixel(pc, pb).R
vh = 255 - .GetPixel(pc, pb).G
vb = 255 - .GetPixel(pc, pb).B
If vm <= 0 Then vm = 0
If vb <= 0 Then vb = 0
If vh <= 0 Then vh = 0
.SetPixel(pc, pb, Color.FromArgb(vm, vh, vb))
Next
picture2.Image = gambar
picture2.Refresh()
Next
End With
End Sub
Private Sub BrigthnessToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BrigthnessToolStripMenuItem.Click
If picture2.Image Is Nothing Then
MsgBox("WARNING : Tidak ada gambar untuk di konversi!")
Exit Sub
End If
Dim pb, pc As Integer
Dim vm, vh, vb As Double
With gambar
For pb = 0 To .Height - 1
For pc = 0 To .Width - 1
vm = .GetPixel(pc, pb).R + 5
vh = .GetPixel(pc, pb).G + 5
vb = .GetPixel(pc, pb).B + 5
If vm > 255 Then vm = 255
If vb > 255 Then vb = 255
If vh > 255 Then vh = 255
.SetPixel(pc, pb, Color.FromArgb(vm, vh, vb))
Next
picture2.Image = gambar
picture2.Refresh()
Next
End With
End Sub
Private Sub BinerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BinerToolStripMenuItem.Click
If picture2.Image Is Nothing Then
MsgBox("WARNING : Tidak ada gambar untuk di konversi!")
Exit Sub
End If
Dim pb, pc As Integer
Dim rata, vm, vh, vb As Double
With gambar
For pb = 0 To .Height - 1
For pc = 0 To .Width - 1
vm = .GetPixel(pc, pb).R
vh = .GetPixel(pc, pb).G
vb = .GetPixel(pc, pb).B
rata = (vm + vh + vb) / 3
If (rata < 128) Then
vm = 0
vh = 0
vb = 0
Else
vm = 255
vh = 255
vb = 255
End If
.SetPixel(pc, pb, Color.FromArgb(vm, vh, vb))
Next
picture2.Image = gambar
picture2.Refresh()
Next
End With
End Sub
Private Sub OpenCitraToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenCitraToolStripMenuItem.Click
OFD.Filter = "File BMP|*.bmp|File JPG|*.jpg"
OFD.FileName = ""
If OFD.ShowDialog = Windows.Forms.DialogResult.OK Then
picture1.Image = Image.FromFile(OFD.FileName)
picture2.Image = Image.FromFile(OFD.FileName)
gambar = New Bitmap(picture1.Image)
End If
ButtonX1.Visible = False
End Sub
Private Sub SaveCitraToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveCitraToolStripMenuItem.Click
SFD.Filter = "File JPG|*.Jpg|File BMP|*.bm"
SFD.ShowDialog()
If SFD.FileName = "" Then Exit Sub
If SFD.FilterIndex = 1 Then
gambar.Save(SFD.FileName, System.Drawing.Imaging.ImageFormat.Jpeg)
End If
If SFD.FilterIndex = 2 Then
gambar.Save(SFD.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
End If
End Sub
Private Sub KeluarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KeluarToolStripMenuItem.Click
End
End Sub
Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem2.Click
If gambar IsNot Nothing Then
gambar.RotateFlip(RotateFlipType.Rotate90FlipXY)
picture2.Image = gambar
End If
End Sub
Private Sub ToolStripMenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem3.Click
If gambar IsNot Nothing Then
gambar.RotateFlip(RotateFlipType.Rotate180FlipX)
picture2.Image = gambar
End If
End Sub
Private Sub ToolStripMenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem4.Click
If gambar IsNot Nothing Then
gambar.RotateFlip(RotateFlipType.Rotate270FlipNone)
picture2.Image = gambar
End If
End Sub
Private Sub SmootingToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If gambar IsNot Nothing Then
Exit Sub
End If
Dim MF(2, 2) As Double
'MaskFilter.Show()
'matriks Filter
' 0 1 2
'0 a b c
'1 d e f
'2 g h i
'Filter smoothing
MF(0, 0) = 1 / 9 'a
MF(0, 1) = 1 / 9 'b
MF(0, 2) = 1 / 9 'c
MF(1, 0) = 1 / 9 'd
MF(1, 1) = 1 / 9 'e
MF(1, 2) = 1 / 9 'f
MF(2, 0) = 1 / 9 'g
MF(2, 1) = 1 / 9 'h
MF(2, 2) = 1 / 9 'i
gambar = New Bitmap(picture2.Image)
picture2.Image = gambar
Dim tempbmp As New Bitmap(picture2.Image)
Dim DX As Integer = 1
Dim DY As Integer = 1
Dim Red As Integer, Green As Integer, Blue As Integer
With gambar
For i = DX To .Height - DX - 1
For j = DY To .Width - DY - 1
'proses matriks filter
'point(j,i)*e --> titik tengah
Red = CInt(.GetPixel(j, i).R) * MF(1, 1)
Green = CInt(.GetPixel(j, i).G) * MF(1, 1)
Blue = CInt(.GetPixel(j, i).B) * MF(1, 1)
'proses titik tetangga
'point(j-1,i-1)*a--> MF(0,0)--> titik kiri atas
If j - 1 < 1 And i - 1 < 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(0, 0))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(0, 0))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(0, 0))
Else
Red = Red + (CInt(.GetPixel(j - 1, i - 1).R) * MF(0, 0))
Green = Green + (CInt(.GetPixel(j - 1, i - 1).G) * MF(0, 0))
Blue = Blue + (CInt(.GetPixel(j - 1, i - 1).B) * MF(0, 0))
End If
'point(j,i-1)*b --> MF(0,1) --> titik atas
If i - 1 < 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(0, 1))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(0, 1))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(0, 1))
Else
Red = Red + (CInt(.GetPixel(j, i - 1).R) * MF(0, 1))
Green = Green + (CInt(.GetPixel(j, i - 1).G) * MF(0, 1))
Blue = Blue + (CInt(.GetPixel(j, i - 1).B) * MF(0, 1))
End If
'point(j+1,i-1)*c --> MF(0,2) --> titik kanan atas
If j + 1 > .Width - DY - 1 And i - 1 > 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(0, 2))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(0, 2))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(0, 2))
Else
Red = Red + (CInt(.GetPixel(j + 1, i - 1).R) * MF(0, 2))
Green = Green + (CInt(.GetPixel(j + 1, i - 1).G) * MF(0, 2))
Blue = Blue + (CInt(.GetPixel(j + 1, i - 1).B) * MF(0, 2))
End If
'point(j-1,i)*d --> MF(1,0) --> titik kiri
If j - 1 < 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(1, 0))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(1, 0))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(1, 0))
Else
Red = Red + (CInt(.GetPixel(j - 1, i).R) * MF(1, 0))
Green = Green + (CInt(.GetPixel(j - 1, i).G) * MF(1, 0))
Blue = Blue + (CInt(.GetPixel(j - 1, i).B) * MF(1, 0))
End If
'point(j+1,i)*f --> MF(1,2) --> titik kanan
If j + 1 > .Width - DY - 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(1, 2))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(1, 2))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(1, 2))
Else
Red = Red + (CInt(.GetPixel(j + 1, i).R) * MF(1, 2))
Green = Green + (CInt(.GetPixel(j + 1, i).G) * MF(1, 2))
Blue = Blue + (CInt(.GetPixel(j + 1, i).B) * MF(1, 2))
End If
'point(j-1,i+1)*g --> MF(2,0) --> titik kiri bawah
If j - 1 < 1 And i + 1 > .Height - DX - 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(2, 0))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(2, 0))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(2, 0))
Else
Red = Red + (CInt(.GetPixel(j - 1, i + 1).R) * MF(2, 0))
Green = Green + (CInt(.GetPixel(j - 1, i + 1).G) * MF(2, 0))
Blue = Blue + (CInt(.GetPixel(j - 1, i + 1).B) * MF(2, 0))
End If
'point(j,i+1)*g --> MF(2,1) --> titik bawah
If i + 1 > .Height - DX - 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(2, 1))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(2, 1))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(2, 1))
Else
Red = Red + (CInt(.GetPixel(j, i + 1).R) * MF(2, 1))
Green = Green + (CInt(.GetPixel(j, i + 1).G) * MF(2, 1))
Blue = Blue + (CInt(.GetPixel(j, i + 1).B) * MF(2, 1))
End If
'point(j+1,i+1)*h --> MF(2,2) --> titik kanan bawah
If j + 1 > .Width - DY - 1 And i + 1 > .Height - DX - 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(2, 2))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(2, 2))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(2, 2))
Else
Red = Red + (CInt(.GetPixel(j + 1, i + 1).R) * MF(2, 2))
Green = Green + (CInt(.GetPixel(j + 1, i + 1).G) * MF(2, 2))
Blue = Blue + (CInt(.GetPixel(j + 1, i + 1).B) * MF(2, 2))
End If
'normalisasi
If Red < 0 Then
Red = 0
Else
If Red > 255 Then
Red = 255
End If
End If
If Green < 0 Then
Green = 0
Else
If Green > 255 Then
Green = 255
End If
End If
If Blue < 0 Then
Blue = 0
Else
If Blue > 255 Then
Blue = 255
End If
End If
'simpan warna hasil smoothing ke point j,i
gambar.SetPixel(j, i, Color.FromArgb(Red, Green, Blue))
Next
If i Mod 10 = 0 Then
picture2.Invalidate()
Me.Text = Int(100 * i / (picture2.Image.Height - 2)).ToString & "%"
picture2.Refresh()
End If
Next
End With
picture2.Refresh()
Me.Text = "Proses Smoothing Image berhasil"
End Sub
Private Sub ContrastToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContrastToolStripMenuItem.Click
If picture2.Image Is Nothing Then
MsgBox("WARNING : Tidak ada gambar untuk di konversi!")
Exit Sub
End If
gambar = New Bitmap(picture2.Image)
picture2.Image = gambar
Dim tempbmp As New Bitmap(picture2.Image)
Dim pb As Integer = 1
Dim pc As Integer = 1
Dim Red, Green, Blue As Integer
Dim X, Y As Integer
Dim r As Integer
r = 5
With tempbmp
For X = pb To .Height - pb - 1
For Y = pc To .Width - pc - 1
Red = CInt(.GetPixel(Y, X).R)
Green = CInt(.GetPixel(Y, X).G)
Blue = CInt(.GetPixel(Y, X).B)
'Grey = (Red + Green + Blue) / 3 'konversi warna pada pixel Y,X ke grey
Red = Red * r
Blue = Blue * r
Green = Green * r
If (Red > 255) Then
Red = 255
End If
If (Blue > 255) Then
Blue = 255
End If
If (Green > 255) Then
Green = 255
End If
gambar.SetPixel(Y, X, Color.FromArgb(Red, Green, Blue))
Next
If X Mod 10 = 0 Then
picture2.Invalidate()
picture2.Refresh()
End If
Next
End With
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MenuStrip1.BackColor = Color.SkyBlue
picture2.Image = picture1.Image
gambar = picture2.Image
ButtonX1.Visible = False
End Sub
Private Sub RedToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RedToolStripMenuItem.Click
If picture2.Image Is Nothing Then
MsgBox("WARNING : Tidak ada gambar untuk di konversi!")
Exit Sub
End If
Dim Pb, Pc As Integer
Dim rata, vM, vH, vB As Double
With gambar
For Pb = 0 To .Height - 1
For Pc = 0 To .Width - 1
vM = .GetPixel(Pc, Pb).R + 100
vH = .GetPixel(Pc, Pb).G + 60
vB = .GetPixel(Pc, Pb).B + 60
rata = (vM + vH + vB) / 3
If (rata >= 255) Then
vH = 0
vM = 255
vB = 0
Else
vM = 0
vH = 0
vB = 0
End If
.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
picture2.Image = gambar
picture2.Refresh()
Next
End With
gambar = gambar
End Sub
Private Sub GreenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GreenToolStripMenuItem.Click
If picture2.Image Is Nothing Then
MsgBox("WARNING : Tidak ada gambar untuk di konversi!")
Exit Sub
End If
Dim Pb, Pc As Integer
Dim rata, vM, vH, vB As Double
With gambar
For Pb = 0 To .Height - 1
For Pc = 0 To .Width - 1
vM = .GetPixel(Pc, Pb).R + 60
vH = .GetPixel(Pc, Pb).G + 100
vB = .GetPixel(Pc, Pb).B + 60
rata = (vM + vH + vB) / 3
If (rata >= 255) Then
vH = 255
vM = 0
vB = 0
Else
vM = 0
vH = 0
vB = 0
End If
.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
picture2.Image = gambar
picture2.Refresh()
Next
End With
gambar = gambar
End Sub
Private Sub BlueToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BlueToolStripMenuItem.Click
If picture2.Image Is Nothing Then
MsgBox("WARNING : Tidak ada gambar untuk di konversi!")
Exit Sub
End If
Dim Pb, Pc As Integer
Dim rata, vM, vH, vB As Double
With gambar
For Pb = 0 To .Height - 1
For Pc = 0 To .Width - 1
vM = .GetPixel(Pc, Pb).R + 60
vH = .GetPixel(Pc, Pb).G + 60
vB = .GetPixel(Pc, Pb).B + 100
rata = (vM + vH + vB) / 3
If (rata >= 255) Then
vH = 0
vM = 0
vB = 255
Else
vM = 0
vH = 0
vB = 0
End If
.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
picture2.Image = gambar
picture2.Refresh()
Next
End With
gambar = gambar
End Sub
Private Sub MirorrToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MirorrToolStripMenuItem.Click
Dim gambar3 = New Bitmap(picture2.Image)
gambar3 = New Bitmap(picture2.Image)
picture2.Image = gambar3
gambar3.RotateFlip(RotateFlipType.RotateNoneFlipX)
picture2.Image = gambar3
End Sub
Private Sub PanbahanRGBToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PanbahanRGBToolStripMenuItem.Click
Dim tL As Object
tL = InputBox("Masukan Nilai C : ", "Transformasi Logaritmik", "0")
If tL <> "" Then
gambar = New Bitmap(picture2.Image) 'Gambar asli dijadikan gambar Bitmap
picture2.Image = gambar
Dim tempbmp As New Bitmap(picture2.Image) 'deklarasi gambar Bitmap dari gambar asli untuk diproses
Dim DX As Integer = 1
Dim DY As Integer = 1
Dim c, Red As Integer, Green As Integer, Blue As Integer, Grey As Integer
Dim X, Y As Integer
c = CDbl(tL)
With tempbmp
For X = DX To .Height - DX - 1
For Y = DY To .Width - DY - 1
Red = c * Math.Log(CInt(.GetPixel(Y, X).R) + 1) 'ambil nilai warna merah (Red) pada pixel(Y,X)
Green = c * Math.Log(CInt(.GetPixel(Y, X).G) + 1) 'ambil nilai warna hijau (Green) pada pixel(Y,X)
Blue = c * Math.Log(CInt(.GetPixel(Y, X).B) + 1) 'ambil nilai warna biru (Blue) pada pixel(Y,X)
If (Red > 255) Then
Red = 255
Else
If Red < 0 Then
Red = 0
End If
End If
If Green > 255 Then
Green = 255
Else
If Green < 0 Then
Green = 0
End If
End If
If Blue > 255 Then
Blue = 255
Else
If Blue < 0 Then
Blue = 0
End If
End If
gambar.SetPixel(Y, X, Color.FromArgb(Red, Green, Blue)) 'simpan warna baru pada pixel(Y,X)
Next
If X Mod 10 = 0 Then
picture2.Invalidate()
picture2.Refresh()
End If
Next
End With
picture2.Refresh()
Me.Text = "Pengolahan Citra : Proses Transformasi Logaritmik berhasil"
End If
End Sub
Private Sub WeightSmothingToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WeightSmothingToolStripMenuItem.Click
Dim MF(2, 2) As Double
'MaskFilter.Show()
'matriks Filter
' 0 1 2
'0 a b c
'1 d e f
'2 g h i
'Filter smoothing
MF(0, 0) = 1 / 16 'a
MF(0, 1) = 2 / 16 'b
MF(0, 2) = 1 / 16 'c
MF(1, 0) = 2 / 16 'd
MF(1, 1) = 4 / 16 'e
MF(1, 2) = 2 / 16 'f
MF(2, 0) = 1 / 16 'g
MF(2, 1) = 2 / 16 'h
MF(2, 2) = 1 / 16 'i
gambar = New Bitmap(picture2.Image)
picture2.Image = gambar
Dim tempbmp As New Bitmap(picture2.Image)
Dim DX As Integer = 1
Dim DY As Integer = 1
Dim Red As Integer, Green As Integer, Blue As Integer
Dim i As Integer, j As Integer
Dim k As Integer, l As Integer 'untuk mask border
With gambar
For i = DX To .Height - DX - 1
For j = DY To .Width - DY - 1
'proses matriks filter
'point(j,i)*e --> titik tengah
Red = CInt(.GetPixel(j, i).R) * MF(1, 1)
Green = CInt(.GetPixel(j, i).G) * MF(1, 1)
Blue = CInt(.GetPixel(j, i).B) * MF(1, 1)
'proses titik tetangga
'point(j-1,i-1)*a--> MF(0,0)--> titik kiri atas
If j - 1 < 1 And i - 1 < 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(0, 0))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(0, 0))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(0, 0))
Else
Red = Red + (CInt(.GetPixel(j - 1, i - 1).R) * MF(0, 0))
Green = Green + (CInt(.GetPixel(j - 1, i - 1).G) * MF(0, 0))
Blue = Blue + (CInt(.GetPixel(j - 1, i - 1).B) * MF(0, 0))
End If
'point(j,i-1)*b --> MF(0,1) --> titik atas
If i - 1 < 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(0, 1))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(0, 1))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(0, 1))
Else
Red = Red + (CInt(.GetPixel(j, i - 1).R) * MF(0, 1))
Green = Green + (CInt(.GetPixel(j, i - 1).G) * MF(0, 1))
Blue = Blue + (CInt(.GetPixel(j, i - 1).B) * MF(0, 1))
End If
'point(j+1,i-1)*c --> MF(0,2) --> titik kanan atas
If j + 1 > .Width - DY - 1 And i - 1 > 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(0, 2))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(0, 2))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(0, 2))
Else
Red = Red + (CInt(.GetPixel(j + 1, i - 1).R) * MF(0, 2))
Green = Green + (CInt(.GetPixel(j + 1, i - 1).G) * MF(0, 2))
Blue = Blue + (CInt(.GetPixel(j + 1, i - 1).B) * MF(0, 2))
End If
'point(j-1,i)*d --> MF(1,0) --> titik kiri
If j - 1 < 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(1, 0))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(1, 0))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(1, 0))
Else
Red = Red + (CInt(.GetPixel(j - 1, i).R) * MF(1, 0))
Green = Green + (CInt(.GetPixel(j - 1, i).G) * MF(1, 0))
Blue = Blue + (CInt(.GetPixel(j - 1, i).B) * MF(1, 0))
End If
'point(j+1,i)*f --> MF(1,2) --> titik kanan
If j + 1 > .Width - DY - 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(1, 2))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(1, 2))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(1, 2))
Else
Red = Red + (CInt(.GetPixel(j + 1, i).R) * MF(1, 2))
Green = Green + (CInt(.GetPixel(j + 1, i).G) * MF(1, 2))
Blue = Blue + (CInt(.GetPixel(j + 1, i).B) * MF(1, 2))
End If
'point(j-1,i+1)*g --> MF(2,0) --> titik kiri bawah
If j - 1 < 1 And i + 1 > .Height - DX - 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(2, 0))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(2, 0))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(2, 0))
Else
Red = Red + (CInt(.GetPixel(j - 1, i + 1).R) * MF(2, 0))
Green = Green + (CInt(.GetPixel(j - 1, i + 1).G) * MF(2, 0))
Blue = Blue + (CInt(.GetPixel(j - 1, i + 1).B) * MF(2, 0))
End If
'point(j,i+1)*g --> MF(2,1) --> titik bawah
If i + 1 > .Height - DX - 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(2, 1))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(2, 1))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(2, 1))
Else
Red = Red + (CInt(.GetPixel(j, i + 1).R) * MF(2, 1))
Green = Green + (CInt(.GetPixel(j, i + 1).G) * MF(2, 1))
Blue = Blue + (CInt(.GetPixel(j, i + 1).B) * MF(2, 1))
End If
'point(j+1,i+1)*h --> MF(2,2) --> titik kanan bawah
If j + 1 > .Width - DY - 1 And i + 1 > .Height - DX - 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(2, 2))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(2, 2))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(2, 2))
Else
Red = Red + (CInt(.GetPixel(j + 1, i + 1).R) * MF(2, 2))
Green = Green + (CInt(.GetPixel(j + 1, i + 1).G) * MF(2, 2))
Blue = Blue + (CInt(.GetPixel(j + 1, i + 1).B) * MF(2, 2))
End If
'normalisasi
If Red < 0 Then
Red = 0
Else
If Red > 255 Then
Red = 255
End If
End If
If Green < 0 Then
Green = 0
Else
If Green > 255 Then
Green = 255
End If
End If
If Blue < 0 Then
Blue = 0
Else
If Blue > 255 Then
Blue = 255
End If
End If
'simpan warna hasil smoothing ke point j,i
gambar.SetPixel(j, i, Color.FromArgb(Red, Green, Blue))
Next
If i Mod 10 = 0 Then
picture2.Invalidate()
Me.Text = Int(100 * i / (picture2.Image.Height - 2)).ToString & "%"
picture2.Refresh()
End If
Next
End With
picture2.Refresh()
Me.Text = "Proses Weighted Smoothing Image berhasil"
End Sub
Private Sub SmootingToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SmootingToolStripMenuItem1.Click
Dim MF(2, 2) As Double
'MaskFilter.Show()
'matriks Filter
' 0 1 2
'0 a b c
'1 d e f
'2 g h i
'Filter smoothing
MF(0, 0) = 1 / 13 'a
MF(0, 1) = 2 / 13 'b
MF(0, 2) = 1 / 13 'c
MF(1, 0) = 2 / 13 'd
MF(1, 1) = 4 / 13 'e
MF(1, 2) = 2 / 13 'f
MF(2, 0) = 1 / 13 'g
MF(2, 1) = 2 / 13 'h
MF(2, 2) = 1 / 13 'i
gambar = New Bitmap(picture2.Image)
picture2.Image = gambar
Dim tempbmp As New Bitmap(picture2.Image)
Dim DX As Integer = 1
Dim DY As Integer = 1
Dim Red As Integer, Green As Integer, Blue As Integer
Dim i As Integer, j As Integer
Dim k As Integer, l As Integer 'untuk mask border
With gambar
For i = DX To .Height - DX - 1
For j = DY To .Width - DY - 1
'proses matriks filter
'point(j,i)*e --> titik tengah
Red = CInt(.GetPixel(j, i).R) * MF(1, 1)
Green = CInt(.GetPixel(j, i).G) * MF(1, 1)
Blue = CInt(.GetPixel(j, i).B) * MF(1, 1)
'proses titik tetangga
'point(j-1,i-1)*a--> MF(0,0)--> titik kiri atas
If j - 1 < 1 And i - 1 < 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(0, 0))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(0, 0))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(0, 0))
Else
Red = Red + (CInt(.GetPixel(j - 1, i - 1).R) * MF(0, 0))
Green = Green + (CInt(.GetPixel(j - 1, i - 1).G) * MF(0, 0))
Blue = Blue + (CInt(.GetPixel(j - 1, i - 1).B) * MF(0, 0))
End If
'point(j,i-1)*b --> MF(0,1) --> titik atas
If i - 1 < 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(0, 1))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(0, 1))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(0, 1))
Else
Red = Red + (CInt(.GetPixel(j, i - 1).R) * MF(0, 1))
Green = Green + (CInt(.GetPixel(j, i - 1).G) * MF(0, 1))
Blue = Blue + (CInt(.GetPixel(j, i - 1).B) * MF(0, 1))
End If
'point(j+1,i-1)*c --> MF(0,2) --> titik kanan atas
If j + 1 > .Width - DY - 1 And i - 1 > 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(0, 2))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(0, 2))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(0, 2))
Else
Red = Red + (CInt(.GetPixel(j + 1, i - 1).R) * MF(0, 2))
Green = Green + (CInt(.GetPixel(j + 1, i - 1).G) * MF(0, 2))
Blue = Blue + (CInt(.GetPixel(j + 1, i - 1).B) * MF(0, 2))
End If
'point(j-1,i)*d --> MF(1,0) --> titik kiri
If j - 1 < 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(1, 0))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(1, 0))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(1, 0))
Else
Red = Red + (CInt(.GetPixel(j - 1, i).R) * MF(1, 0))
Green = Green + (CInt(.GetPixel(j - 1, i).G) * MF(1, 0))
Blue = Blue + (CInt(.GetPixel(j - 1, i).B) * MF(1, 0))
End If
'point(j+1,i)*f --> MF(1,2) --> titik kanan
If j + 1 > .Width - DY - 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(1, 2))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(1, 2))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(1, 2))
Else
Red = Red + (CInt(.GetPixel(j + 1, i).R) * MF(1, 2))
Green = Green + (CInt(.GetPixel(j + 1, i).G) * MF(1, 2))
Blue = Blue + (CInt(.GetPixel(j + 1, i).B) * MF(1, 2))
End If
'point(j-1,i+1)*g --> MF(2,0) --> titik kiri bawah
If j - 1 < 1 And i + 1 > .Height - DX - 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(2, 0))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(2, 0))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(2, 0))
Else
Red = Red + (CInt(.GetPixel(j - 1, i + 1).R) * MF(2, 0))
Green = Green + (CInt(.GetPixel(j - 1, i + 1).G) * MF(2, 0))
Blue = Blue + (CInt(.GetPixel(j - 1, i + 1).B) * MF(2, 0))
End If
'point(j,i+1)*g --> MF(2,1) --> titik bawah
If i + 1 > .Height - DX - 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(2, 1))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(2, 1))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(2, 1))
Else
Red = Red + (CInt(.GetPixel(j, i + 1).R) * MF(2, 1))
Green = Green + (CInt(.GetPixel(j, i + 1).G) * MF(2, 1))
Blue = Blue + (CInt(.GetPixel(j, i + 1).B) * MF(2, 1))
End If
'point(j+1,i+1)*h --> MF(2,2) --> titik kanan bawah
If j + 1 > .Width - DY - 1 And i + 1 > .Height - DX - 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(2, 2))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(2, 2))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(2, 2))
Else
Red = Red + (CInt(.GetPixel(j + 1, i + 1).R) * MF(2, 2))
Green = Green + (CInt(.GetPixel(j + 1, i + 1).G) * MF(2, 2))
Blue = Blue + (CInt(.GetPixel(j + 1, i + 1).B) * MF(2, 2))
End If
'normalisasi
If Red < 0 Then
Red = 0
Else
If Red > 255 Then
Red = 255
End If
End If
If Green < 0 Then
Green = 0
Else
If Green > 255 Then
Green = 255
End If
End If
If Blue < 0 Then
Blue = 0
Else
If Blue > 255 Then
Blue = 255
End If
End If
'simpan warna hasil smoothing ke point j,i
gambar.SetPixel(j, i, Color.FromArgb(Red, Green, Blue))
Next
If i Mod 10 = 0 Then
picture2.Invalidate()
Me.Text = Int(100 * i / (picture2.Image.Height - 2)).ToString & "%"
picture2.Refresh()
End If
Next
End With
picture2.Refresh()
Me.Text = "Proses Smoothing Image berhasil"
End Sub
Private Sub LowPassToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LowPassToolStripMenuItem.Click
Dim MF(2, 2) As Double
'MaskFilter.Show()
'matriks Filter
' 0 1 2
'0 a b c
'1 d e f
'2 g h i
'Filter smoothing
MF(0, 0) = 0 'a
MF(0, 1) = -1 'b
MF(0, 2) = 0 'c
MF(1, 0) = -1 'd
MF(1, 1) = 4 'e
MF(1, 2) = -1 'f
MF(2, 0) = 0 'g
MF(2, 1) = -1 'h
MF(2, 2) = 0 'i
gambar = New Bitmap(picture2.Image)
picture2.Image = gambar
Dim tempbmp As New Bitmap(picture2.Image)
Dim DX As Integer = 1
Dim DY As Integer = 1
Dim Red As Integer, Green As Integer, Blue As Integer
Dim i As Integer, j As Integer
Dim k As Integer, l As Integer 'untuk mask border
With gambar
For i = DX To .Height - DX - 1
For j = DY To .Width - DY - 1
'proses matriks filter
'point(j,i)*e --> titik tengah
Red = CInt(.GetPixel(j, i).R) * MF(1, 1)
Green = CInt(.GetPixel(j, i).G) * MF(1, 1)
Blue = CInt(.GetPixel(j, i).B) * MF(1, 1)
'proses titik tetangga
'point(j-1,i-1)*a--> MF(0,0)--> titik kiri atas
If j - 1 < 1 And i - 1 < 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(0, 0))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(0, 0))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(0, 0))
Else
Red = Red + (CInt(.GetPixel(j - 1, i - 1).R) * MF(0, 0))
Green = Green + (CInt(.GetPixel(j - 1, i - 1).G) * MF(0, 0))
Blue = Blue + (CInt(.GetPixel(j - 1, i - 1).B) * MF(0, 0))
End If
'point(j,i-1)*b --> MF(0,1) --> titik atas
If i - 1 < 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(0, 1))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(0, 1))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(0, 1))
Else
Red = Red + (CInt(.GetPixel(j, i - 1).R) * MF(0, 1))
Green = Green + (CInt(.GetPixel(j, i - 1).G) * MF(0, 1))
Blue = Blue + (CInt(.GetPixel(j, i - 1).B) * MF(0, 1))
End If
'point(j+1,i-1)*c --> MF(0,2) --> titik kanan atas
If j + 1 > .Width - DY - 1 And i - 1 > 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(0, 2))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(0, 2))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(0, 2))
Else
Red = Red + (CInt(.GetPixel(j + 1, i - 1).R) * MF(0, 2))
Green = Green + (CInt(.GetPixel(j + 1, i - 1).G) * MF(0, 2))
Blue = Blue + (CInt(.GetPixel(j + 1, i - 1).B) * MF(0, 2))
End If
'point(j-1,i)*d --> MF(1,0) --> titik kiri
If j - 1 < 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(1, 0))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(1, 0))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(1, 0))
Else
Red = Red + (CInt(.GetPixel(j - 1, i).R) * MF(1, 0))
Green = Green + (CInt(.GetPixel(j - 1, i).G) * MF(1, 0))
Blue = Blue + (CInt(.GetPixel(j - 1, i).B) * MF(1, 0))
End If
'point(j+1,i)*f --> MF(1,2) --> titik kanan
If j + 1 > .Width - DY - 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(1, 2))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(1, 2))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(1, 2))
Else
Red = Red + (CInt(.GetPixel(j + 1, i).R) * MF(1, 2))
Green = Green + (CInt(.GetPixel(j + 1, i).G) * MF(1, 2))
Blue = Blue + (CInt(.GetPixel(j + 1, i).B) * MF(1, 2))
End If
'point(j-1,i+1)*g --> MF(2,0) --> titik kiri bawah
If j - 1 < 1 And i + 1 > .Height - DX - 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(2, 0))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(2, 0))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(2, 0))
Else
Red = Red + (CInt(.GetPixel(j - 1, i + 1).R) * MF(2, 0))
Green = Green + (CInt(.GetPixel(j - 1, i + 1).G) * MF(2, 0))
Blue = Blue + (CInt(.GetPixel(j - 1, i + 1).B) * MF(2, 0))
End If
'point(j,i+1)*g --> MF(2,1) --> titik bawah
If i + 1 > .Height - DX - 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(2, 1))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(2, 1))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(2, 1))
Else
Red = Red + (CInt(.GetPixel(j, i + 1).R) * MF(2, 1))
Green = Green + (CInt(.GetPixel(j, i + 1).G) * MF(2, 1))
Blue = Blue + (CInt(.GetPixel(j, i + 1).B) * MF(2, 1))
End If
'point(j+1,i+1)*h --> MF(2,2) --> titik kanan bawah
If j + 1 > .Width - DY - 1 And i + 1 > .Height - DX - 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(2, 2))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(2, 2))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(2, 2))
Else
Red = Red + (CInt(.GetPixel(j + 1, i + 1).R) * MF(2, 2))
Green = Green + (CInt(.GetPixel(j + 1, i + 1).G) * MF(2, 2))
Blue = Blue + (CInt(.GetPixel(j + 1, i + 1).B) * MF(2, 2))
End If
'normalisasi
If Red < 0 Then
Red = 0
Else
If Red > 255 Then
Red = 255
End If
End If
If Green < 0 Then
Green = 0
Else
If Green > 255 Then
Green = 255
End If
End If
If Blue < 0 Then
Blue = 0
Else
If Blue > 255 Then
Blue = 255
End If
End If
'simpan warna hasil smoothing ke point j,i
gambar.SetPixel(j, i, Color.FromArgb(Red, Green, Blue))
Next
If i Mod 10 = 0 Then
picture2.Invalidate()
Me.Text = Int(100 * i / (picture2.Image.Height - 2)).ToString & "%"
picture2.Refresh()
End If
Next
End With
picture2.Refresh()
Me.Text = "Proses Low Pass Image berhasil"
End Sub
Private Sub HightPassToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HightPassToolStripMenuItem.Click
Dim MF(2, 2) As Double
'MaskFilter.Show()
'matriks Filter
' 0 1 2
'0 a b c
'1 d e f
'2 g h i
'Filter smoothing
MF(0, 0) = -1 'a
MF(0, 1) = -1 'b
MF(0, 2) = -1 'c
MF(1, 0) = -1 'd
MF(1, 1) = 8 'e
MF(1, 2) = -1 'f
MF(2, 0) = -1 'g
MF(2, 1) = -1 'h
MF(2, 2) = -1 'i
gambar = New Bitmap(picture2.Image)
picture2.Image = gambar
Dim tempbmp As New Bitmap(picture2.Image)
Dim DX As Integer = 1
Dim DY As Integer = 1
Dim Red As Integer, Green As Integer, Blue As Integer
Dim i As Integer, j As Integer
Dim k As Integer, l As Integer 'untuk mask border
With gambar
For i = DX To .Height - DX - 1
For j = DY To .Width - DY - 1
'proses matriks filter
'point(j,i)*e --> titik tengah
Red = CInt(.GetPixel(j, i).R) * MF(1, 1)
Green = CInt(.GetPixel(j, i).G) * MF(1, 1)
Blue = CInt(.GetPixel(j, i).B) * MF(1, 1)
'proses titik tetangga
'point(j-1,i-1)*a--> MF(0,0)--> titik kiri atas
If j - 1 < 1 And i - 1 < 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(0, 0))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(0, 0))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(0, 0))
Else
Red = Red + (CInt(.GetPixel(j - 1, i - 1).R) * MF(0, 0))
Green = Green + (CInt(.GetPixel(j - 1, i - 1).G) * MF(0, 0))
Blue = Blue + (CInt(.GetPixel(j - 1, i - 1).B) * MF(0, 0))
End If
'point(j,i-1)*b --> MF(0,1) --> titik atas
If i - 1 < 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(0, 1))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(0, 1))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(0, 1))
Else
Red = Red + (CInt(.GetPixel(j, i - 1).R) * MF(0, 1))
Green = Green + (CInt(.GetPixel(j, i - 1).G) * MF(0, 1))
Blue = Blue + (CInt(.GetPixel(j, i - 1).B) * MF(0, 1))
End If
'point(j+1,i-1)*c --> MF(0,2) --> titik kanan atas
If j + 1 > .Width - DY - 1 And i - 1 > 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(0, 2))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(0, 2))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(0, 2))
Else
Red = Red + (CInt(.GetPixel(j + 1, i - 1).R) * MF(0, 2))
Green = Green + (CInt(.GetPixel(j + 1, i - 1).G) * MF(0, 2))
Blue = Blue + (CInt(.GetPixel(j + 1, i - 1).B) * MF(0, 2))
End If
'point(j-1,i)*d --> MF(1,0) --> titik kiri
If j - 1 < 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(1, 0))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(1, 0))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(1, 0))
Else
Red = Red + (CInt(.GetPixel(j - 1, i).R) * MF(1, 0))
Green = Green + (CInt(.GetPixel(j - 1, i).G) * MF(1, 0))
Blue = Blue + (CInt(.GetPixel(j - 1, i).B) * MF(1, 0))
End If
'point(j+1,i)*f --> MF(1,2) --> titik kanan
If j + 1 > .Width - DY - 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(1, 2))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(1, 2))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(1, 2))
Else
Red = Red + (CInt(.GetPixel(j + 1, i).R) * MF(1, 2))
Green = Green + (CInt(.GetPixel(j + 1, i).G) * MF(1, 2))
Blue = Blue + (CInt(.GetPixel(j + 1, i).B) * MF(1, 2))
End If
'point(j-1,i+1)*g --> MF(2,0) --> titik kiri bawah
If j - 1 < 1 And i + 1 > .Height - DX - 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(2, 0))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(2, 0))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(2, 0))
Else
Red = Red + (CInt(.GetPixel(j - 1, i + 1).R) * MF(2, 0))
Green = Green + (CInt(.GetPixel(j - 1, i + 1).G) * MF(2, 0))
Blue = Blue + (CInt(.GetPixel(j - 1, i + 1).B) * MF(2, 0))
End If
'point(j,i+1)*g --> MF(2,1) --> titik bawah
If i + 1 > .Height - DX - 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(2, 1))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(2, 1))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(2, 1))
Else
Red = Red + (CInt(.GetPixel(j, i + 1).R) * MF(2, 1))
Green = Green + (CInt(.GetPixel(j, i + 1).G) * MF(2, 1))
Blue = Blue + (CInt(.GetPixel(j, i + 1).B) * MF(2, 1))
End If
'point(j+1,i+1)*h --> MF(2,2) --> titik kanan bawah
If j + 1 > .Width - DY - 1 And i + 1 > .Height - DX - 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(2, 2))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(2, 2))
Blue = Blue + (CInt(.GetPixel(j, i).B) * MF(2, 2))
Else
Red = Red + (CInt(.GetPixel(j + 1, i + 1).R) * MF(2, 2))
Green = Green + (CInt(.GetPixel(j + 1, i + 1).G) * MF(2, 2))
Blue = Blue + (CInt(.GetPixel(j + 1, i + 1).B) * MF(2, 2))
End If
'normalisasi
If Red < 0 Then
Red = 0
Else
If Red > 255 Then
Red = 255
End If
End If
If Green < 0 Then
Green = 0
Else
If Green > 255 Then
Green = 255
End If
End If
If Blue < 0 Then
Blue = 0
Else
If Blue > 255 Then
Blue = 255
End If
End If
'simpan warna hasil smoothing ke point j,i
gambar.SetPixel(j, i, Color.FromArgb(Red, Green, Blue))
Next
If i Mod 10 = 0 Then
picture2.Invalidate()
Me.Text = Int(100 * i / (picture2.Image.Height - 2)).ToString & "%"
picture2.Refresh()
End If
Next
End With
picture2.Refresh()
Me.Text = "Proses High Pass Image berhasil"
End Sub
Private Sub PenguranganRGBToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PenguranganRGBToolStripMenuItem.Click
Dim inVal As Object
inVal = InputBox("Berapa Bit ? ", "Inversi", "8")
If inVal <> "" Then
gambar = New Bitmap(picture2.Image) 'Gambar asli dijadikan gambar Bitmap
picture2.Image = gambar
Dim tempbmp As New Bitmap(picture2.Image) 'deklarasi gambar Bitmap dari gambar asli untuk diproses
Dim DX As Integer = 1
Dim DY As Integer = 1
Dim mBit, Red As Integer, Green As Integer, Blue As Integer, Grey As Integer
Dim X, Y As Integer
mBit = CInt(inVal)
With tempbmp
For X = DX To .Height - DX - 1
For Y = DY To .Width - DY - 1
Red = CInt((Math.Pow(2, mBit) - 1)) - CInt(.GetPixel(Y, X).R) 'ambil nilai warna merah (Red) pada pixel(Y,X)
Green = CInt((Math.Pow(2, mBit) - 1)) - CInt(.GetPixel(Y, X).G) 'ambil nilai warna hijau (Green) pada pixel(Y,X)
Blue = CInt((Math.Pow(2, mBit) - 1)) - CInt(.GetPixel(Y, X).B) 'ambil nilai warna biru (Blue) pada pixel(Y,X)
If (Red > 255) Then
Red = 255
Else
If Red < 0 Then
Red = 0
End If
End If
If Green > 255 Then
Green = 255
Else
If Green < 0 Then
Green = 0
End If
End If
If Blue > 255 Then
Blue = 255
Else
If Blue < 0 Then
Blue = 0
End If
End If
gambar.SetPixel(Y, X, Color.FromArgb(Red, Green, Blue)) 'simpan warna baru pada pixel(Y,X)
Next
If X Mod 10 = 0 Then
picture2.Invalidate()
picture2.Refresh()
End If
Next
End With
picture2.Refresh()
Me.Text = "Pengolahan Citra : Proses Inversi Scale berhasil"
End If
End Sub
Private Sub FileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileToolStripMenuItem.Click
End Sub
Private Sub CaptureFotoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CaptureFotoToolStripMenuItem.Click
starcam()
ButtonX1.Visible = True
picture2.Image = Nothing
End Sub
Private Sub ButtonX1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX1.Click
'awal listing capture kamera
Dim data As IDataObject
Dim bmap As Image
If ButtonX1.Text = "Ambil Foto" Then
SendMessage(hWnd, WM_CAP_EDIT_COPY, 0, 0)
data = Clipboard.GetDataObject()
If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
bmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Image)
picture1.Image = bmap
picture2.Image = picture1.Image
SendMessage(hWnd, WM_CAP_DRIVER_DISCONNECT, VideoSource, 0)
DestroyWindow(hWnd)
End If
ButtonX1.Text = "Ulang Ke Kamera"
Else
starcam()
ButtonX1.Text = "Ambil Foto"
picture2.Image = Nothing
End If
'akhir capture button
End Sub
End Class
daripada bingung ane juga dah siapin file jadinya yang bisa di download disini...
Selamat Mencoba dan terus kembangkan Script ini....
Salam Hangat dari Hendika :*
0 komentar:
Post a Comment