langsung saja ke pokok masalahnya.sebelumnya silakan buat desain anda seperti gambar berikut
pada menu strip file silahkan masukkan isinya open citra,save citra dan keluar sedangkan pada manipulasi ctra isikan dengan Default gambar,grayscale,brigthness,rotate(90,180,270),Biner,contrast,smoothing dan pada pengaturan RGB isikan dengan +Merah,-Merah,+Hijau,-Hijau,+Biru dan -Biru
silahkan tambakan lagi dengan OpenFileDialog1 ganti name dengan OFD,SaveFileDialog1 dengan name SFD dan tambahkan lagi ProgressBar1.perhatikan gambar dibawah
maka listing programmnya ..
Public Class Form1
Dim gambar As Bitmap
Private Sub OpenCitraToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenCitraToolStripMenuItem.Click
OFD.Filter = "BMP|*.bmp|JPG|*.Jpg"
OFD.ShowDialog()
If OFD.FileName = "" Then Exit Sub
Pic1.Image = Image.FromFile(OFD.FileName)
gambar = New Bitmap(Pic1.Name)
End Sub
Private Sub SaveCitraToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveCitraToolStripMenuItem.Click
SFD.Filter = "JPG|*.Jpg|BMP|*.bmp"
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.Filter = 2 Then
gambar.Save(SFD.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
End If
End Sub
Private Sub GrayscaleToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GrayscaleToolStripMenuItem.Click
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
Pic2.Image = gambar
Pic2.Refresh()
Next
End With
End Sub
Private Sub NegatifToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NegatifToolStripMenuItem.Click
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
Pic2.Image = gambar
Pic2.Refresh()
Next
End With
End Sub
Private Sub KeluarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KeluarToolStripMenuItem.Click
End
End Sub
Private Sub BinerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BinerToolStripMenuItem.Click
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
Pic2.Image = gambar
Pic2.Refresh()
Next
End With
End Sub
Private Sub DefaultGambarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DefaultGambarToolStripMenuItem.Click
gambar = New Bitmap(Pic1.Image)
End Sub
Private Sub BrightnessToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BrightnessToolStripMenuItem.Click
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
Pic2.Image = gambar
Pic2.Refresh()
Next
End With
End Sub
Private Sub HijauTToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HijauTToolStripMenuItem.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
Dim gambar2 = New Bitmap(Pic2.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 + 10
vB = gambar2.GetPixel(Pc, Pb).B
If vH >= 255 Then vH = 255
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar2
Pic2.Refresh()
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Pic2.Image = Pic1.Image
End Sub
Private Sub HijauKToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HijauKToolStripMenuItem1.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
Dim gambar2 = New Bitmap(Pic2.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 - 10
vB = gambar2.GetPixel(Pc, Pb).B
If vH <= 0 Then vH = 0
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar2
Pic2.Refresh()
Next
End Sub
Private Sub MerahTToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MerahTToolStripMenuItem.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
Dim gambar2 = New Bitmap(Pic2.Image)
For Pb = 0 To gambar2.Height - 1
For Pc = 0 To gambar2.Width - 1
vM = gambar2.GetPixel(Pc, Pb).R + 10
vH = gambar2.GetPixel(Pc, Pb).G
vB = gambar2.GetPixel(Pc, Pb).B
If vM >= 255 Then vM = 255
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar2
Pic2.Refresh()
Next
End Sub
Private Sub MerahKToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MerahKToolStripMenuItem1.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
Dim gambar2 = New Bitmap(Pic2.Image)
For Pb = 0 To gambar2.Height - 1
For Pc = 0 To gambar2.Width - 1
vM = gambar2.GetPixel(Pc, Pb).R - 10
vH = gambar2.GetPixel(Pc, Pb).G
vB = gambar2.GetPixel(Pc, Pb).B
If vM <= 0 Then vM = 0
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar2
Pic2.Refresh()
Next
End Sub
Private Sub BiruTToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BiruTToolStripMenuItem.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
Dim gambar2 = New Bitmap(Pic2.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 + 10
If vB >= 255 Then vB = 255
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar2
Pic2.Refresh()
Next
End Sub
Private Sub BiruKToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BiruKToolStripMenuItem1.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
Dim gambar2 = New Bitmap(Pic2.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 - 10
If vB <= 0 Then vB = 0
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar2
Pic2.Refresh()
Next
End Sub
Private Sub ContrastToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContrastToolStripMenuItem.Click
Dim gambar2 = New Bitmap(Pic2.Image)
Pic2.Image = gambar2
Dim tempbmp As New Bitmap(Pic2.Image)
Dim DX As Integer = 1
Dim DY As Integer = 1
Dim Red, Green, Blue As Integer
Dim X, Y As Integer
Dim tc As Integer
tc = 5
ProgressBar1.Width = Pic1.Width
ProgressBar1.Show()
With tempbmp
For X = DX To .Height - DX - 1
For Y = DY To .Width - DY - 1
Red = CInt(.GetPixel(Y, X).R) 'ambil nilai warna merah (Red) pada pixel(Y,X)
Green = CInt(.GetPixel(Y, X).G) 'ambil nilai warna hijau (Green) pada pixel(Y,X)
Blue = CInt(.GetPixel(Y, X).B) 'ambil nilai warna biru (Blue) pada pixel(Y,X)
'Grey = (Red + Green + Blue) / 3 'konversi warna pada pixel Y,X ke grey
Red = Red * tc
Blue = Blue * tc
Green = Green * tc
If (Red > 255) Then
Red = 255
End If
If (Blue > 255) Then
Blue = 255
End If
If (Green > 255) Then
Green = 255
End If
gambar2.SetPixel(Y, X, Color.FromArgb(Red, Green, Blue)) 'simpan warna baru pada pixel(Y,X)
Next
If X Mod 10 = 0 Then
Pic2.Invalidate()
Me.Text = "Progres Proses contrast : " & Int(100 * X / (Pic1.Image.Height - 2)).ToString & "%"
ProgressBar1.Value = Int(100 * X / (Pic1.Image.Height - 2))
Pic2.Refresh()
End If
Next
End With
ProgressBar1.Hide()
Pic2.Refresh()
Me.Text = "Pengolahan Citra : Proses contrast berhasil"
End Sub
Private Sub ToolStripMenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem3.Click
Dim Pb, pc As Integer
Dim vM, vH, vB As Double
Dim gambar3 As Bitmap = New Bitmap(Pic1.Image)
With gambar
For Pb = .Height - 1 To 0 Step -1
For pc = .Width - 1 To 0 Step -1
vM = .GetPixel(pc, Pb).R
vH = .GetPixel(pc, Pb).G
vB = .GetPixel(pc, Pb).B
gambar3.SetPixel(.Width - 1 - pc, .Height - 1 - Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar3
Pic2.Refresh()
Next
End With
gambar = gambar3
End Sub
Private Sub Rotasi(ByVal s As RotateFlipType)
Dim gambar2 = New Bitmap(Pic2.Image)
gambar2 = New Bitmap(Pic2.Image)
Pic2.Image = gambar2
gambar2.RotateFlip(s)
Pic2.Image = gambar2
End Sub
Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem2.Click
Rotasi(RotateFlipType.Rotate90FlipNone)
End Sub
Private Sub ToolStripMenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem4.Click
Rotasi(RotateFlipType.Rotate270FlipNone)
End Sub
Private Sub SmoothingToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SmoothingToolStripMenuItem.Click
Dim gambar2 = New Bitmap(Pic2.Image)
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
gambar2 = New Bitmap(Pic2.Image)
Pic2.Image = gambar2
Dim tempbmp As New Bitmap(Pic2.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
ProgressBar1.Width = Pic1.Width
ProgressBar1.Show()
With gambar2
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
gambar2.SetPixel(j, i, Color.FromArgb(Red, Green, Blue))
Next
If i Mod 10 = 0 Then
Pic1.Invalidate()
Me.Text = Int(100 * i / (Pic1.Image.Height - 2)).ToString & "%"
ProgressBar1.Value = Int(100 * i / (Pic1.Image.Height - 2))
Pic1.Refresh()
End If
Next
End With
ProgressBar1.Hide()
Pic2.Refresh()
Me.Text = "Proses Smoothing Image berhasil"
End Sub
End Class
Dim gambar As Bitmap
Private Sub OpenCitraToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenCitraToolStripMenuItem.Click
OFD.Filter = "BMP|*.bmp|JPG|*.Jpg"
OFD.ShowDialog()
If OFD.FileName = "" Then Exit Sub
Pic1.Image = Image.FromFile(OFD.FileName)
gambar = New Bitmap(Pic1.Name)
End Sub
Private Sub SaveCitraToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveCitraToolStripMenuItem.Click
SFD.Filter = "JPG|*.Jpg|BMP|*.bmp"
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.Filter = 2 Then
gambar.Save(SFD.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
End If
End Sub
Private Sub GrayscaleToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GrayscaleToolStripMenuItem.Click
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
Pic2.Image = gambar
Pic2.Refresh()
Next
End With
End Sub
Private Sub NegatifToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NegatifToolStripMenuItem.Click
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
Pic2.Image = gambar
Pic2.Refresh()
Next
End With
End Sub
Private Sub KeluarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KeluarToolStripMenuItem.Click
End
End Sub
Private Sub BinerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BinerToolStripMenuItem.Click
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
Pic2.Image = gambar
Pic2.Refresh()
Next
End With
End Sub
Private Sub DefaultGambarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DefaultGambarToolStripMenuItem.Click
gambar = New Bitmap(Pic1.Image)
End Sub
Private Sub BrightnessToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BrightnessToolStripMenuItem.Click
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
Pic2.Image = gambar
Pic2.Refresh()
Next
End With
End Sub
Private Sub HijauTToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HijauTToolStripMenuItem.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
Dim gambar2 = New Bitmap(Pic2.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 + 10
vB = gambar2.GetPixel(Pc, Pb).B
If vH >= 255 Then vH = 255
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar2
Pic2.Refresh()
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Pic2.Image = Pic1.Image
End Sub
Private Sub HijauKToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HijauKToolStripMenuItem1.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
Dim gambar2 = New Bitmap(Pic2.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 - 10
vB = gambar2.GetPixel(Pc, Pb).B
If vH <= 0 Then vH = 0
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar2
Pic2.Refresh()
Next
End Sub
Private Sub MerahTToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MerahTToolStripMenuItem.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
Dim gambar2 = New Bitmap(Pic2.Image)
For Pb = 0 To gambar2.Height - 1
For Pc = 0 To gambar2.Width - 1
vM = gambar2.GetPixel(Pc, Pb).R + 10
vH = gambar2.GetPixel(Pc, Pb).G
vB = gambar2.GetPixel(Pc, Pb).B
If vM >= 255 Then vM = 255
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar2
Pic2.Refresh()
Next
End Sub
Private Sub MerahKToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MerahKToolStripMenuItem1.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
Dim gambar2 = New Bitmap(Pic2.Image)
For Pb = 0 To gambar2.Height - 1
For Pc = 0 To gambar2.Width - 1
vM = gambar2.GetPixel(Pc, Pb).R - 10
vH = gambar2.GetPixel(Pc, Pb).G
vB = gambar2.GetPixel(Pc, Pb).B
If vM <= 0 Then vM = 0
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar2
Pic2.Refresh()
Next
End Sub
Private Sub BiruTToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BiruTToolStripMenuItem.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
Dim gambar2 = New Bitmap(Pic2.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 + 10
If vB >= 255 Then vB = 255
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar2
Pic2.Refresh()
Next
End Sub
Private Sub BiruKToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BiruKToolStripMenuItem1.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
Dim gambar2 = New Bitmap(Pic2.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 - 10
If vB <= 0 Then vB = 0
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar2
Pic2.Refresh()
Next
End Sub
Private Sub ContrastToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContrastToolStripMenuItem.Click
Dim gambar2 = New Bitmap(Pic2.Image)
Pic2.Image = gambar2
Dim tempbmp As New Bitmap(Pic2.Image)
Dim DX As Integer = 1
Dim DY As Integer = 1
Dim Red, Green, Blue As Integer
Dim X, Y As Integer
Dim tc As Integer
tc = 5
ProgressBar1.Width = Pic1.Width
ProgressBar1.Show()
With tempbmp
For X = DX To .Height - DX - 1
For Y = DY To .Width - DY - 1
Red = CInt(.GetPixel(Y, X).R) 'ambil nilai warna merah (Red) pada pixel(Y,X)
Green = CInt(.GetPixel(Y, X).G) 'ambil nilai warna hijau (Green) pada pixel(Y,X)
Blue = CInt(.GetPixel(Y, X).B) 'ambil nilai warna biru (Blue) pada pixel(Y,X)
'Grey = (Red + Green + Blue) / 3 'konversi warna pada pixel Y,X ke grey
Red = Red * tc
Blue = Blue * tc
Green = Green * tc
If (Red > 255) Then
Red = 255
End If
If (Blue > 255) Then
Blue = 255
End If
If (Green > 255) Then
Green = 255
End If
gambar2.SetPixel(Y, X, Color.FromArgb(Red, Green, Blue)) 'simpan warna baru pada pixel(Y,X)
Next
If X Mod 10 = 0 Then
Pic2.Invalidate()
Me.Text = "Progres Proses contrast : " & Int(100 * X / (Pic1.Image.Height - 2)).ToString & "%"
ProgressBar1.Value = Int(100 * X / (Pic1.Image.Height - 2))
Pic2.Refresh()
End If
Next
End With
ProgressBar1.Hide()
Pic2.Refresh()
Me.Text = "Pengolahan Citra : Proses contrast berhasil"
End Sub
Private Sub ToolStripMenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem3.Click
Dim Pb, pc As Integer
Dim vM, vH, vB As Double
Dim gambar3 As Bitmap = New Bitmap(Pic1.Image)
With gambar
For Pb = .Height - 1 To 0 Step -1
For pc = .Width - 1 To 0 Step -1
vM = .GetPixel(pc, Pb).R
vH = .GetPixel(pc, Pb).G
vB = .GetPixel(pc, Pb).B
gambar3.SetPixel(.Width - 1 - pc, .Height - 1 - Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar3
Pic2.Refresh()
Next
End With
gambar = gambar3
End Sub
Private Sub Rotasi(ByVal s As RotateFlipType)
Dim gambar2 = New Bitmap(Pic2.Image)
gambar2 = New Bitmap(Pic2.Image)
Pic2.Image = gambar2
gambar2.RotateFlip(s)
Pic2.Image = gambar2
End Sub
Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem2.Click
Rotasi(RotateFlipType.Rotate90FlipNone)
End Sub
Private Sub ToolStripMenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem4.Click
Rotasi(RotateFlipType.Rotate270FlipNone)
End Sub
Private Sub SmoothingToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SmoothingToolStripMenuItem.Click
Dim gambar2 = New Bitmap(Pic2.Image)
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
gambar2 = New Bitmap(Pic2.Image)
Pic2.Image = gambar2
Dim tempbmp As New Bitmap(Pic2.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
ProgressBar1.Width = Pic1.Width
ProgressBar1.Show()
With gambar2
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
gambar2.SetPixel(j, i, Color.FromArgb(Red, Green, Blue))
Next
If i Mod 10 = 0 Then
Pic1.Invalidate()
Me.Text = Int(100 * i / (Pic1.Image.Height - 2)).ToString & "%"
ProgressBar1.Value = Int(100 * i / (Pic1.Image.Height - 2))
Pic1.Refresh()
End If
Next
End With
ProgressBar1.Hide()
Pic2.Refresh()
Me.Text = "Proses Smoothing Image berhasil"
End Sub
End Class
maka jalankanlah program tersebut, ehee jangan lupa pilih gambarnya dulu ya dari komputer anda .






hasil akhirnya gak ada broo
ReplyDelete