Selasa, 03 Januari 2012

Tugas Pengolahan Citra - Deteksi Tepi

Kelompok :

cahaya pangripta alam (50408216)

anas abdurrahman (50408096)

Kelas : 4IA11


Deteksi Tepi


Deteksi tepi merupakan sebuah proses di mana proses tersebut berfungsi untuk

mendeteksi garis tepi yang membatasi dua wilayah citra. Saat ini telah banyak operatoroperator

yang dapat digunakan dalam pembuatan deteksi tepi, contohnya adalah

operator Robert Cross, prewitt, sobel, serta operator turunan seperti laplace. Deteksi tepi

itu sendiri bertujuan untuk menandai bagian yang menjadi detail citra, dan memperbaiki

serta mengubah citra. DIsini Saya akan menjelaskan program untuk deteksi tepi menggunakan metode Sobel..


1. Pertama kita lakukan proses memasukan image

ofdLoadImage.FileName = ""

ofdLoadImage.ShowDialog()

If ofdLoadImage.FileName = "" Then Return


If Not Me.pbBefore.Image Is Nothing Then

Me.pbBefore.Image.Dispose()

End If


Me.pbBefore.Image = Image.FromFile(ofdLoadImage.FileName) 'New Bitmap(ofdLoadImage.FileName)

Catch ex As Exception

MsgBox("Error: " & ex.Message)


2. setelah itu kita Deklarasikan terlebih dahulu matriks sobelnya

Dim xMask(,) As Single = New Single(,) {{-1, 0, 1}, _

{-2, 0, 2}, _

{-1, 0, 1}}


Dim yMask(,) As Single = New Single(,) {{1, 2, 1}, _

{0, 0, 0}, _

{-1, -2, -1}}


3. Setelah itu kita lakukan Proses deteksi tepi

- Disini kita mencari pixel dalam matriks dari image yg kita upload :

For y As Integer = 0 To inImg.Height - 1

For x As Integer = 0 To inImg.Width - 1

Dim gradX As Single = 0

Dim gradY As Single = 0

Dim grad As Single = 0


If x = 0 Or y = 0 Or x = inImg.Width - 1 Or y = inImg.Height - 1 Then

grad = 0

Else


- Disini setelah kita mendapatkan matriks pixel dari image kita lakukan deteksi tepi

For i As Integer = -1 To 1

For j As Integer = -1 To 1

Dim p As Color = inImg.GetPixel(x + i, y + j)

Dim intensity As Single = 0.333F * (CInt(p.R) + p.G + p.B)

'// approximate X gradient

gradX += intensity * xMask(i + 1, j + 1)

'// approximate Y gradient

gradY += intensity * yMask(i + 1, j + 1)

Next

Next

- setelah itu hasil dari matriks x dan y di tambahkan dan di taruh di tengah matriks

grad = (Math.Abs(gradX) + Math.Abs(gradY))

' grad = grad / 100

End If


grad = Math.Max(0, grad)

'// could easily add a threshold here:

'// If grad < 100 Then

'// grad = 0

'// End If


grad = Math.Min(255, grad)


'grad = 255 - grad


out.SetPixel(x, y, Color.FromArgb(CInt(grad), CInt(grad), CInt(grad)))

Next


Me.pbAfter.Image = out

Me.pbAfter.Refresh()

Next


Return out


hasilnya seperti ini :






Sumber : http://visualcore.com , www.gunadarma.ac.id/library/articles/.../Artikel_50405669.pdf

0 comments:

 
Themes by: Free Templates Studio. Powered by Blogger