Sebelum kita memasuki Program pengolahan citra,ada baiknya kita
membahas sedikit tentang apa sich itu pengolahan citra.Berikut sedikit
penjelasannya dari beberapa sumber.
Pengolahan citra adalah salah satu cabang dari ilmu
informatika. Pengolahan citra berkutat pada usaha untuk melakukan transformasi suatu
citra/gambar menjadi citra lain dengan menggunakan teknik tertentu.
Citra adalah
gambar dua dimensi yang dihasilkan dari gambar analog dua dimensi yang kontinu menjadi gambar diskrit melalui proses
sampling.
Gambar analog dibagi menjadi N baris dan M kolom sehingga menjadi
gambar diskrit. Persilangan antara baris dan kolom tertentu disebut
dengan piksel. Contohnya adalah gambar/titik diskrit pada baris n dan
kolom m disebut dengan piksel [n,m].
Dalam program berikut ini terdapat beberapa komponen seperti:
- Grayscale=Citra yang memiliki derajat keabuan dari hitam ke putih
ini disebut citra hitam-putih (greyscale image) atau citra monokrom.
- Citra Biner (Monokrom)=Citra monokrom atau citra hitam putih
merupakan suatu citra suatu kanal dimana citra f (x,y) merupakan fungsi
tingkat keabuan dari hitam keputih.
- Citra Warna (true color)=Setiap piksel pada citra warna mewakili
warna yang merupakan kombinasi tiga warna dasar, yaitu merah, hijau, dan
biru (RGB = Red, Green, Blue). Setiap warna dasar menggunakan
penyimpanan 8 bit = 1 byte (nilai maksimum 255 warna), jadi satu piksel
pada citra warna diwakili oleh 3 byte.
- brightness adalah persepsi yang ditangkap dari sebuah objek yang
memantulkan cahaya.Ok mungkin itu saja penjelasan sedikit mengenai
pengolahan citra.
langsung saja kita masuk kepada program
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 = “Images|*.GIF;*.TIF;*.JPG;*.BMP”
OFD.ShowDialog()
If OFD.FileName = “” Then Exit Sub
Pic1.Image = Image.FromFile(OFD.FileName)
gambar = New Bitmap(Pic1.Image)
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.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 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 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 ManipulasiCitraToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ManipulasiCitraToolStripMenuItem.Click
End Sub
Private Sub MenuStrip1_ItemClicked(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles
MenuStrip1.ItemClicked
End Sub
Private Sub OFD_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OFD.FileOk
End Sub
Private Sub SFD_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SFD.FileOk
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
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 RotateToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub MenuStrip2_ItemClicked(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles
MenuStrip2.ItemClicked
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 ContrastToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ContrastToolStripMenuItem.Click
Dim pb, pc As Integer
Dim vm, rt, VH, VB As Double
With gambar
For pb = 0 To .Height – 1
For pc = 0 To .Width – 1
vm = .GetPixel(pc, pb).R * 10
VH = .GetPixel(pc, pb).G * 10
VB = .GetPixel(pc, pb).B * 10
rt = (vm + VH + VB) / 3
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 SmoothingToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SmoothingToolStripMenuItem.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 / 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(Pic1.Image)
Pic1.Image = gambar
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
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
Pic2.Image = gambar
Pic2.Refresh()
Next
End With
End Sub
Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
End Sub
Private Sub LeftToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
LeftToolStripMenuItem.Click
Rotasi(RotateFlipType.Rotate270FlipNone)
End Sub
Private Sub RigthToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Rigth.Click
Rotasi(RotateFlipType.Rotate90FlipNone)
End Sub
Private Sub RotateToolStripMenuItem_Click_1(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
RotateToolStripMenuItem.Click
End Sub
Private Sub Rotasi(ByVal s As RotateFlipType)
gambar = New Bitmap(Pic1.Image)
gambar.RotateFlip(s)
Pic2.Image = gambar
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 ToolStripMenuItem3_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ToolStripMenuItem3.Click
Rotasi(RotateFlipType.Rotate180FlipNone)
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 Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btngt.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
With gambar
For Pb = 0 To gambar.Height – 1
For Pc = 0 To gambar.Width – 1
vM = gambar.GetPixel(Pc, Pb).R
vH = gambar.GetPixel(Pc, Pb).G + 50
vB = gambar.GetPixel(Pc, Pb).B
If vH >= 255 Then vH = 255
gambar.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar
Pic2.Refresh()
Next
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtngK.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
With gambar
For Pb = 0 To gambar.Height – 1
For Pc = 0 To gambar.Width – 1
vM = gambar.GetPixel(Pc, Pb).R
vH = gambar.GetPixel(Pc, Pb).G – 50
vB = gambar.GetPixel(Pc, Pb).B
If vH >= 255 Then vH = 255
gambar.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar
Pic2.Refresh()
Next
End With
End Sub
Private Sub WeightedSmoothingToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub WeiToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles WeiToolStripMenuItem.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(Pic1.Image)
Pic1.Image = gambar
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
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
Pic2.Image = gambar
Pic2.Refresh()
Next
End With
End Sub
Private Sub Btnrt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnrt.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
With gambar
For Pb = 0 To gambar.Height – 1
For Pc = 0 To gambar.Width – 1
vM = gambar.GetPixel(Pc, Pb).R + 50
vH = gambar.GetPixel(Pc, Pb).G
vB = gambar.GetPixel(Pc, Pb).B
If vM >= 255 Then vM = 255
gambar.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar
Pic2.Refresh()
Next
End With
End Sub
Private Sub Btnbt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnbt.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
With gambar
For Pb = 0 To gambar.Height – 1
For Pc = 0 To gambar.Width – 1
vM = gambar.GetPixel(Pc, Pb).R
vH = gambar.GetPixel(Pc, Pb).G
vB = gambar.GetPixel(Pc, Pb).B + 50
If vB >= 255 Then vB = 255
gambar.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar
Pic2.Refresh()
Next
End With
End Sub
Private Sub Btnrk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnrk.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
With gambar
For Pb = 0 To gambar.Height – 1
For Pc = 0 To gambar.Width – 1
vM = gambar.GetPixel(Pc, Pb).R – 50
vH = gambar.GetPixel(Pc, Pb).G
vB = gambar.GetPixel(Pc, Pb).B
If vM >= 255 Then vM = 255
gambar.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar
Pic2.Refresh()
Next
End With
End Sub
Private Sub Btnbk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnbk.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
With gambar
For Pb = 0 To gambar.Height – 1
For Pc = 0 To gambar.Width – 1
vM = gambar.GetPixel(Pc, Pb).R
vH = gambar.GetPixel(Pc, Pb).G
vB = gambar.GetPixel(Pc, Pb).B – 50
If vB >= 255 Then vB = 255
gambar.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar
Pic2.Refresh()
Next
End With
End Sub
Private Sub ByDegreToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ByDegreToolStripMenuItem.Click
End Sub
End Class
Dan Berikut saya tampilkan hasil dari program tersebut
