Robert Edge Detection With VB.net

If picada = False Then

            MsgBox("Pilih dulu gambar yang akan diproses", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Error Proses")
            Exit Sub
        End If
        bmap = New Bitmap(picAwal.Image)
        picAwal.Image = bmap
        Dim tempbmp As New Bitmap(picAwal.Image)
        Dim robert As Int64
        Dim tempRed(0 To 2000, 0 To 2000) As Int64, tempGreen(0 To 2000, 0 To 2000) _
        As Int64, tempBlue(0 To 2000, 0 To 2000) As Int64
        Dim i, j, t1, t2, t3, t4, sx, sy As Integer

        ProgressBar1.Width = picAwal.Width
        ProgressBar1.Show()

        With bmap
            For i = 0 To .Height - 2
                For j = 0 To .Width - 2
                    t1 = CInt((.GetPixel(j, i).R) + CInt(.GetPixel(j, i).G) + CInt(.GetPixel(j, i).B) / 3)
                    t2 = CInt(CInt(.GetPixel(j + 1, i + 1).R) + CInt(.GetPixel(j + 1, i + 1).G) + CInt(.GetPixel(j + 1, i + 1).B) / 3)
                    sx = t1 - t2
                    t3 = CInt(CInt(.GetPixel(j + 1, i).R) + CInt(.GetPixel(j + 1, i).G) + CInt(.GetPixel(j + 1, i).B) / 3)
                    t4 = CInt(CInt(.GetPixel(j, i + 1).R) + CInt(.GetPixel(j, i + 1).G) + CInt(.GetPixel(j, i + 1).B) / 3)
                    sy = t3 - t4
                    tempRed(j, i) = Math.Sqrt(sx * sx + sy * sy)

                Next
            Next

            For i = 0 To .Height - 1
                For j = 0 To .Width - 1
                    robert = tempRed(j, i)
                    'trsholding
                    If robert < 50 Then robert = 0
                    If robert >= 255 Then robert = 255
                    bmap.SetPixel(j, i, Color.FromArgb(robert, robert, robert))
                Next
                If i Mod 10 = 0 Then
                    picAwal.Invalidate()
                    Me.Text = Int(100 * i / (picAwal.Image.Height - 2)).ToString & "%"
                    ProgressBar1.Value = Int(100 * i / (picAwal.Image.Height - 2))
                    picAwal.Refresh()
                End If
            Next
        End With
        ProgressBar1.Hide()
        picAwal.Refresh()
        Me.Text = "Pengolahan Citra : Proses robert selesai"

Komentar

Postingan populer dari blog ini

THRESHOLDING

Hitung Manual Gabor Filter

Keceraha (Brightness)