280 likes | 569 Views
Deteksi Tepi. Achmad Basuki Politeknik Elektronika Negeri Surabaya PENS-ITS. Tujuan. Bagaimana mendapatkan garis-garis tepi suatu obyek gambar. Differensial. x(n). 1. n. 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. Menggunakan formulasi h(n)=x(n)-x(n-1) diperoleh:. x(n). n. 0.
E N D
Deteksi Tepi Achmad Basuki Politeknik Elektronika Negeri Surabaya PENS-ITS
Tujuan Bagaimana mendapatkan garis-garis tepi suatu obyek gambar
Differensial x(n) 1 n 0 1 2 3 4 5 6 7 8 9 10 11 Menggunakan formulasi h(n)=x(n)-x(n-1) diperoleh: x(n) n 0 1 2 3 4 5 6 7 8 9 10 11
Differensial Horisontal 1 (-1) (0) + (1) (1) 0 0 1 1 1 0 0 1 0 0 0 0 1 1 1 0 0 1 0 0 Setiap pixel dikurangi dengan nilai pixel sebelah kirinya 0 0 1 1 1 0 0 1 0 0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1
Differensial Vertikal -1 (-1) (1) + (1) (0) 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 Setiap pixel dikurangi dengan nilai pixel sebelah kirinya 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1 0 0 -1 0 0 0 0 0 0 1 0 0 0 -1 0
Kernel Differensial H/W Kernel Differensial Horizontal -1 1 H= Kernel Differensial Vertikal -1 H= 1
Implementasi Label1 Label2 Picture2 Picture1 FORM PROPERTY: (1) BorderStyle = None (2) ScaleMode = Pixel
Implementasi Code Private Sub Form_Load() Dim xg(320, 240) As Integer 'Mengubah ke gray scale For i = 0 To Picture1.ScaleWidth - 1 For j = 0 To Picture1.ScaleHeight - 1 w = Picture1.Point(i, j) r = w And RGB(255, 0, 0) g = Int((w And RGB(0, 255, 0)) / 256) b = Int(Int((w And RGB(0, 0, 255)) / 256) / 256) xg(i, j) = Int((r + g + b) / 3) Picture1.PSet (i, j), RGB(xg(i, j), xg(i, j), xg(i, j)) Next j Next i 'Deteksi Tepi For i = 1 To Picture1.ScaleWidth - 2 For j = 1 To Picture1.ScaleHeight - 2 z1 = xg(i , j + 1) - xg(i, j - 1) z = Abs(z1) If z > 255 Then z = 255 Picture2.PSet (i, j), RGB(z, z, z) Next j Next i End Sub
DifferensialMenurut Metode Newton (Metode Numerik) Metode Newton Maju: Differensial h(n) diperoleh dari data x(n+1) dikurangi oleh x(n), ditulis dengan: h(n) = x(n+1) – x(n) Metode Newton Mundur: Differensial h(n) diperoleh dari data x(n) dikurangi oleh x(n-1), ditulis dengan: h(n) = x(n) – x(n-1) Metode Newton Tengahan: Differensial h(n) diperoleh dari setengah data x(n+1) dikurangi oleh x(n-1), ditulis dengan: h(n) = ½ { x(n+1) – x(n-1) }
Differensial HorisontalMetode Newton Tengahan 1 (-1) (0) + (1) (1) H(i,j) = x(i,j+1) – x(i,j-1) 0 0 1 1 1 0 0 1 0 0 0 0 1 1 1 0 0 1 0 0 0 0 1 1 1 0 0 1 0 0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 Formulasi : H(i,j) = (-1) X(i,j) + (0) X(i,j) + (1) X(i,j+1)
Differensial Horisontal/VertikalMetode Newton Tengahan Diff. Horisontal: H(i,j) = (-1) X(i,j-1) + (0) X(i,j) + (1) X(i,j+1) -1 0 1 Kernel Diff. Horisontal: H(i,j) = (-1) X(i-1,j) + (0) X(i,j) + (1) X(i+1,j) -1 Kernel 0 1
Metode Prewitt Metode ini mengembangkan metode newton tengahan dengan menggunakan kernel yang berupa kernel 2D sebagai berikut: -1 0 1 -1 -1 -1 -1 0 1 0 0 0 -1 0 1 1 1 1 Horisontal Vertikal
Implementasi Code Metode Prewitt Private Sub Form_Load() Dim xg(320, 240) As Integer 'Mengubah ke gray scale For i = 0 To Picture1.ScaleWidth - 1 For j = 0 To Picture1.ScaleHeight - 1 w = Picture1.Point(i, j) r = w And RGB(255, 0, 0) g = Int((w And RGB(0, 255, 0)) / 256) b = Int(Int((w And RGB(0, 0, 255)) / 256) / 256) xg(i, j) = Int((r + g + b) / 3) Picture1.PSet (i, j), RGB(xg(i, j), xg(i, j), xg(i, j)) Next j Next i 'Deteksi Tepi For i = 1 To Picture1.ScaleWidth - 2 For j = 1 To Picture1.ScaleHeight - 2 z1 = xg(i - 1, j + 1) - xg(i - 1, j - 1) z2 = xg(i, j + 1) - xg(i, j - 1) z3 = xg(i + 1, j + 1) - xg(i + 1, j - 1) z = Abs(z1 + z2 + z3) If z > 255 Then z = 255 Picture2.PSet (i, j), RGB(z, z, z) Next j Next i End Sub
Pengembangan Metode Prewitt -1 0 1 -1 -1 -1 -2 -1 0 + = -1 0 1 0 0 0 -1 0 1 -1 0 1 1 1 1 0 1 2 Horisontal Vertikal Gabungan
Implementasi Code Metode Prewitt Private Sub Form_Load() Dim xg(320, 240) As Integer 'Mengubah ke gray scale For i = 0 To Picture1.ScaleWidth - 1 For j = 0 To Picture1.ScaleHeight - 1 w = Picture1.Point(i, j) r = w And RGB(255, 0, 0) g = Int((w And RGB(0, 255, 0)) / 256) b = Int(Int((w And RGB(0, 0, 255)) / 256) / 256) xg(i, j) = Int((r + g + b) / 3) Picture1.PSet (i, j), RGB(xg(i, j), xg(i, j), xg(i, j)) Next j Next i 'Deteksi Tepi For i = 1 To Picture1.ScaleWidth - 2 For j = 1 To Picture1.ScaleHeight - 2 z1 = -2 * xg(i - 1, j - 1) - xg(i - 1, j) z2 = -xg(i, j - 1) + xg(i, j - 1) z3 = xg(i + 1, j) + 2 * xg(i + 1, j + 1) z = Abs(z1 + z2 + z3) If z > 255 Then z = 255 Picture2.PSet (i, j), RGB(z, z, z) Next j Next i End Sub
Perbandingan Hasil METODE PREWITT HORISONTAL METODE PREWITT GABUNGAN
Pengembangan Metode Prewitt -2 -1 0 -1 0 1 -1 0 1 -2 0 2 0 1 2 -1 0 1 Metode Prewitt Gabungan Metode Sobel Horisontal
Metode Sobel Metode ini mengembangkan metode Prewitt dengan menambahkan pembobot gaussian sehingga Metode Sobel ini metode deteksi tepi yang mempunyai kemampuan untuk smoothing -1 0 1 -1 -2 -1 -2 0 2 0 0 0 -1 0 1 1 2 1 Horisontal Vertikal
Implementasi Code Metode Prewitt Private Sub Form_Load() Dim xg(320, 240) As Integer 'Mengubah ke gray scale For i = 0 To Picture1.ScaleWidth - 1 For j = 0 To Picture1.ScaleHeight - 1 w = Picture1.Point(i, j) r = w And RGB(255, 0, 0) g = Int((w And RGB(0, 255, 0)) / 256) b = Int(Int((w And RGB(0, 0, 255)) / 256) / 256) xg(i, j) = Int((r + g + b) / 3) Picture1.PSet (i, j), RGB(xg(i, j), xg(i, j), xg(i, j)) Next j Next i 'Deteksi Tepi For i = 1 To Picture1.ScaleWidth - 2 For j = 1 To Picture1.ScaleHeight - 2 z1 = xg(i - 1, j + 1) - xg(i - 1, j - 1) z2 =2*( xg(i, j + 1) - xg(i, j - 1) ) z3 = xg(i + 1, j + 1) - xg(i + 1, j - 1) z = Abs(z1 + z2 + z3) If z > 255 Then z = 255 Picture2.PSet (i, j), RGB(z, z, z) Next j Next i End Sub