Kamis, 30 Juni 2011

DETEKSI TEPI MENGGUNAKAN VISUAL BASIC

• Buka terlebih dahulu visual basic Anda masing-masing kemudian buatlah sebuah form yang berisikan tool-tool berikut ini :

• Sehingga tampilan formnya

• Tuliskan source code deklarasi dan prosedur pada menu general

Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long

Dim R As Integer, G As Integer, B As Integer
Dim GradX As Long, GradY As Long, Grad As Long
Dim PixelValue As Long

Sub DecTORGB(ByVal Col As Long, R As Integer, G As Integer, B As Integer)
R = Col Mod 256
G = ((Col - R) Mod 65536) / 256
B = (Col - R - G) / 65536
If R < 0 Then R = 0: If R >= 255 Then R = 255
If G < 0 Then G = 0: If G >= 255 Then G = 255
If B < 0 Then B = 0: If B >= 255 Then B = 255
End Sub

• Berikut ini source code perintah operator Robert yang di tuliskan pada button1
Dim Op_X(-1 To 0, -1 To 0) As Integer, Op_Y(-1 To 0, -1 To 0) As Integer
Dim X As Integer, Y As Integer, I As Integer, J As Integer
Pic2.Cls
Grad = 0
Op_X(-1, -1) = 1: Op_X(0, -1) = 0
Op_X(-1, 0) = 0: Op_X(0, 0) = -1
Op_Y(-1, -1) = 0: Op_Y(0, -1) = -1
Op_Y(-1, 0) = 1: Op_Y(0, 0) = 0

For Y = 0 To Pic1.Height - 1
For X = 0 To Pic1.Width - 1
GradX = 0: GradY = 0: Grad = 0
If X = 0 Or Y = 0 Or X = Pic1.Width - 1 Or Y = Pic1.Height - 1 Then
Grad = 0
Else
For I = -1 To 0
For J = -1 To 0
PixelValue = GetPixel(Pic1.hdc, X + I, Y + J) //dapatkan pixel dari posisi x + i dan y + j
DecTORGB PixelValue, R, G, B //fungsi proses mendapatkan nilai RGB
Itensity = (R + G + B) / 3 //Itensitas / B & W
GradX = GradX + (Itensity * Op_X(I, J))
GradY = GradY + (Itensity * Op_Y(I, J))
Next J
Next I
Grad = Round(Sqr(Abs(GradX * GradX) + Abs(GradY * GradY)))
End If
If Grad <= 0 Then Grad = 0: If Grad >= 255 Then Grad = 255
SetPixel Pic2.hdc, X, Y, RGB(Grad, Grad, Grad)
Pic2.Refresh
Next X
Pic2.Refresh
Next Y

End Sub

• Contoh tampilan hasil deteksi



MASIH DALAM TAHAP PENGEMBANGAN
SEMOGA BERMANFAAT DAN SUKSES SELALU.............
BY : ARIE SUKANDAR
EMAIL : lope_arie@yahoo.co.id
website : www.ariearea89.co.cc

1 komentar:

  1. ini deteksi tepinya menggunakan metodenya robert saja ya? kalau prewitt,sobel atau yg lainnya ada tdk ???

    BalasHapus