PENGOLAHAN MANIPULASI CITRA
Tampilan Awal
Public Class Form1
Dim gambar As Bitmap
Private Sub OpenFileToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
OpenFileToolStripMenuItem.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.Image)
End Sub
Private Sub DefaultGambarToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
DefaultGambarToolStripMenuItem.Click
Pic2.Image = Pic1.Image
End Sub
Private Sub SaveFileToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As
System.EventArgs) Handles
SaveFileToolStripMenuItem.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.FilterIndex = 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
pc = 0 To 1
vM = 255 - .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()
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 BrigthnessToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
BrigthnessToolStripMenuItem.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 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
Pic1.Refresh()
Next
End With
End Sub
Private Sub RotateToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
RotateToolStripMenuItem.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 ContrasToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
ContrasToolStripMenuItem.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
Pic1.Width = Pic1.Width
Pic2.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 & "%"
Pic2.Image = gambar2
Pic2.Refresh()
End
If
Next
End With
Pic2.Hide()
Pic2.Refresh()
Me.Text
= "Pengolahan Citra : Proses contrast
berhasil"
End Sub
Private Sub Rotate270ToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
Rotate270ToolStripMenuItem.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
-2
For
pc = .Width - 1 To 0 Step
-2
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 = gambar
Pic2.Refresh()
Next
End With
gambar = gambar3
End Sub
Private Sub HijauToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
HijauToolStripMenuItem.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 HijauKuningToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
HijauKuningToolStripMenuItem.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 MerahTuaToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
MerahTuaToolStripMenuItem.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 MerahToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
MerahToolStripMenuItem.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 BiruToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
BiruToolStripMenuItem.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 Form1_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub
End Class
Tampilan
Negatif
Tampilan
Biner
Tampilan
Rotate
Tampilan
Warna Biru