Kamis, 21 Februari 2013
Jumat, 01 Juli 2011
APLIKASI PENGOLAHAN CITRA MENGGUNAKAN VB 6.0
DETEKSI TEPI
Properti :

Coding :
Dim Pixel
Dim Pixel2
Dim Rred
Dim Ggreen
Dim Bblue
Dim RR1
Dim GG1
Dim BB1
Dim RR2
Dim GG2
Dim BB2
Dim RR3
Dim GG3
Dim BB3
Dim Temp As Integer
Dim Temp2 As Integer
Dim XXX As Integer
Dim YYY As Integer
Dim XX As Integer
Dim YY As Integer
Dim RR As Integer
Dim RG As Integer
Dim RB As Integer
Dim CurX
Dim CurY
Dim JB As Byte
Sub UppdateScroll()
If Picture1.Width <= PC.ScaleWidth Then
HScroll1.Enabled = False
Else
HScroll1.Enabled = True
End If
If Picture1.Height <= PC.ScaleHeight Then
VScroll1.Enabled = False
Else
VScroll1.Enabled = True
End If
VScroll1.Max = Picture1.ScaleHeight - PC.ScaleHeight
HScroll1.Max = Picture1.ScaleWidth - PC.ScaleWidth
If HScroll1.Enabled = False Then
Picture1.Left = (PC.Width / 2) - (Picture1.Width / 2)
End If
If VScroll1.Enabled = False Then
Picture1.Top = (PC.Height / 2) - (Picture1.Height / 2)
End If
HScroll1.Value = 0
VScroll1.Value = 0
End Sub
Private Sub GetRGB(ByVal Col As String)
On Error Resume Next
Bblue = Col \ (256 ^ 2)
Ggreen = (Col - Bblue * 256 ^ 2) \ 256
Rred = (Col - Bblue * 256 ^ 2 - Ggreen * 256) '\ 256
End Sub
Private Sub Command2_Click()
On Error Resume Next
Q = InputBox("Enter a value for find horizontal edges (higher value = brighter image)", "", "4")
If Q = "" Then Exit Sub
For YYY = 0 To Picture1.ScaleHeight - 1
For XXX = 0 To Picture1.ScaleWidth - 1
Pixel2 = GetPixel(Picture1.HDC, XXX + 2, YYY)
Pixel = GetPixel(Picture1.HDC, XXX + 1, YYY)
GetRGB Pixel
RR1 = Rred
GG1 = Ggreen
BB1 = Bblue
GetRGB Pixel2
RR2 = Rred
GG2 = Ggreen
BB2 = Bblue
If RR1 = RR2 Then RR3 = 0
If RR1 > RR2 Then
RR3 = RR1 - RR2
Else
RR3 = RR2 - RR1
End If
If GG1 = GG2 Then GG3 = 0
If GG1 > GG2 Then
GG3 = GG1 - GG2
Else
GG3 = GG2 - GG1
End If
If BB1 = BB2 Then BB3 = 0
If BB1 > BB2 Then
BB3 = BB1 - BB2
Else
BB3 = BB2 - BB1
End If
SetPixelV Picture1.HDC, XXX, YYY, RGB(RR3 * Q, GG3 * Q, BB3 * Q)
Next
Picture1.Refresh
Next
Picture1.Refresh
End Sub
Private Sub Command3_Click()
On Error Resume Next
Q = InputBox("Enter a value for find vertical edges (higher value = brighter image)", "", "4")
If Q = "" Then Exit Sub
For XXX = 0 To Picture1.ScaleWidth - 1
For YYY = 0 To Picture1.ScaleHeight - 1
Pixel2 = GetPixel(Picture1.HDC, XXX, YYY + 2)
Pixel = GetPixel(Picture1.HDC, XXX, YYY + 1)
GetRGB Pixel
RR1 = Rred
GG1 = Ggreen
BB1 = Bblue
GetRGB Pixel2
RR2 = Rred
GG2 = Ggreen
BB2 = Bblue
If RR1 = RR2 Then RR3 = 0
If RR1 > RR2 Then
RR3 = RR1 - RR2
Else
RR3 = RR2 - RR1
End If
If GG1 = GG2 Then GG3 = 0
If GG1 > GG2 Then
GG3 = GG1 - GG2
Else
GG3 = GG2 - GG1
End If
If BB1 = BB2 Then BB3 = 0
If BB1 > BB2 Then
BB3 = BB1 - BB2
Else
BB3 = BB2 - BB1
End If
SetPixelV Picture1.HDC, XXX, YYY, RGB(RR3 * Q, GG3 * Q, BB3 * Q)
Next
Picture1.Refresh
Next
Picture1.Refresh
End Sub
Private Sub Command1_Click()
CM.CancelError = True
On Error GoTo ja
CM.Filter = "Image|*.bmp;*.gif;*.jpg;*.wmf;*.emf;*.ico;*.cur"
CM.ShowOpen
Picture1.Picture = LoadPicture(CM.FileName)
UppdateScroll
Exit Sub
ja:
Exit Sub
End Sub
Private Sub Form_Load()
UppdateScroll
End Sub
Private Sub HScroll1_Change()
Picture1.Left = 0 - HScroll1.Value
End Sub
Private Sub HScroll1_Scroll()
HScroll1_Change
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
JB = 1
CurX = X
CurY = Y
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error Resume Next
If JB = 1 Then
If HScroll1.Enabled = True Then HScroll1.Value = HScroll1.Value + CurX - X
If VScroll1.Enabled = True Then VScroll1.Value = VScroll1.Value + CurY - Y
End If
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
JB = 0
End Sub
Private Sub VScroll1_Change()
Picture1.Top = 0 - VScroll1.Value
End Sub
Private Sub VScroll1_Scroll()
VScroll1_Change
End Sub
Tampilan saat program dijalankan

Klik tombol Cari Tepi untuk mendeteksi tepi gambar tersebut

Masukkan nilai untuk mengatur pendeteksi tepi,musalkan masukkan angka 4,
Akan menghasilkan pendeteksian tepi pada gambar dibawah ini

Senin, 22 Desember 2008
Langganan:
Komentar (Atom)
