Sabtu, 29 Juni 2013

PENGOLAHAN CITRA


                                                                                                                                                NAMA :  SAMLYOT  HUTASOIT
                                                                                                                                                NPM     :  1111155                                                                                                                                            
PENGOLAHAN CITRA
Macam –macam jenis pengolahan citra yaitu:
1.GRAYSCALE
2.NEGATIF
3.BRIGHTNESS
4.BINER
5.ROTATE 90
6.CONTRAST
7.SMOOTHING
8.INVERSI
9.LOGARITMIK
10.WEIGHTED SMOOTING
11.LOW PASS
12.HIGH PASS
13.ROTATE 180
TAMPILAN NYA;







BERIKUT INI LISTING PROGRAM  DAN TAMPILANNYA
Public Class Form1
    Dim gambar As Bitmap
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    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.Image)
    End Sub

    Private Sub SAVECITRAToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SAVECITRAToolStripMenuItem.Click
        SFD.Filter = "BMP|*.bmp|JPG|*.Jpg"
        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 DEFAULTGAMBARToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DEFAULTGAMBARToolStripMenuItem.Click
        gambar = New Bitmap(pic1.Image)
    End Sub

    Private Sub KELUARToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KELUARToolStripMenuItem.Click
        End
    End Sub



1.GRAYSCALE
LISTING PROGRAM;
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





2.NEGATIF
LISTING PROGRAM;
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






3.BRIGHTNESS
LISTING PROGRAM;
Private Sub BRIGHTToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BRIGHTToolStripMenuItem.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





4.BINER
LISTING PROGRAM;
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





5.ROTATE 90
LISTING PROGRAM;

Private Sub ROTATE90ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ROTATE90ToolStripMenuItem.Click
        Dim rgb As Image
        rgb = pic2.Image
        If rgb IsNot Nothing Then rgb.RotateFlip(RotateFlipType.Rotate90FlipXY)
        pic2.Image = rgb

    End Sub



6.CONTRAST
LISTING PROGRAM;

Private Sub CONTRASTToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CONTRASTToolStripMenuItem.Click
        gambar = New Bitmap(pic1.Image)
        pic2.Image = gambar
        Dim tempbmp As New Bitmap(pic1.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

        With tempbmp
            For X = DX To .Height - DX - 1
                For Y = DY To .Width - DY - 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 * 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
                    gambar.SetPixel(Y, X, Color.FromArgb(Red, Green, Blue))
                Next
                If X Mod 10 = 0 Then
                    pic1.Invalidate()
                    pic2.Refresh()
                End If
            Next
        End With

    End Sub





7.SMOOTHING
LISTING PROGRAM;

Private Sub SMOTHINGToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SMOTHINGToolStripMenuItem.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)
        pic2.Image = gambar
        Dim tempbmp As New Bitmap(pic1.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
                    pic1.Invalidate()
                    Me.Text = Int(100 * i / (pic1.Image.Height - 2)).ToString & "%"
                    pic1.Refresh()
                End If
            Next
        End With
        pic1.Refresh()
        Me.Text = "Proses Smoothing Image berhasil"

    End Sub






8.INVERSI
LISTING PROGRAM;

Private Sub INVERSIToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles INVERSIToolStripMenuItem.Click
        Dim inVal As Object

        inVal = InputBox("Berapa Bit ? ", "Inversi", "8")

        If inVal <> "" Then
            gambar = New Bitmap(pic1.Image) 'Gambar asli dijadikan gambar Bitmap
            pic2.Image = gambar
            Dim tempbmp As New Bitmap(pic1.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
                        pic1.Invalidate()
                        pic1.Refresh()
                    End If
                Next
            End With

            pic1.Refresh()
            Me.Text = "Pengolahan Citra : Proses Inversi Scale berhasil"
        End If

    End Sub






9.LOGARITMIK
LISTING PROGRAM;

Private Sub LOGARITMIKToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LOGARITMIKToolStripMenuItem.Click
        Dim tL As Object

        tL = InputBox("Masukan Nilai C : ", "Transformasi Logaritmik", "0")

        If tL <> "" Then
            gambar = New Bitmap(pic1.Image) 'Gambar asli dijadikan gambar Bitmap
            pic2.Image = gambar
            Dim tempbmp As New Bitmap(pic1.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
                        pic1.Invalidate()
                        pic1.Refresh()
                    End If
                Next
            End With
            pic1.Refresh()
            Me.Text = "Pengolahan Citra : Proses Transformasi Logaritmik berhasil"
        End If

    End Sub





10.WEIGHTED SMOOTING
LISTING PROGRAM;

Private Sub WeightedSmoothingToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WEIGHTEDSMOOTHINGToolStripMenuItem.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)
        pic2.Image = gambar
        Dim tempbmp As New Bitmap(pic1.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
                    pic1.Invalidate()
                    Me.Text = Int(100 * i / (pic1.Image.Height - 2)).ToString & "%"
                    pic1.Refresh()
                End If
            Next
        End With
        pic1.Refresh()
        Me.Text = "Proses Weighted Smoothing Image berhasil"
    End Sub





11.LOW PASS
LISTIING PROGRAM;

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(pic1.Image)
        pic2.Image = gambar
        Dim tempbmp As New Bitmap(pic1.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
                    pic1.Invalidate()
                    Me.Text = Int(100 * i / (pic1.Image.Height - 2)).ToString & "%"
                    pic1.Refresh()
                End If
            Next
        End With
        pic1.Refresh()
        Me.Text = "Proses Low Pass Image berhasil"

    End Sub






12.HIGH PASS
LISTING PROGRAM;

Private Sub HIGHPASSToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HIGHPASSToolStripMenuItem.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(pic1.Image)
        pic2.Image = gambar
        Dim tempbmp As New Bitmap(pic1.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
                    pic1.Invalidate()
                    Me.Text = Int(100 * i / (pic1.Image.Height - 2)).ToString & "%"
                    pic1.Refresh()
                End If
            Next
        End With
        pic1.Refresh()
        Me.Text = "Proses High Pass Image berhasil"

    End Sub






13.ROTATE 180
LISTING PROGRAM;

Private Sub ROTATE180ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ROTATE180ToolStripMenuItem.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
    End Sub
End Class









 http://mesran.blogspot.com/2013/05/tugas-si-p1101.html