Terima kasih telah mengunjungi Blog saya...

Selasa, 14 Januari 2014

Pengolahan Citra VB.Net 2008

1. Buka Microsoft Visual Studio 2008
2. Klik => Create: Project
3. Ubah Project name dengan Nama anda


 
Gambar VB

4. Maka setelah itu akan muncul sebuah Form1 pada Project kita
  
Gambar Form 1

5. Kemudian Desain Form tersebut dengan Label, TextBox, ComboBox, dan Button yang dapat kita pilih pada properties Toolbox, yang ada di sebelah kiri Form anda
Gambar Desain Form VB

6. Listing program
Public Class Form1

    Dim gambar2 As Bitmap
    Private Sub Btngray_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btngray.Click
        Dim Pb, Pc As Integer
        Dim Rt, vM, vH, vB As Double
        gambar2 = New Bitmap(Picturebox2.Image)
        For Pb = 0 To gambar2.Height - 1
            For Pc = 0 To gambar2.Width - 1
                vM = gambar2.GetPixel(Pc, Pb).R
                vH = gambar2.GetPixel(Pc, Pb).G
                vB = gambar2.GetPixel(Pc, Pb).B
                Rt = (vM + vH + vB) / 3
                gambar2.SetPixel(Pc, Pb, Color.FromArgb(Rt, Rt, Rt))
            Next
            Picturebox2.Image = gambar2
            Picturebox2.Refresh()
        Next
    End Sub


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Picturebox2.Image = Picturebox1.Image

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Pb, Pc As Integer
        Dim vM, vH, vB As Double
        gambar2 = New Bitmap(Picturebox2.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
            Picturebox2.Image = gambar2
            Picturebox2.Refresh()
        Next
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim Pb, Pc As Integer
        Dim vM, vH, vB As Double
        gambar2 = New Bitmap(Picturebox2.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
            Picturebox2.Image = gambar2
            Picturebox2.Refresh()
        Next
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim Pb, Pc As Integer
        Dim vM, vH, vB As Double
        gambar2 = New Bitmap(Picturebox2.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
            Picturebox2.Image = gambar2
            Picturebox2.Refresh()
        Next
     
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Dim Pb, Pc As Integer
        Dim vM, vH, vB As Double
        gambar2 = New Bitmap(Picturebox2.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
            Picturebox2.Image = gambar2
            Picturebox2.Refresh()
        Next

    End Sub

  
    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        Dim Pb, Pc As Integer
        Dim vM, vH, vB As Double
        gambar2 = New Bitmap(Picturebox2.Image)
        For Pb = 0 To gambar2.Height - 1
            For Pc = 0 To gambar2.Width - 1
                vM = gambar2.GetPixel(Pc, Pb).R + 5
                vH = gambar2.GetPixel(Pc, Pb).G + 5
                vB = gambar2.GetPixel(Pc, Pb).B + 5
                If vM >= 255 Then vM = 255
                If vB >= 255 Then vB = 255
                If vH >= 255 Then vH = 255
                gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
            Next
            Picturebox2.Image = gambar2
            Picturebox2.Refresh()
        Next
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Dim Pb, Pc As Integer
        Dim vM, vH, vB As Double
        gambar2 = New Bitmap(Picturebox1.Image)
        Dim gambar3 As Bitmap = New Bitmap(Picturebox1.Image)
        For Pb = gambar2.Height - 1 To 0 Step -1
            For Pc = gambar2.Width - 1 To 0 Step -1
                vM = gambar2.GetPixel(Pc, Pb).R
                vH = gambar2.GetPixel(Pc, Pb).G
                vB = gambar2.GetPixel(Pc, Pb).B
                gambar3.SetPixel(gambar2.Width - 1 - Pc, gambar2.Height - 1 - Pb, Color.FromArgb(vM, vH, vB))
            Next
            Picturebox2.Image = gambar3
            Picturebox2.Refresh()
        Next
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        Dim Pb, Pc As Integer
        Dim vM, vH, vB As Double
        gambar2 = New Bitmap(Picturebox2.Image)
        For Pb = 0 To gambar2.Height - 1
            For Pc = 0 To gambar2.Width - 1
                vM = gambar2.GetPixel(Pc, Pb).R - 5
                vH = gambar2.GetPixel(Pc, Pb).G - 5
                vB = gambar2.GetPixel(Pc, Pb).B - 5
                If vM <= 0 Then vM = 0
                If vB <= 0 Then vB = 0
                If vH <= 0 Then vH = 0
                gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
            Next
            Picturebox2.Image = gambar2
            Picturebox2.Refresh()
        Next
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        Dim Pb, Pc As Integer
        Dim Rt, vM, vH, vB As Double
        gambar2 = New Bitmap(Picturebox2.Image)
        For Pb = 0 To gambar2.Height - 1
            For Pc = 0 To gambar2.Width - 1
                vM = 255 - gambar2.GetPixel(Pc, Pb).R
                vH = 255 - gambar2.GetPixel(Pc, Pb).G
                vB = 255 - gambar2.GetPixel(Pc, Pb).B
                If vM <= 0 Then vM = 0
                If vB <= 0 Then vB = 0
                If vH <= 0 Then vH = 0
                gambar2.SetPixel(Pc, Pb, Color.FromArgb(Rt, Rt, Rt))
            Next
            Picturebox2.Image = gambar2
            Picturebox2.Refresh()
        Next
    End Sub
End Class

7. setelah selesai, tekan F5 atau Start Debugging untuk menjalankan programnya
Hasilnya :

 Gambar Hasil tampilan

8.    Jika klik brightness, maka warna pada foto akan berubah menjadi terang .

Gambar Brightness

9.  Jika klik +Hijau , maka warna pada foto akan berubah menjadi Hijau .
 
 
Gambar Hijau

10.  Jika klik +Merah , maka warna pada foto akan berubah menjadi Merah .

Gambar Merah

 
11. Jika klik +Greyscale , maka warna pada foto akan berubah menjadi Greyscale .


Gambar Greyscale
12.  Jika klik Rotate , maka warna pada foto akan berputar.


Gambar Rotate

NB: Sekian Pembelajaran Pengolahan Citra nya
            Selamat Mencoba