Implementasi dan Deteksi Pola Wajah Pada Citra Digital Menggunakan Skin Color dan K-Means Clustering

(1)

LAMPIRAN

List Program FDeteksiWajah.vb

Imports System.ComponentModel

Public Class FDeteksiWajah

Private CGen As ClGeneral

Dim CWajah As ClDeteksi

Dim CShape As New ClShapeA

Dim tProgress As Integer

Private Sub IndikatorHandle(ByVal Kondisi As Boolean, Optional ByVal Pesan

As String = "")

If Kondisi Then

Label1.Text = Pesan Label2.Text = ""

Timer1.Enabled = True

ProgressBar1.Visible = True

Else

Label1.Text = Pesan Label2.Text = ""

Timer1.Enabled = False

ProgressBar1.Visible = False

End If

End Sub

Private Sub FrmSkinDetect_Load(ByVal sender As Object, ByVal e As

System.EventArgs) Handles Me.Load IndikatorHandle(False) End Sub

Private Sub BWReadPixel_DoWork(ByVal sender As Object, ByVal e As

System.ComponentModel.DoWorkEventArgs) Handles BWReadPixel.DoWork Dim worker As BackgroundWorker = _

CType(sender, BackgroundWorker) Dim CImage As New ClImage

CImage.ReadPixel(CType(e.Argument, ClGeneral), worker, e) End Sub

Private Sub BWReadPixel_ProgressChanged(ByVal sender As Object, ByVal e As

System.ComponentModel.ProgressChangedEventArgs) Handles

BWReadPixel.ProgressChanged

ProgressBar1.Value = e.ProgressPercentage End Sub

Private Sub BWReadPixel_RunWorkerCompleted(ByVal sender As Object, ByVal e

As System.ComponentModel.RunWorkerCompletedEventArgs) Handles

BWReadPixel.RunWorkerCompleted

Label1.Text = "Database Read.."

Application.DoEvents()

BWDatabaseRead.RunWorkerAsync(CGen) End Sub


(2)

Private Sub BWDatabaseRead_DoWork(ByVal sender As Object, ByVal e As

System.ComponentModel.DoWorkEventArgs) Handles BWDatabaseRead.DoWork Dim worker As BackgroundWorker = _

CType(sender, BackgroundWorker) Dim CDb As New ClDatabase

CDb.Connstring = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" &

Application.StartupPath & "\db.mdb"

CDb.TblName = "tbl_color"

CDb.ReadDBColor(CType(e.Argument, ClGeneral), worker, e) End Sub

Private Sub BWDatabaseRead_ProgressChanged(ByVal sender As Object, ByVal e

As System.ComponentModel.ProgressChangedEventArgs) Handles

BWDatabaseRead.ProgressChanged

ProgressBar1.Value = e.ProgressPercentage End Sub

Private Sub BWDatabaseRead_RunWorkerCompleted(ByVal sender As Object, ByVal

e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles

BWDatabaseRead.RunWorkerCompleted Label1.Text = "Skin Detection"

Application.DoEvents()

BWDetectSkin.RunWorkerAsync(CGen) End Sub

Private Sub BWDetectSkin_DoWork(ByVal sender As Object, ByVal e As

System.ComponentModel.DoWorkEventArgs) Handles BWDetectSkin.DoWork Dim worker As BackgroundWorker = _

CType(sender, BackgroundWorker) Dim CColorDetect As New ClColorDetect

CColorDetect.DetectColor(CType(e.Argument, ClGeneral), worker, e) End Sub

Private Sub BWDetectSkin_ProgressChanged(ByVal sender As Object, ByVal e As

System.ComponentModel.ProgressChangedEventArgs) Handles

BWDetectSkin.ProgressChanged

ProgressBar1.Value = e.ProgressPercentage End Sub

Private Sub BWDetectSkin_RunWorkerCompleted(ByVal sender As Object, ByVal e

As System.ComponentModel.RunWorkerCompletedEventArgs) Handles

BWDetectSkin.RunWorkerCompleted

IndikatorHandle(True, "Binerisasi") Application.DoEvents()

BWBinerisasi.RunWorkerAsync(CGen) End Sub

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As

System.EventArgs) Handles Timer1.Tick

Label2.Text = ProgressBar1.Value & " %"

End Sub

Private Sub BWBinerisasi_DoWork(ByVal sender As Object, ByVal e As

System.ComponentModel.DoWorkEventArgs) Handles BWBinerisasi.DoWork Dim worker As BackgroundWorker = _


(3)

Dim CImage As New ClImage

CImage.Binerisasi(CType(e.Argument, ClGeneral), worker, e) End Sub

Private Sub BWBinerisasi_ProgressChanged(ByVal sender As Object, ByVal e As

System.ComponentModel.ProgressChangedEventArgs) Handles

BWBinerisasi.ProgressChanged

ProgressBar1.Value = e.ProgressPercentage End Sub

Private Sub BWBinerisasi_RunWorkerCompleted(ByVal sender As Object, ByVal e

As System.ComponentModel.RunWorkerCompletedEventArgs) Handles

BWBinerisasi.RunWorkerCompleted

IndikatorHandle(True, "Erosi..") Application.DoEvents()

BWErosi.RunWorkerAsync(CGen) End Sub

Private Sub BWDilasi_DoWork(ByVal sender As Object, ByVal e As

System.ComponentModel.DoWorkEventArgs) Handles BWDilasi.DoWork Dim worker As BackgroundWorker = _

CType(sender, BackgroundWorker) Dim CShapeA As New ClShapeA

CShapeA.Dilasi(CType(e.Argument, ClGeneral), worker, e) End Sub

Private Sub BWDilasi_ProgressChanged(ByVal sender As Object, ByVal e As

System.ComponentModel.ProgressChangedEventArgs) Handles

BWDilasi.ProgressChanged

ProgressBar1.Value = e.ProgressPercentage End Sub

Private Sub BWDilasi_RunWorkerCompleted(ByVal sender As Object, ByVal e As

System.ComponentModel.RunWorkerCompletedEventArgs) Handles

BWDilasi.RunWorkerCompleted

IndikatorHandle(True, "Face Area..") Application.DoEvents()

CShape = New ClShapeA

BWKodeRantai.RunWorkerAsync(CGen) End Sub

Private Sub BWErosi_DoWork(ByVal sender As Object, ByVal e As

System.ComponentModel.DoWorkEventArgs) Handles BWErosi.DoWork Dim worker As BackgroundWorker = _

CType(sender, BackgroundWorker) Dim CShapeA As New ClShapeA

CShapeA.Erosi(CType(e.Argument, ClGeneral), worker, e) End Sub

Private Sub BWErosi_ProgressChanged(ByVal sender As Object, ByVal e As

System.ComponentModel.ProgressChangedEventArgs) Handles BWErosi.ProgressChanged ProgressBar1.Value = e.ProgressPercentage

End Sub

Private Sub BWErosi_RunWorkerCompleted(ByVal sender As Object, ByVal e As

System.ComponentModel.RunWorkerCompletedEventArgs) Handles


(4)

IndikatorHandle(True, "Dilasi..") Application.DoEvents()

BWDilasi.RunWorkerAsync(CGen) End Sub

Private Sub BWKodeRantai_DoWork(ByVal sender As Object, ByVal e As

System.ComponentModel.DoWorkEventArgs) Handles BWKodeRantai.DoWork Dim worker As BackgroundWorker = _

CType(sender, BackgroundWorker) Dim CShapeA As ClShapeA = CShape

CShapeA.CariKandidat(CType(e.Argument, ClGeneral), worker, e) End Sub

Private Sub BWKodeRantai_ProgressChanged(ByVal sender As Object, ByVal e As

System.ComponentModel.ProgressChangedEventArgs) Handles

BWKodeRantai.ProgressChanged

ProgressBar1.Value = e.ProgressPercentage End Sub

Private Sub BWKodeRantai_RunWorkerCompleted(ByVal sender As Object, ByVal e

As System.ComponentModel.RunWorkerCompletedEventArgs) Handles

BWKodeRantai.RunWorkerCompleted

PictureBox7.Image = CGen.ResImage2.Clone PictureBox7.Refresh()

CWajah = New ClDeteksi

CWajah.JC = Val(TextBox1.Text) BWWajah.RunWorkerAsync(CWajah) Application.DoEvents()

End Sub

Private Sub BWWajah_DoWork(ByVal sender As Object, ByVal e As

System.ComponentModel.DoWorkEventArgs) Handles BWWajah.DoWork Dim worker As BackgroundWorker = _

CType(sender, BackgroundWorker)

Dim CWajah2 As ClDeteksi = CType(e.Argument, ClDeteksi) CWajah2.Persentase = Val(TextBox1.Text)

CWajah2.Identifikasi(CShape, PictureBox1.Image, worker, e, tProgress) End Sub

Private Sub BWWajah_ProgressChanged(ByVal sender As Object, ByVal e As

System.ComponentModel.ProgressChangedEventArgs) Handles BWWajah.ProgressChanged ProgressBar1.Value = e.ProgressPercentage

End Sub

Private Sub BWWajah_RunWorkerCompleted(ByVal sender As Object, ByVal e As

System.ComponentModel.RunWorkerCompletedEventArgs) Handles

BWWajah.RunWorkerCompleted IndikatorHandle(False) Dim i As Integer

ListView1.Items.Clear() Dim LV As ListViewItem

For i = 0 To CWajah.LWajah.Count - 1

LV = ListView1.Items.Add(CWajah.LWajah(i).Nama) LV.SubItems.Add(CWajah.LWajah(i).Peluang) Next


(5)

Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e

As System.EventArgs) Handles ToolStripButton1.Click OpenFileDialog1.FileName = ""

OpenFileDialog1.ShowDialog()

If OpenFileDialog1.FileName <> "" Then

PictureBox1.ImageLocation = OpenFileDialog1.FileName PictureBox1.Load()

End If

End Sub

Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e

As System.EventArgs) Handles ToolStripButton2.Click CGen = New ClGeneral

CGen.PubImage = PictureBox1.Image.Clone IndikatorHandle(True, "Scan Pixel") BWReadPixel.RunWorkerAsync(CGen) End Sub

Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e

As System.EventArgs) Handles ToolStripButton3.Click Me.Close()

End Sub End Class

FFiturWajah.vb

Imports System.ComponentModel

Public Class FFiturWajah

Dim CGen As ClGeneral

Dim CKMeans As ClKMeans

Dim JC As Integer

Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e

As System.EventArgs) Handles ToolStripButton1.Click OpenFileDialog1.FileName = String.Empty OpenFileDialog1.ShowDialog()

If OpenFileDialog1.FileName <> String.Empty Then

Dim FIS As New IO.FileStream(OpenFileDialog1.FileName, IO.FileMode.Open)

CGen = New ClGeneral

CGen.PubImage = Image.FromStream(FIS) FIS.Close()

PictureBox1.Image = CGen.PubImage End If

End Sub

Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e

As System.EventArgs) Handles ToolStripButton2.Click JC = Val(TextBox1.Text)

CGen = New ClGeneral

CGen.PubImage = PictureBox1.Image.Clone BackgroundWorker1.RunWorkerAsync(CGen) End Sub


(6)

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As

System.EventArgs) Handles Timer1.Tick End Sub

Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As

System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork Dim worker As BackgroundWorker = _

CType(sender, BackgroundWorker) Dim CImage As New ClImage

CImage.ReadPixel(CType(e.Argument, ClGeneral), worker, e) End Sub

Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal

e As System.ComponentModel.ProgressChangedEventArgs) Handles

BackgroundWorker1.ProgressChanged

ProgressBar1.Value = e.ProgressPercentage End Sub

Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object,

ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles

BackgroundWorker1.RunWorkerCompleted Application.DoEvents()

BackgroundWorker2.RunWorkerAsync(CGen) End Sub

Private Sub BackgroundWorker2_DoWork(ByVal sender As Object, ByVal e As

System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker2.DoWork Dim worker As BackgroundWorker = _

CType(sender, BackgroundWorker) CKMeans = New ClKMeans

CKMeans.ScanCluster(CType(e.Argument, ClGeneral), JC) End Sub

Private Sub BackgroundWorker2_RunWorkerCompleted(ByVal sender As Object,

ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles

BackgroundWorker2.RunWorkerCompleted ListView1.Items.Clear() Dim LV As ListViewItem

Dim i As Integer

For i = 0 To CKMeans.LCluster.Count - 1 LV = ListView1.Items.Add(i + 1)

LV.SubItems.Add(CKMeans.LCluster(i).CR) LV.SubItems.Add(CKMeans.LCluster(i).CG) LV.SubItems.Add(CKMeans.LCluster(i).CB) LV.SubItems.Add(CKMeans.LCluster(i).Populasi) Application.DoEvents() Next

'RichTextBox1.Text = CKMeans.Lapor

End Sub

Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e

As System.EventArgs) Handles ToolStripButton3.Click If CKMeans.LCluster.Count < 1 Then

Exit Sub


(7)

Dim Konek As New OleDb.OleDbConnection

Konek.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & Application.StartupPath & "\db.mdb"

Konek.Open()

Dim CMD As OleDb.OleDbCommand = Konek.CreateCommand Dim DR1 As OleDb.OleDbDataReader

CMD.CommandText = "delete from wajah where nama='" & TextBox2.Text &

"'"

CMD.ExecuteNonQuery()

CMD.CommandText = "delete from cluster where nama='" & TextBox2.Text &

"'"

CMD.ExecuteNonQuery()

CMD.CommandText = "insert into wajah(jcluster,nama) values(" & JC &

",'" & TextBox2.Text & "')"

CMD.ExecuteNonQuery() Dim i As Integer

For i = 0 To CKMeans.LCluster.Count - 1 With CKMeans.LCluster(i)

CMD.CommandText = "insert into cluster(cr,cg,cb,pop,nama) values(" & .CR & "," & .CG & "," & .CB & "," & .Populasi & ",'" & TextBox2.Text & "')"

CMD.ExecuteNonQuery() End With

Application.DoEvents() Next

Konek.Close()

MsgBox("Fitur Berhasil Di Simpan") End Sub

Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e

As System.EventArgs) Handles ToolStripButton4.Click Me.Close()

End Sub

Private Sub ToolStrip1_ItemClicked(ByVal sender As System.Object, ByVal e

As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles

ToolStrip1.ItemClicked End Sub

End Class

FCover.vb

Public Class FCover

Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e

As System.EventArgs) Handles ToolStripButton1.Click Dim F As New FFiturWajah

F.ShowDialog() End Sub

Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e

As System.EventArgs) Handles ToolStripButton2.Click Dim F As New FDeteksiWajah


(8)

F.ShowDialog() End Sub

Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e

As System.EventArgs) Handles ToolStripButton4.Click End

End Sub End Class

ClDeteksi.vb

Imports System.ComponentModel

Public Class ClDeteksi

Public Class Wajah

Public Nama As String

Public Peluang As Double

End Class

Public LWajah As List(Of Wajah) Public Persentase As Double

Public JC As Integer

Public Sub Identifikasi(ByVal cShape As ClShapeA, ByVal Gambar As Bitmap,

ByVal worker As BackgroundWorker, _

ByVal e As DoWorkEventArgs, ByRef tProgress As Integer) Dim i As Integer

Dim j As Integer

Dim k As Integer

Dim l As Integer

Dim m As Integer

Dim GambarTes As Bitmap

Dim XTengah As Integer

Dim YTengah As Integer

Dim XAwal As Integer

Dim YAwal As Integer

Dim XAkhir As Integer

Dim YAkhir As Integer

Dim Jarak As Double

Dim Tamp1 As Double

Dim Warna1 As Color

Dim Warna2 As Color

Dim tObjek As Wajah

Dim R1 As Integer

Dim G1 As Integer

Dim B1 As Integer

Dim R2 As Integer

Dim G2 As Integer

Dim B2 As Integer

Dim CKMeans As ClKMeans

Dim CKMeans2 As ClKMeans

Dim CGen1 As ClGeneral


(9)

Dim PPiksel As ClGeneral.PubPixel

Dim Konek2 As OleDb.OleDbConnection = New OleDb.OleDbConnection

Dim CMD2 As OleDb.OleDbCommand

Dim DR2 As OleDb.OleDbDataReader

Dim Konek As OleDb.OleDbConnection = New OleDb.OleDbConnection

Dim CMD1 As OleDb.OleDbCommand

Dim DR1 As OleDb.OleDbDataReader

Dim FIO As IO.FileStream

Konek.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & Application.StartupPath & "\db.mdb"

Konek.Open()

Konek2.ConnectionString = Konek.ConnectionString Konek2.Open()

CMD2 = Konek2.CreateCommand

If Konek.State = ConnectionState.Closed Then

Exit Sub

End If

CMD1 = Konek.CreateCommand

CMD1.CommandText = "select * from wajah where jcluster=" & JC

DR1 = CMD1.ExecuteReader LWajah = New List(Of Wajah) If DR1.HasRows Then

Do While DR1.Read

For i = 0 To cShape.LWajah.Count - 1 XAwal = cShape.LWajah(i).X1 XAkhir = cShape.LWajah(i).X2 YAwal = cShape.LWajah(i).Y1 YAkhir = cShape.LWajah(i).Y2 CGen1 = New ClGeneral

CGen1.LPubPixel = New List(Of ClGeneral.PubPixel) For j = XAwal To XAkhir

For k = YAwal To YAkhir

Warna1 = Gambar.GetPixel(j, k) PPiksel = New ClGeneral.PubPixel

PPiksel.R = Warna1.R PPiksel.G = Warna1.G PPiksel.B = Warna1.B

CGen1.LPubPixel.Add(PPiksel) Next

Next

k = 0 l = 0

CMD2.CommandText = "select * from cluster where nama='" & DR1("nama") & "'"

DR2 = CMD2.ExecuteReader If DR2.HasRows Then

CKMeans = New ClKMeans

CKMeans.LCluster = New List(Of ClKMeans.Cluster) Do While DR2.Read

ClusterK = New ClKMeans.Cluster


(10)

ClusterK.CG = DR2("cg") ClusterK.CB = DR2("cb")

ClusterK.Populasi = DR2("pop")

CKMeans.LCluster.Add(ClusterK) Loop

End If

DR2.Close()

CKMeans2 = New ClKMeans

CKMeans2.ScanCluster2(CGen1, CKMeans.LCluster, JC) l = 0

k = CKMeans.LCluster.Count

For j = 0 To CKMeans.LCluster.Count - 1 If CKMeans.LCluster(j).Populasi <= CKMeans2.LCluster(j).Populasi Then

l += 1 Else

l += (CKMeans2.LCluster(j).Populasi / CKMeans.LCluster(j).Populasi)

End If

Next

If k > 0 Then

k = (l / k) * 100 End If

If k >= 70 Then

tObjek = New Wajah

tObjek.Nama = DR1("nama") tObjek.Peluang = k

LWajah.Add(tObjek) End If

tProgress = (i / cShape.LWajah.Count) * 100 Next Loop End If DR1.Close() Konek.Close() End Sub End Class CLImage.vb

Imports System

Imports System.Collections

Imports System.ComponentModel

Imports System.Threading

Imports DeteksiWajah.ClGeneral Public Class ClImage

Private Structure ColorFind

Dim R As Long

Dim G As Long

Dim B As Long


(11)

Dim tColorF As New ColorFind

Public Sub ReadPixel(ByRef CGen As ClGeneral, ByVal worker As BackgroundWorker, _

ByVal e As DoWorkEventArgs)

Dim tBitmap As Bitmap = CGen.PubImage.Clone Dim tColor As Color

Dim i As Long = 0 Dim j As Long = 0 Dim k As Long = 0

Dim tPixel As PubPixel = Nothing

CGen.LPubPixel = New List(Of PubPixel) For i = 0 To tBitmap.Width - 1

For j = 0 To tBitmap.Height - 1

If worker.CancellationPending = True Then

e.Cancel = True

Exit Sub

End If

tColor = tBitmap.GetPixel(i, j) tPixel = New PubPixel

tPixel.X = i + 1 tPixel.Y = j + 1 tPixel.R = tColor.R tPixel.G = tColor.G tPixel.B = tColor.B

CGen.LPubPixel.Add(tPixel) k += 1

worker.ReportProgress((k / (tBitmap.Width * tBitmap.Height)) * 100)

Application.DoEvents() Next

Next

End Sub

Public Sub RecColor(ByRef CGen As ClGeneral, ByVal worker As BackgroundWorker, _

ByVal e As DoWorkEventArgs) Dim i As Long = 0

Dim j As Long = 0 Dim k As Long = 0

Dim TempColor As List(Of HistColor) = Nothing

Dim TempColor2 As HistColor = Nothing

Dim temp As Long = 0

TempColor = CGen.LHistColor

For i = 0 To CGen.LPubPixel.Count - 1

If worker.CancellationPending = True Then

e.Cancel = True

Exit Sub

End If


(12)

'temp += CGen.LPubPixel.Item(i).G

'temp += CGen.LPubPixel.Item(i).B

temp = 1

tColorF.R = CGen.LPubPixel.Item(i).R / temp tColorF.G = CGen.LPubPixel.Item(i).G / temp tColorF.B = CGen.LPubPixel.Item(i).B / temp k = -1

k = TempColor.FindIndex(AddressOf FindColor) If k >= 0 Then

TempColor.Item(k).Bin += 1 Else

TempColor2 = New HistColor

TempColor2.R = tColorF.R TempColor2.G = tColorF.G TempColor2.B = tColorF.B TempColor2.Bin = 1

TempColor.Add(TempColor2) End If

worker.ReportProgress((i / (CGen.LPubPixel.Count - 1)) * 100) Application.DoEvents()

Next

CGen.LHistColor = TempColor Application.DoEvents() End Sub

Private Function FindColor(ByVal tColor As HistColor) As Boolean

Dim Jarak As Double

Jarak = Math.Pow(tColorF.R - tColor.R, 2) Jarak += Math.Pow(tColorF.G - tColor.G, 2) Jarak += Math.Pow(tColorF.B - tColor.B, 2) Jarak = Math.Sqrt(Jarak)

If Jarak <= 10 Then

Return True

Else

Return False

End If

End Function

Public Sub Binerisasi(ByRef CGen As ClGeneral, ByVal worker As BackgroundWorker, _

ByVal e As DoWorkEventArgs)

Dim tempPixel As ClGeneral.PubPixel = Nothing

Dim i As Long = 0

Dim tempImage As Bitmap = New Bitmap(CGen.PubImage) For i = 0 To CGen.LPubPixel.Count - 1

With CGen.LPubPixel.Item(i)

If .R > 0 And .G > 0 And .B > 0 Then

.R = 255 .G = 255 .B = 255 End If


(13)

End With

worker.ReportProgress((i / (CGen.LPubPixel.Count - 1)) * 100) Application.DoEvents()

Next

CGen.ResImage1 = New Bitmap(tempImage) tempImage.Dispose()

End Sub End Class

CLDetectColor.vb

Imports System

Imports System.Collections

Imports System.ComponentModel

Imports System.Threading

Imports System.Drawing

Imports DeteksiWajah.ClGeneral Public Class ClColorDetect

Private Class ColorF

Public R As Long

Public G As Long

Public B As Long

End Class

Private tColorF As ColorF

Public Sub DetectColor(ByRef CGen As ClGeneral, ByVal worker As BackgroundWorker, _

ByVal e As DoWorkEventArgs) Dim i As Long = 0

Dim k As Long = 0 Dim tempImage As Bitmap

tempImage = New Bitmap(CGen.PubImage) Dim tColor As Color = Nothing

Dim Peluang As Double = 0

For i = 0 To CGen.LPubPixel.Count - 1

If worker.CancellationPending = True Then

e.Cancel = True

Exit Sub

End If

tColorF = New ColorF

tColorF.R = CGen.LPubPixel.Item(i).R tColorF.G = CGen.LPubPixel.Item(i).G tColorF.B = CGen.LPubPixel.Item(i).B k = -1

k = CGen.LHistColor.FindIndex(AddressOf FindColor) If k < 0 Then

With CGen.LPubPixel.Item(i)

tempImage.SetPixel(.X - 1, .Y - 1, Color.FromArgb(0, 0, 0)) .R = 0


(14)

.G = 0 .B = 0 End With

Else

Peluang = CGen.LHistColor(k).Bin / CGen.MaxHistBin If Peluang < 0.01 Then

With CGen.LPubPixel.Item(i)

tColor = Color.FromArgb(0, 0, 0)

tempImage.SetPixel(.X - 1, .Y - 1, Color.FromArgb(0, 0, 0))

.R = 0 .G = 0 .B = 0 End With

End If

End If

worker.ReportProgress((i / (CGen.LPubPixel.Count - 1)) * 100) Application.DoEvents()

Next

CGen.ResImage1 = tempImage.Clone tempImage.Dispose()

End Sub

Private Function FindColor(ByVal tColor As HistColor) As Boolean

Dim Jarak As Double

Jarak = Math.Pow(tColorF.R - tColor.R, 2) Jarak += Math.Pow(tColorF.G - tColor.G, 2) Jarak += Math.Pow(tColorF.B - tColor.B, 2) Jarak = Math.Sqrt(Jarak)

If Jarak <= 10 Then

Return True Else Return False End If End Function End Class ClDatabase.vb

Imports System

Imports System.Collections

Imports System.ComponentModel

Imports System.Threading

Imports DeteksiWajah.ClGeneral Public Class ClDatabase

Public TblName As String

Public Connstring As String

Public Sub ReadDBColor(ByRef CGen As ClGeneral, ByVal worker As BackgroundWorker, _

ByVal e As DoWorkEventArgs)


(15)

Dim DbConnection As New OleDb.OleDbConnection

DbConnection.ConnectionString = Connstring DbConnection.Open()

Dim DbCommand As OleDb.OleDbCommand = DbConnection.CreateCommand DbCommand.CommandText = "select * from " & TblName

Dim DbReader As OleDb.OleDbDataReader = DbCommand.ExecuteReader CGen.LHistColor = New List(Of HistColor)

Dim TempSum As Long = 0 If DbReader.HasRows Then

Do While DbReader.Read

If worker.CancellationPending = True Then

e.Cancel = True

DbReader.Close() DbConnection.Close() Exit Sub

End If

TempHist = New HistColor

TempHist.R = DbReader(1) TempHist.G = DbReader(2) TempHist.B = DbReader(3) TempHist.Bin = DbReader(4) If TempSum < TempHist.Bin Then

TempSum = TempHist.Bin End If

CGen.LHistColor.Add(TempHist) Loop

End If

CGen.MaxHistBin = TempSum DbReader.Close()

DbConnection.Close() End Sub

Public Sub SaveDbColor(ByRef CGen As ClGeneral, ByVal worker As BackgroundWorker, _

ByVal e As DoWorkEventArgs) Dim i As Long = 0

Dim CString As String = ""

Dim DbConnection As New OleDb.OleDbConnection

DbConnection.ConnectionString = Connstring DbConnection.Open()

Dim DbCommand As OleDb.OleDbCommand = DbConnection.CreateCommand DbCommand.CommandText = "delete from tbl_color"

DbCommand.ExecuteNonQuery()

For i = 0 To CGen.LHistColor.Count - 1 With CGen.LHistColor

If worker.CancellationPending = True Then

e.Cancel = True

DbConnection.Close() Exit Sub


(16)

CString = "insert into tbl_color(r,g,b,bin) values(" & .Item(i).R & ", " & .Item(i).G & _

", " & .Item(i).B & ", " & .Item(i).Bin & ")"

DbCommand.CommandText = CString DbCommand.ExecuteNonQuery()

worker.ReportProgress((i / (.Count - 1)) * 100) Application.DoEvents() End With Next DbConnection.Close() End Sub End Class ClShape.vb

Imports System

Imports System.Collections

Imports System.ComponentModel

Public Class ClShapeA

Private Class kCari

Public X As Long

Public Y As Long

End Class

Private Class TempPixel

Public X As Long

Public Y As Long

Public R As Long

Public G As Long

Public B As Long

Public Label As Long

End Class

Private Class TitikObjek

Public X As Long

Public Y As Long

Public Nilai As Long

End Class

Private Class Objek

Public Titik As List(Of TitikObjek) Public Nama As String

Public Kode As String

Public P As Double

Public Area As Double

End Class

Public Class Wajah

Public X1 As Long

Public X2 As Long

Public Y1 As Long

Public Y2 As Long

End Class

Private LCObjek As List(Of Objek) Public LWajah As List(Of Wajah) Private tBitmap As Bitmap


(17)

Private LTempPixel As List(Of TempPixel) Private tempCari As kCari = Nothing

Private tempNilaiCari As Long

Public Sub CariKandidat(ByRef CGen As ClGeneral, ByVal worker As BackgroundWorker, _

ByVal e As DoWorkEventArgs) Dim i As Long = 0

Dim j As Long = 0 Dim k As Long = 0 Dim l As Long = 0 Dim temp As Long = 0 Dim OCount As Long = 0 Dim z As Long = 0

Dim TempTObjek As TitikObjek = Nothing

Dim TempObjek As Objek = Nothing

Dim TTempPixel As TempPixel = Nothing

Dim TampX As Long = 0 Dim TampY As Long = 0

Dim ArrUrutanObjek(,) As Long

tBitmap = New Bitmap(CGen.PubImage)

Dim ArrObjek(tBitmap.Width - 1, tBitmap.Height - 1, 1) As Long

CGen.JumlahKandidat = 0

LTempPixel = New List(Of TempPixel) For i = 0 To CGen.LPubPixel.Count - 1

ArrObjek(CGen.LPubPixel.Item(i).X - 1, CGen.LPubPixel.Item(i).Y - 1, 0) = CGen.LPubPixel.Item(i).R

ArrObjek(CGen.LPubPixel.Item(i).X - 1, CGen.LPubPixel.Item(i).Y - 1, 1) = 0

worker.ReportProgress((i / (CGen.LPubPixel.Count - 1)) * 100) Application.DoEvents()

Next

z = 1 OCount = 0

LCObjek = New List(Of Objek) For i = 1 To tBitmap.Width - 2 For j = 1 To tBitmap.Height - 2 If ArrObjek(i, j, 1) > 0 Then

j += 1

If j <= tBitmap.Height - 1 Then

Do While ArrObjek(i, j, 0) > 0 j += 1

If j > tBitmap.Height - 1 Then

Exit Do

End If

Loop

End If

ElseIf ArrObjek(i, j, 1) = 0 And ArrObjek(i, j, 0) > 0 Then

OCount += 1 TampX = i TampY = j

TempTObjek = New TitikObjek

TempTObjek.X = i TempTObjek.Y = j TempTObjek.Nilai = 255


(18)

TempObjek = New Objek

TempObjek.Titik = New List(Of TitikObjek) TempObjek.Titik.Add(TempTObjek)

TempObjek.Nama = OCount TempObjek.Kode = ""

l = j k = i temp = 0

Do While temp >= 0

temp = CekTetangga(k, l, ArrObjek) If temp > -1 Then

ArrObjek(k, l, 1) = OCount TempTObjek = New TitikObjek

TempTObjek.X = k TempTObjek.Y = l TempTObjek.Nilai = 255

TempObjek.Titik.Add(TempTObjek) TempObjek.Kode &= temp

End If

Loop

LCObjek.Add(TempObjek) j += 1

If j <= tBitmap.Height - 1 Then

Do While ArrObjek(i, j, 0) > 0 j += 1

If j > tBitmap.Height - 1 Then

Exit Do

End If

Loop

End If

Else

If ArrObjek(i, j, 0) > 0 Then

Do While ArrObjek(i, j, 0) > 0 j += 1

If j > tBitmap.Height - 1 Then

Exit Do End If Loop End If End If Next

worker.ReportProgress((z / (tBitmap.Width * tBitmap.Height)) * 100) Application.DoEvents()

z += 1 Next

tBitmap = New Bitmap(CGen.PubImage) tempNilaiCari = 10

Do While True

k = -1

k = LCObjek.FindIndex(AddressOf CariJumlahTitik) If k >= 0 Then

LCObjek.RemoveAt(k) Else

Exit Do


(19)

Loop

For k = 0 To LCObjek.Count - 1 With LCObjek.Item(k)

For l = 0 To .Titik.Count - 1 With .Titik.Item(l) If k Mod 2 = 0 Then

tBitmap.SetPixel(.X, .Y, Color.FromArgb(0, 255, 0)) ElseIf k Mod 3 = 0 Then

tBitmap.SetPixel(.X, .Y, Color.FromArgb(255, 0, 0)) Else

tBitmap.SetPixel(.X, .Y, Color.FromArgb(0, 0, 255)) End If

End With

Next

End With

worker.ReportProgress((k / (LCObjek.Count - 1)) * 100) Application.DoEvents()

Next

CGen.ResImage1 = New Bitmap(tBitmap) ReDim ArrUrutanObjek(LCObjek.Count - 1, 1) For i = 0 To LCObjek.Count - 1

ArrUrutanObjek(i, 0) = i

ArrUrutanObjek(i, 1) = LCObjek.Item(i).Titik.Count Next

Dim txMax As Long = 0 Dim tyMax As Long = 0 Dim txMin As Long = 0 Dim tyMin As Long = 0 Dim JarakHor As Double = 0 Dim JarakVer As Double = 0 Dim tempWajah As Wajah = Nothing

Dim tValid As Boolean = False

Dim sIndexY As Long = 0 Dim sIndexX As Long = 0 Dim tPixel As Long = 0 LWajah = New List(Of Wajah) For i = 0 To LCObjek.Count - 1 With LCObjek.Item(i)

TampX = .Titik.Item(0).X TampY = .Titik.Item(0).Y tyMin = TampY

txMin = TampX txMax = TampX tyMax = TampY tValid = False

For j = 1 To .Titik.Count - 1 If tyMin > .Titik.Item(j).Y Then

tyMin = .Titik.Item(j).Y sIndexY = j

End If

Next


(20)

If txMin > .Titik.Item(j).X Then

txMin = .Titik.Item(j).X sIndexX = j

End If

Next

For j = 1 To .Titik.Count - 1 If txMax < .Titik.Item(j).X Then

txMax = .Titik.Item(j).X sIndexX = j

End If

Next

For j = 1 To .Titik.Count - 1 If tyMax < .Titik.Item(j).Y Then

tyMax = .Titik.Item(j).Y sIndexY = j

End If

Next

For j = sIndexX To 1 Step -1 k = .Titik.Item(j).X l = .Titik.Item(j).Y If tyMin > l Then

tyMin = l End If

If tyMax < l Then

tyMax = l End If

JarakVer = Math.Pow(txMin - txMax, 2) JarakVer += Math.Pow(tyMin - tyMin, 2) JarakVer = Math.Sqrt(JarakVer)

JarakHor = Math.Pow(txMin - txMin, 2) JarakHor += Math.Pow(tyMin - tyMax, 2) JarakHor = Math.Sqrt(JarakHor)

If ((tyMax - tyMin) / (txMax - txMin)) < 3 And ((tyMax - tyMin) / (txMax - txMin)) > 0.5 Then

tPixel = 0

For k = txMin To txMax For l = tyMin To tyMax

If ArrObjek(k, l, 1) > 0 Then

sIndexX = ArrObjek(k, l, 1) l += 1

If l > tyMax Then

Exit For

End If

Do While ArrObjek(k, l, 1) <> sIndexX If ArrObjek(k, l, 0) > 0 Then

tPixel += 1 End If

l += 1

If l > tyMax Then


(21)

End If

Loop

End If

Next

Next

'If tPixel > 0 Then

' tValid = True

' Exit For

'End If

If (tPixel / ((tyMax - tyMin) * (txMax - txMin))) > 0.3

And (tPixel / ((tyMax - tyMin) * (txMax - txMin))) <= 0.95 Then 'And JarakHor >= JarakVer Then

tValid = True

Exit For

End If

End If

Next

End With

If tValid Then

tempWajah = New Wajah

tempWajah.X1 = txMin tempWajah.Y1 = tyMin tempWajah.X2 = txMax tempWajah.Y2 = tyMax LWajah.Add(tempWajah) End If

worker.ReportProgress((i / (LCObjek.Count - 1)) * 100) Application.DoEvents()

Next

CGen.JumlahKandidat = LWajah.Count CGen.JumlahWajah = 0

Dim LRata As Double = 0 For i = 0 To LWajah.Count - 1 With LWajah.Item(i)

LRata += (.X2 - .X1) * (.Y2 - .Y1) End With

Next

LRata = LRata / LWajah.Count i = 0

Do While True

If LWajah.Count < 1 Then

Exit Do

End If

With LWajah.Item(i)

If LRata > (((.X2 - .X1) * (.Y2 - .Y1)) * 1.5) Then

LWajah.RemoveAt(i) i -= 1

If i < 0 Then

If i = LWajah.Count - 1 Then

Exit Do

End If

i += 1 End If


(22)

Else

If i = LWajah.Count - 1 Then

Exit Do

End If

i += 1 End If

End With

Loop

CGen.JumlahWajah = LWajah.Count tBitmap = New Bitmap(CGen.PubImage) For i = 0 To LWajah.Count - 1 'If i = 0 Then

With LWajah.Item(i) For k = .X1 To .X2

tBitmap.SetPixel(k, .Y1, Color.FromArgb(255, 255, 0)) Next

For k = .Y1 To .Y2

tBitmap.SetPixel(.X1, k, Color.FromArgb(255, 255, 0)) Next

For k = .X1 To .X2

tBitmap.SetPixel(k, .Y2, Color.FromArgb(255, 255, 0)) Next

For k = .Y1 To .Y2

tBitmap.SetPixel(.X2, k, Color.FromArgb(255, 255, 0)) Next

End With

'End If

worker.ReportProgress(((i + 1) / (LWajah.Count)) * 100) Application.DoEvents()

Next

CGen.ResImage2 = New Bitmap(tBitmap) End Sub

Private Function CariJumlahTitik(ByVal tTitik As Objek) As Boolean

If tTitik.Titik.Count <= tempNilaiCari Then

Return True

Else

Return False

End If

End Function

Private Function CekTetangga(ByRef tX As Long, ByRef tY As Long, ByRef

tArr(,,) As Long) As Long

Dim tempX As Long = 0 Dim tempY As Long = 0

'check kode 2...

tempX = tX tempY = tY tempY -= 1

If tempY >= 0 Then

If tArr(tempX, tempY, 0) > 0 And tArr(tempX, tempY, 1) = 0 Then


(23)

If tempX >= 0 Then

If tArr(tempX, tempY, 0) = 0 Then

tX = tempX + 1 tY = tempY Return 2 End If

End If

If tempX < 0 Then

tempX += 1 tX = tempX + 1 tY = tempY Return 2 End If

End If

End If

'check kode 1...

tempX = tX tempY = tY tempX += 1 tempY -= 1

If tempX <= tBitmap.Width - 1 And tempY >= 0 Then

If tArr(tempX, tempY, 0) > 0 And tArr(tempX, tempY, 1) = 0 Then

tempX -= 1

'If tempX >= 0 Then

If tArr(tempX, tempY, 0) = 0 Then

tX = tempX + 1 tY = tempY Return 1 End If

'End If

End If

End If

'check kode 0...

tempX = tX tempY = tY tempX += 1

If tempX <= tBitmap.Width - 1 Then

If tArr(tempX, tempY, 0) > 0 And tArr(tempX, tempY, 1) = 0 Then

tempY -= 1

If tempY >= 0 Then

If tArr(tempX, tempY, 0) = 0 Then

tX = tempX tY = tempY + 1 Return 0 End If

End If

If tempY < 0 Then

tempY += 1 tX = tempX tY = tempY + 1 Return 0 End If

End If


(24)

'check kode 7...

tempX = tX tempY = tY tempX += 1 tempY += 1

If tempX <= tBitmap.Width - 1 And tempY <= tBitmap.Height - 1 Then

If tArr(tempX, tempY, 0) > 0 And tArr(tempX, tempY, 1) = 0 Then

tempY -= 1

'If tempY >= 0 Then

If tArr(tempX, tempY, 0) = 0 Then

tX = tempX tY = tempY + 1 Return 7 End If

'End If

End If

End If

'check kode 6...

tempX = tX tempY = tY tempY += 1

If tempY <= tBitmap.Height - 1 Then

If tArr(tempX, tempY, 0) > 0 And tArr(tempX, tempY, 1) = 0 Then

tempX += 1

If tempX <= tBitmap.Width - 1 Then

If tArr(tempX, tempY, 0) = 0 Then

tX = tempX - 1 tY = tempY Return 6 End If

End If

If tempX > tBitmap.Width - 1 Then

tempX -= 1 tX = tempX - 1 tY = tempY Return 6 End If

End If

End If

'check kode 5...

tempX = tX tempY = tY tempY += 1 tempX -= 1

If tempY <= tBitmap.Height - 1 And tempX >= 0 Then

If tArr(tempX, tempY, 0) > 0 And tArr(tempX, tempY, 1) = 0 Then

tempX += 1

'If tempX <= tBitmap.Width - 1 Then

If tArr(tempX, tempY, 0) = 0 Then

tX = tempX - 1 tY = tempY Return 5 End If

'End If


(25)

End If

'check kode 4...

tempX = tX tempY = tY 'tempY += 1

tempX -= 1

If tempX >= 0 Then

If tArr(tempX, tempY, 0) > 0 And tArr(tempX, tempY, 1) = 0 Then

tempY += 1

If tempY <= tBitmap.Height - 1 Then

If tArr(tempX, tempY, 0) = 0 Then

tX = tempX tY = tempY - 1 Return 4 End If

End If

If tempY > tBitmap.Height - 1 Then

tempY -= 1 tX = tempX tY = tempY - 1 Return 4 End If

End If

End If

'check kode 3...

tempX = tX tempY = tY tempY -= 1 tempX -= 1

If tempX >= 0 And tempY >= 0 Then

If tArr(tempX, tempY, 0) > 0 And tArr(tempX, tempY, 1) = 0 Then

tempY += 1

'If tempY <= tBitmap.Height - 1 Then

If tArr(tempX, tempY, 0) = 0 Then

tX = tempX tY = tempY - 1 Return 3 End If

'End If

End If

End If

Return -1 End Function

Public Sub Dilasi(ByRef CGen As ClGeneral, ByVal worker As BackgroundWorker, _

ByVal e As DoWorkEventArgs) Dim i As Long = 0

Dim k As Long = 0

Dim tempNilai As Long = 0 Dim tempMax As Long = 0

Dim tempPixel As ClGeneral.PubPixel = Nothing

Dim tempImage As New Bitmap(CGen.PubImage)


(26)

Dim DilasiC As Long = 0 For DilasiC = 1 To 2

For i = 0 To CGen.LPubPixel.Count - 1 With CGen.LPubPixel.Item(i) tempArr(.X - 1, .Y - 1) = .R End With

worker.ReportProgress((i / (CGen.LPubPixel.Count - 1)) * 100) Application.DoEvents()

Next

For i = 0 To CGen.LPubPixel.Count - 1 With CGen.LPubPixel.Item(i)

If .X > 1 And .Y > 1 And .X < tempImage.Width And .Y < tempImage.Height And .R < 255 Then

tempMax = 0

If tempArr((.X - 1) - 1, (.Y - 1) - 1) > 0 Then

tempMax = 255 End If

If tempArr((.X - 1), (.Y - 1) - 1) > 0 Then

tempMax = 255 End If

If tempArr((.X - 1) + 1, (.Y - 1) - 1) > 0 Then

tempMax = 255 End If

If tempArr((.X - 1) - 1, (.Y - 1)) > 0 Then

tempMax = 255 End If

'If tempArr((.X - 1), (.Y - 1)) > 0 Then

' tempMax = 255

'End If

If tempArr((.X - 1) + 1, (.Y - 1)) > 0 Then

tempMax = 255 End If

If tempArr((.X - 1) - 1, (.Y - 1) + 1) > 0 Then

tempMax = 255 End If

If tempArr((.X - 1), (.Y - 1) + 1) > 0 Then

tempMax = 255 End If

If tempArr((.X - 1) + 1, (.Y - 1) + 1) > 0 Then

tempMax = 255 End If

.R = tempMax .G = tempMax .B = tempMax


(27)

tempImage.SetPixel(.X - 1, .Y - 1, Color.FromArgb(.R, .G, .B))

Else

tempImage.SetPixel(.X - 1, .Y - 1, Color.FromArgb(.R, .G, .B))

End If

End With

worker.ReportProgress((i / (CGen.LPubPixel.Count - 1)) * 100) Application.DoEvents()

Next

Next

CGen.ResImage1 = New Bitmap(tempImage) tempImage.Dispose()

End Sub

Public Sub Dilasi2(ByRef CGen As ClGeneral, ByVal worker As BackgroundWorker, _

ByVal e As DoWorkEventArgs) Dim i As Long = 0

Dim k As Long = 0

Dim tempNilai As Long = 0 Dim tempMax As Long = 0

Dim tempPixel As ClGeneral.PubPixel = Nothing

Dim tempImage As New Bitmap(CGen.PubImage)

Dim tempArr(tempImage.Width - 1, tempImage.Height - 1) As Long

Dim DilasiC As Long = 0 For DilasiC = 1 To 1

For i = 0 To CGen.LPubPixel.Count - 1 With CGen.LPubPixel.Item(i) tempArr(.X - 1, .Y - 1) = .R End With

worker.ReportProgress((i / (CGen.LPubPixel.Count - 1)) * 100) Application.DoEvents()

Next

For i = 0 To CGen.LPubPixel.Count - 1 With CGen.LPubPixel.Item(i)

If .X > 1 And .Y > 1 And .X < tempImage.Width And .Y < tempImage.Height And .R < 255 Then

tempMax = 0

If tempArr((.X - 1) - 1, (.Y - 1) - 1) > 0 Then

tempMax = 255 End If

If tempArr((.X - 1), (.Y - 1) - 1) > 0 Then

tempMax = 255 End If

If tempArr((.X - 1) + 1, (.Y - 1) - 1) > 0 Then

tempMax = 255 End If

If tempArr((.X - 1) - 1, (.Y - 1)) > 0 Then

tempMax = 255 End If


(28)

'If tempArr((.X - 1), (.Y - 1)) > 0 Then

' tempMax = 255

'End If

If tempArr((.X - 1) + 1, (.Y - 1)) > 0 Then

tempMax = 255 End If

If tempArr((.X - 1) - 1, (.Y - 1) + 1) > 0 Then

tempMax = 255 End If

If tempArr((.X - 1), (.Y - 1) + 1) > 0 Then

tempMax = 255 End If

If tempArr((.X - 1) + 1, (.Y - 1) + 1) > 0 Then

tempMax = 255 End If

.R = tempMax .G = tempMax .B = tempMax

tempImage.SetPixel(.X - 1, .Y - 1, Color.FromArgb(.R, .G, .B))

Else

tempImage.SetPixel(.X - 1, .Y - 1, Color.FromArgb(.R, .G, .B))

End If

End With

worker.ReportProgress((i / (CGen.LPubPixel.Count - 1)) * 100) Application.DoEvents()

Next

Next

CGen.ResImage1 = New Bitmap(tempImage) tempImage.Dispose()

End Sub

Public Sub Erosi(ByRef CGen As ClGeneral, ByVal worker As BackgroundWorker, _

ByVal e As DoWorkEventArgs) Dilasi2(CGen, worker, e) Dim i As Long = 0

Dim k As Long = 0

Dim tempNilai As Long = 0 Dim tempMax As Long = 0

Dim tempPixel As ClGeneral.PubPixel = Nothing

Dim tempImage As New Bitmap(CGen.PubImage)

Dim tempArr(tempImage.Width - 1, tempImage.Height - 1) As Long

Dim ErosiC As Long = 0 For ErosiC = 1 To 4

For i = 0 To CGen.LPubPixel.Count - 1 With CGen.LPubPixel.Item(i) tempArr(.X - 1, .Y - 1) = .R


(29)

End With

worker.ReportProgress((i / (CGen.LPubPixel.Count - 1)) * 100) Application.DoEvents()

Next

For i = 0 To CGen.LPubPixel.Count - 1 With CGen.LPubPixel.Item(i)

If .X > 1 And .Y > 1 And .X < tempImage.Width And .Y < tempImage.Height And .R > 0 Then

tempMax = 255

If tempArr((.X - 1) - 1, (.Y - 1) - 1) < 255 Then

tempMax = 0 End If

If tempArr((.X - 1), (.Y - 1) - 1) < 255 Then

tempMax = 0 End If

If tempArr((.X - 1) + 1, (.Y - 1) - 1) < 255 Then

tempMax = 0 End If

If tempArr((.X - 1) - 1, (.Y - 1)) < 255 Then

tempMax = 0 End If

'If tempArr((.X - 1), (.Y - 1)) > 0 Then

' tempMax = 255

'End If

If tempArr((.X - 1) + 1, (.Y - 1)) < 255 Then

tempMax = 0 End If

If tempArr((.X - 1) - 1, (.Y - 1) + 1) < 255 Then

tempMax = 0 End If

If tempArr((.X - 1), (.Y - 1) + 1) < 255 Then

tempMax = 0 End If

If tempArr((.X - 1) + 1, (.Y - 1) + 1) < 255 Then

tempMax = 0 End If

.R = tempMax .G = tempMax .B = tempMax

tempImage.SetPixel(.X - 1, .Y - 1, Color.FromArgb(.R, .G, .B))

Else

tempImage.SetPixel(.X - 1, .Y - 1, Color.FromArgb(.R, .G, .B))

End If


(30)

worker.ReportProgress((i / (CGen.LPubPixel.Count - 1)) * 100) Application.DoEvents()

Next

For i = 0 To CGen.LPubPixel.Count - 1 With CGen.LPubPixel.Item(i) tempArr(.X - 1, .Y - 1) = .R End With

worker.ReportProgress((i / (CGen.LPubPixel.Count - 1)) * 100) Application.DoEvents()

Next

For i = 0 To CGen.LPubPixel.Count - 1 With CGen.LPubPixel.Item(i)

If .X > 1 And .Y > 1 And .X < tempImage.Width And .Y < tempImage.Height And .R > 0 Then

tempMax = 0

If tempArr((.X - 1) - 1, (.Y - 1) - 1) > 0 Then

tempMax += 1 End If

If tempArr((.X - 1), (.Y - 1) - 1) > 0 Then

tempMax += 1 End If

If tempArr((.X - 1) + 1, (.Y - 1) - 1) > 0 Then

tempMax += 1 End If

If tempArr((.X - 1) - 1, (.Y - 1)) > 0 Then

tempMax += 1 End If

'If tempArr((.X - 1), (.Y - 1)) > 0 Then

' tempMax = 255

'End If

If tempArr((.X - 1) + 1, (.Y - 1)) > 0 Then

tempMax += 1 End If

If tempArr((.X - 1) - 1, (.Y - 1) + 1) > 0 Then

tempMax += 1 End If

If tempArr((.X - 1), (.Y - 1) + 1) > 0 Then

tempMax += 1 End If

If tempArr((.X - 1) + 1, (.Y - 1) + 1) > 0 Then

tempMax += 1 End If

If tempMax >= 2 Then

tempMax = 255 Else


(31)

End If

.R = tempMax .G = tempMax .B = tempMax

tempImage.SetPixel(.X - 1, .Y - 1, Color.FromArgb(.R, .G, .B))

Else

tempImage.SetPixel(.X - 1, .Y - 1, Color.FromArgb(.R, .G, .B))

End If

End With

worker.ReportProgress((i / (CGen.LPubPixel.Count - 1)) * 100) Application.DoEvents()

Next

Next

CGen.ResImage1 = New Bitmap(tempImage) tempImage.Dispose()

End Sub End Class


(32)

CURRICULUM VITAE

--- Data Pribadi

Nama : Septy Diana Sari Saragih Tempat/Tanggal Lahir : Binjai / 28 September 1991 Tinggi/Berat Badan : 163 cm / 42 kg

Agama : Islam Kewarganegaraan : Indonesia

Alamat : Jl. Klambir V Gg. Kalpataru No. 7 Medan Alamat Orang Tua : Jl. Klambir V Gg. Kalpataru No. 7 Medan Telp/ Hp : 082370046677

Email : chiqels@gmail.com

--- Riwayat Pendidikan

[2010 – 2016] : S1 Ilmu Komputer Universitas Sumatera Utara, Medan [2006 – 2009] : SMA Negeri 15 Medan

[2003 – 2006] : SMP Negeri 7 Medan [1997 – 2003] : SD Negeri 020267 Binjai

--- Keahlian/Kursus

Keahlian Komputer Bahasa :

Pemrograman : C++, Visual Basic English

Database : MySQL Indonesia

Perkantoran : Microsoft Office

--- Pengalaman Organisasi


(33)

[2011 – 2012] Anggota IMILKOM 2011/2012 [2012 – 2013] Anggota IMILKOM 2012 – 2013

--- Pengalaman Kepanitiaan

[2010] Anggota Seksi Perlengkapan Seminar I-Pear ILKOM [2012] Koordinator Kesehatan PMB IMILKOM USU

--- Seminar


(34)

DAFTAR PUSTAKA

Al-Mohair, H. K., Saleh, J. M., & Suandi, S. A. (2013). Impact of Color Space on Human Skin Color Detection Using an Intelligent System. Recent Advances in Image, Audio and Signal Processing, ISBN : 978-960-474-350-6.

Azad, R. (2013). Novel and Tuneable Method for Skin Detection Based on Hybrid Color Space and Color Statistical Features. First International Conference on computer, Information Technology and Digital Media (CITADIM Proceeding-Scientific).

Bhat, V. S., & Pujari, J. D. (2013). Face detection system using HSV color model and morphing operations. International Journal of Current Engineering and Technology, ISSN 2277 - 4106.

Dubey, S. R., Dixit, P., Singh, N., & Gupta, J. P. (2013). Infected Fruit Part Detection using K-Means Clutering Segmentation Technique. International Journal of Artificial Intelligence and Interactive Multimedia, Vol. 2, No. 2.

Hamilton, E. (1992). JPEG File Interchange Format. W3 Organization. Kadir, A. (2013). Teori dan Aplikasi Pengolahan Citra. Jakarta: Andi.

Muthukumar, A., & Kannan, S. (2013). Finger Knuckle Print Recognition With Sift and K-Means Algorithm. ICTACT Journal On Image and Video Processing, Vol. 3, Issue : 03.

Osman, G. (2012). Enhanced Skin Color Classifier Using RGB Ratio Model. International Journal on Soft Computing (IJSC) Vol.3, No. 4.

Putra, D. (2010). Pengolahan Citra Digital. Yogyakarta: Penerbit Andi.

Sutoyo, T. (2009). Teori Pengolahan Citra Digital. Yogyakarta: Penerbit Andi.


(35)

BAB 3

ANALISIS DAN PERANCANGAN SISTEM

3.1Analisis Permasalahan

Masalah yang diangkat dari penelitian tugas akhir ini adalah pembuatan sistem Deteksi wajah pada citra digital menggunakan kombinasi metode skin color detection dan k-means clustering. Metode skin color detection merupakan metode yang digunakan untuk memisahkan atau mengekstraksi piksel – piksel pada citra digital yang memiliki warna seperti warna kulit manusia. Deteksi wajah pada citra digital menggunakan metode skin color detection pada citra digital untuk mengecilkan area – area dari citra sehingga proses deteksi wajah menjadi lebih efektif dibandingkan dengan proses pembacaan secara linear piksel per piksel. Metode k-means clustering digunakan untuk mengidentifikasi wajah pada area warna kulit yang diperoleh. Penerapan kedua metode tersebut pada bidang identifikasi manusia khususnya wajah menjadi lebih efektif dan efisien.

3.2Analisis Kebutuhan Sistem

Analisis kebutuhan sistem meliputi analisis kebutuhan fungsional dan analisis kebutuhan non-fungsional sistem.

3.2.1 Analisis Kebutuhan Fungsional Sistem

Kebutuhan fungsional yang harus dimiliki oleh sistem identifikasi wajah pada citra digital menggunakan metode skin color detection dan k-means clustering adalah : 1 Sistem dapat melakukan ekstraksi piksel – piksel warna kulit dari piksel – piksel

lain pada citra digital.

2 Sistem dapat mengekstraksi fitur wajah menggunakan k-means clustering. 3 Sistem dapat mengidentifikasi posisi wajah manusia pada citra digital.


(36)

4 Sistem dapat menggunakan citra dengan satu atau beberapa wajah pada citra digital.

3.2.2 Analisis Kebutuhan Non-Fungsional Sistem

Kebutuhan non-fungsional yang harus dimiliki oleh sistem deteksi wajah citra digital menggunakan metode skin color detection dan k-means clustering adalah :

1. Sistem memiliki proses yang akurat dan cepat.

2. Tampilan antarmuka sistem menarik dan dapat dimengerti oleh pengguna sistem.

3.3Pemodelan

Pada penelitian ini digunakan UML sebagai bahasa pemodelan untuk mendesain dan merancang sistem deteksi wajah citra digital menggunakan metode skin color

detection dan k-means clustering. Model UML yang digunakan adalah use case

dan activity diagram.

3.3.1 Pemodelan dengan Menggunakan Use Case Diagram

Untuk mengetahui aktor dan use case yang akan digunakan, maka dilakukan identifikasi aktor dan identifikasi use case. Setelah mendapatkan aktor dan use

case, maka use case diagram dapat digambarkan.

Aktor yang berinteraksi dengan sistem ini adalah user yang terdiri atas satu jenis yaitu:user. Sistem dapat melakukan pelatihan dan identifikasi seperti pada (Gambar 3.1).


(37)

DETEKSI WAJAH

MENGGUNAKAN SKIN COLOR

DAN KMEANS

User

Pengenalan Pola Wajah KMeans

Deteksi Wajah

Gambar 3.1Use Case Diagram yang akan dikembangkan

3.3.1.1Use Case Pengenalan Pola Wajah K-Means

Use case ini akan menjelaskan secara sederhana fungsi sistem pada saat proses

pengenalan pola wajah menggunakan k-means clustering yang kemudian dapat digunakan pada saat deteksi wajah pada citra digital. Dapat dilihat pada (Tabel 3.1) yang merupakan dokumentasi naratif dari use case pengenalan pola wajah

k-means.

Tabel 3.1 Spesifikasi Use Case Pengenalan Pola Wajah K-means Nama Use Case Pengenalan Pola Wajah K-Means

Aktor User

Deskripsi Use Case ini mendeskripsikan bagaimana proses pengenalan

pola wajah menggunakan K-Means clustering. Kegiatan User Respon Sistem

Alur Dasar 1. Tekan tombol Open 1. Menampilkan dialog buka gambar.


(38)

Tabel 3.2 Spesifikasi Use Case Pengenalan (Lanjutan)

2. Tekan tombol

Proses!

2. Melakukan proses

pengelompokan piksel

– piksel wajah

menggunakan K-Means clustering.

3. Tekan tombol Save! 3. Menyimpan informasi pengelompokkan

kedalam database Kondisi Sesudah Sistem melakukan penyimpanan informasi pengelompokan

piksel wajah kedalam database

3.3.1.2 Use Case Deteksi Wajah

Use case ini akan menjelaskan secara sederhana fungsi sistem pada saat deteksi

wajah pada citra digital. Dapat dilihat pada (Tabel 3.2) yang merupakan dokumentasi naratif dari use case deteksi wajah.

Tabel 3.3 Spesifikasi Use Case Deteksi Wajah Nama Use Case Deteksi Wajah

Aktor User

Deskripsi Use Case ini mendeskripsikan bagaimana proses deteksi

wajah pada citra digital


(39)

Alur Dasar 1. Tekan tombol Open 1. Menampilkan dialog untuk memilih gambar dan menampilkan gambar ke antarmuka sistem

2. Tekan tombol

Proses

2. Melakukan proses ekstraksi warna kulit pada citra yang kemudian area piksel

dari kulit dibandingkan dengan

pola wajah menggunakan

K-Means clustering.

Alur Alternatif Tidak ada

Kondisi Sesudah Sistem melakukan deteksi wajah pada citra digital.

3.3.2 Pemodelan dengan Menggunakan Activity Diagram

Diagram aktifitas atau activity diagram menggambarkan alur kerja (workflow) atau aktifitas dari sebuah sistem.

3.3.2.1 Activity Diagram Pengenalan Pola Wajah

Activity diagram pengenalan pola wajah akan menggambarkan hubungan aliran

kerja yang telah dijelaskan pada use case pengenalan pola wajah. Activity


(40)

User Sistem

Klik Tombol Open Buka Gambar Wajah

Baca Piksel Pilih Jumlah Cluster Yang Digunakan

Klik Tombol Simpan

Melakukan Clustering Piksel Wajah

Menampilkan Informasi Cluster Wajah

Menyimpan Informasi Cluster Wajah

Gambar 3.2 Activity Diagram Proses Pengenalan Pola Wajah 3.3.2.2Activity Diagram Deteksi Wajah

Activity diagram deteksi wajah akan menggambarkan hubungan aliran kerja yang

telah dijelaskan pada use case deteksi wajah. Activity diagram deteksi wajah dapat dilihat pada (Gambar 3.3).


(41)

User Sistem

Klik Tombol Open Buka Gambar

Baca Piksel Pilih Jumlah Cluster Yang Digunakan

Melakukan Proses Ekstraksi Piksel Kulit Manusia

Membandingkan Area Warna Kulit Dengan Fitur Wajah

Menampilkan Lokasi Wajah Pada Citra Melihat Hasil Deteksi dan Keluar Dari Sistem

Gambar 3.3 Activity Diagram Proses Deteksi Wajah

3.3.3 Diagram Ishikawa

Diagram ishikawa adalah diagram yang menunjukkan penyebab-penyebab dari sebuah even yang spesifik. Berikut rancangan diagram Ishikawa dari penelitian ini.


(42)

Deteksi Wajah Citra Digital

People Method

Material Machine

Operator

Skin Color

KMeans

Contoh Wajah

Citra Uji

Visual Basic .Net

Gambar 3.4 Diagram Ishikawa 3.4 Perancang Sistem

3.4.1 Flowchart Sistem

3.4.1.1 Flowchart Gambaran Umum Sistem

Gambaran umum sistem ini dapat dilihat pada flowchart yang dirancang pada sub bab ini yang terdiri dari dua bagian utama yaitu proses pengenalan pola wajah dan proses deteksi :


(43)

START

Membaca Piksel Pada Citra Wajah

Input Citra Wajah dan jumlah cluster

Mengelompokkan Piksel Ke dalam Sejumlah Cluster

yang telah ditetapkan

Menyimpan informasi cluster

ke database

Output Informsasi

Cluster Wajah

END A

A

Gambar 3.5 Flowchart Gambaran Umum Sistem Proses Pengenalan Pola

Wajah

Keterangan :

Dari (Gambar 3.5) dapat dilihat gambaran umum dari sistem ini. Proses pengenalan pola wajah seperti yang terlihat pada flowchart yang dirancang dimulai dengan input dari pengguna berupa citra wajah dan jumlah cluster yang digunakan. Sistem kemudian akan membaca setiap piksel wajah dan mengelompokkannya kedalam beberapa cluster dengan menggunakan metode

K-Means clustering. Informasi cluster kemudian disimpan kedalam database dan


(44)

START

Melakukan ekstraksi warna kulit pada citra uji

Input Citra Uji dan jumlah cluster

Membandingkan setiap cluster dari

area wajah dengan cluster

dari database

Output lokasi area wajah yang memenuhi cluster dari database

END A

Mengelompokkan Piksel warna kulit

Ke dalam Sejumlah Cluster

yang telah ditetapkan

A

Membaca cluster wajah dari

database

Gambar 3.6 Flowchart Gambaran Sistem Proses Deteksi Wajah Keterangan :

Dari (Gambar 3.6) dapat dilihat gambaran umum dari sistem ini. Proses deteksi wajah dimulai dengan input citra uji dan jumlah cluster yang digunakan. Sistem kemudian melakukan ekstraksi warna kulit pada piksel dan membentuk area dari piksel – piksel yang tergolong ke dalam warna kulit. Area dari warna kulit tersebut di cluster menggunakan K-Means clustering. Sistem kemudian membaca informas cluster wajah dari database dan membandingkan cluster tersebut dengan

cluster area warna kulit hasil ekstraksi. Area warna kulit yang memiliki cluster


(45)

3.4.1.2 Flowchart Proses Skin Color Detection

START

Melakukan perhitungan nilai mean dan variance dari Hue, Cb dan Cr

dari setiap piksel dari citra Input Citra

Output Piksel yang

tergolong ke warna

kulit

END

Melakukan pemindaian tiap piksel pada citra digital dan menggolongkan piksel – piksel

yang tergolong ke warna kulit ArrPiksel = Membaca Piksel

Citra Tes

Gambar 3.7 Flowchart Proses Skin Color Detection

Keterangan :

Dari (Gambar 3.7) dapat dilihat proses dari skin color detection. Sistem menerima input citra yang kemudian sistem akan melakukan komputasi nilai


(46)

variance dari ruang warna hue, Cb dan Cr. Kemudian sistem kemudian

melakukan penyeleksian piksel per piksel menggunakan pemeriksaan kondisi terhadap nilai variance yang diperoleh. Sistem kemudian menampilkan hasil piksel dari warna kulit pada citra.

3.4.1.3Flowchart Proses K-Means Clustering

START

Membentuk cluster awal sebanyak jumlah yang ditentukan

Input Citra dan jumlah cluster

END A

Memberikan nilai centroid acak awal pada cluster yang dibentuk

Melakukan pengelompokan piksel ke dalam cluster yang dibentuk berdasarkan jarak warna dengan

centroid dari cluster

Apakah nilai centroid awal berbeda dengan

centroid baru? Melakukan perhitungan centroid menggunakan nilai rata-rata dari

anggota tiap cluster

A B

B True

Output Informasi

Cluster False


(47)

Keterangan :

Dari (Gambar 3.8) dapat dilihat proses dari proses K-Means clustering. Proses dimulai dengan membentuk cluster awal dengan nilai centroid acak. Sistem kemudian melakukan pengelompokkan piksel citra ke dalam cluster yang dibentuk berdasarkan jarak warna piksel tersebut terhadap nilai centroid tiap

cluster. Setelah proses pengelompokkan selesai proses dilanjutkan dengan

perhitungan centroid baru dengan menggunakan nilai rata-rata dari piksel anggota dari cluster. Jika ternyata centroid baru tidak sama dengan centroid lama maka proses pengelompokkan diulang kembali menggunakan centroid baru.

3.4.2 Rancangan Database

Struktur database merupakan tempat penyimpanan informasi dari aliran data yang digunakan dalam sebuah sistem. Dalam perancangan aplikasi deteksi wajah ini terdiri dari dari beberapa tabel yaitu sebagai berikut.

1. Tabel Wajah

Tabel wajah merupakan tabel yang befungsi untuk menyimpan data wajah yang digunakan pada proses pengenalan.

Nama Tabel : tbl_wajah Primary Key : id_wajah

Tabel 3.3 Struktur Tabel Wajah

No. Field Tipe Ukuran Keterangan

1. ID_Wajah Varchar 10 Id data wajah

2. Nama Text 20 Nama Wajah

3. Keterangan Text 20 Keterangan Wajah

2. Tabel Detail Wajah

Tabel detail wajah berfungsi untuk menyimpan informasi k-means clustering dari citra wajah yang digunakan pada proses pengenalan.


(48)

Nama Tabel : tbl_detail_wajah Primary Key : id_detail_wajah

Tabel 3.4 Struktur Tabel Detail Wajah

No. Field Tipe Ukuran Keterangan

1. Id_detail_wajah Integer - ID Record Detail Wajah

2. JCluster Int 20 Jumlah Cluster yang

digunakan

3. Nama Text 20 Nama Pemilik Wajah

3. Tabel Cluster

Tabel cluster berfungsi untuk menyimpan data pencatatan informasi cluster dari proses k-means clustering dari masing – masing wajah.

Nama Tabel : tbl_cluster Primary Key : id_cluster

Tabel 3.5 Struktur Tabel Cluster

No. Field Tipe Ukuran Keterangan

1. Id_cluster Integer - ID Record data cluster

2. Id_wajah Integer - Id Wajah

3. CR Integer - Nilai Centroid Red

4. CG Integer - Nilai Centroid Green

5. CB Integer - Nilai Centroid Blue

6. Populasi Integer - Jumlah Populasi Piksel dari Cluster


(49)

3.4.3 Rancangan Antarmuka

Sistem akan dibangun menggunakan bahasa pemrograman Visual Basic dengan menggunakan software Microsoft Visual Studio 2010. Rancangan antar muka disesuaikan dengan kebutuhan dan software yang digunakan. Antar muka menggunakan 4 form, yaitu : form cover, form fitur wajah, form deteksi, dan form

about. Form cover berfungsi sebagai cover dari sistem dimana terdapat menu utama.

3.4.3.1 Antarmuka FormCover

Gambar 3.9 Rancangan Form Cover

Komponen yang dipakai untuk membangun antar muka form Cover pada (Gambar) 3.9 adalah sebagai berikut :

1. Menu “Fitur Wajah” : untuk masuk ke tampilan fitur wajah.

2. Menu “Deteksi” : untuk masuk ke tampilan Deteksi.

3. Menu “About” : untuk masuk ke tampilan about.

4. Menu “Exit” : untuk keluar dari program.

3.4.3.2Antarmuka Form Fitur Wajah

Pada form fitur wajah terdapat antarmuka yang bertujuan untuk melakukan ekstraksi fitur wajah menggunakan K-Means clustering menggunakan citra wajah

Deteksi Wajah (Skin Color Detection – K-Means Clustering) Fitur Wajah

Deteksi About Exit


(50)

yang dipilih oleh pengguna. Proses ekstraksi fitur wajah menggunakan jumlah cluster yang di-input oleh pengguna untuk membentuk cluster pada K-Means

clustering.

Gambar 3.10 Rancangan Form Fitur Wajah

Komponen yang dipakai untuk membangun antar muka form fitur wajah pada (Gambar 3.10) adalah sebagai berikut :

1. PictureBox1 : control yang berfungsi untuk menampilkan gambar yang

dibuka oleh pengguna.

2. Button “Open” : button yang berfungsi untuk membuka dialog untuk

memilih gambar.

3. Button “Scan” : button yang berfungsi untuk memulai proses

pengelompokkan fitur wajah.

PictureBox1

TextLabel RichTextBox1 Fitur Wajah

Open Scan Save Exit


(51)

4. Button “Save” : button yang berfungsi untuk menyimpan informasi fitur

wajah.

5. Button “Exit” : button yang berfungsi untuk keluar dari antarmuka.

6. Text “TextLabel” : control yang berfungsi untuk menampung jumlah cluster yang digunakan.

7. Richtextbox “Richtextbox1” : control yang berfungsi untuk menampung

informasi proses.

8. Tabel “Tabel1” : control yang berfungsi untuk menampilkan hasil cluster

dari K-Means clustering. 3.4.3.3Antarmuka Form Deteksi

Gambar 3.11 Rancangan Form Deteksi

Komponen yang dipakai untuk membangun antar muka form deteksi pada (Gambar 3.11) adalah sebagai berikut :

PictureBox1

TextLabel RichTextBox1 Deteksi

Open Deteksi Exit


(52)

1. PictureBox1 : control yang berfungsi untuk menampilkan gambar yang

dibuka oleh pengguna.

2. PictureBox2 : control yang berfungsi untuk menampilkan gambar hasil

deteksi wajah.

3. Button “Open” : button yang berfungsi untuk membuka dialog untuk

memilih gambar.

4. Button “Deteksi” : button yang berfungsi untuk memulai proses deteksi.

5. Button “Exit” : button yang berfungsi untuk keluar dari antarmuka.

6. Text “TextLabel” : control yang berfungsi untuk menampung jumlah

cluster yang digunakan.

7. Richtextbox “Richtextbox1” : control yang berfungsi untuk menampilkan

informasi proses yang dilakukan sistem.

3.4.3.4Antarmuka Form About

Gambar 3.12 Rancangan Form About

Komponen yang dipakai untuk membangun antar muka form about pada (Gambar 3.12) adalah sebagai berikut :

PictureBox1 TextLabel About


(53)

1. PictureBox1 : control yang berfungsi untuk menampilkan gambar wajah

penulis.

2. Text “TextLabel” : control yang berfungsi untuk menampilkan informasi


(54)

BAB 4

IMPLEMENTASI DAN PENGUJIAN

4.1. Implementasi

Sesuai dengan analisa dan perancangan seperti yang telah dijabarkan pada bab sebelumnya yaitu bab analisis dan perancangan, maka pada bagian ini akan dipaparkan hasil dari aplikasi yang dibangun menggunakan perancangan yang telah dilakukan pada bab sebelumnya. Pada bab ini pembahasan akan dilakukan terhadap hasil dari sistem yang dibangun, fungsional sistem dan analisis terhadap kinerja sistem berdasarkan hasil output yang dihasilkan oleh sistem.

4.1.1. Implementasi Sistem

Topik utama pada tugas akhir ini adalah merancang sistem yang mampu mendeteksi wajah pada citra digital. Area wajah pertama sekali dicari dengan proses pembacaan warna kulit menggunakan skin color detection yang kemudian wajah dideteksi menggunakan K-Means clustering.


(55)

Sistem dibangun menggunakan MS Visual Basic 2010 sehingga dalam proses pembangunan sistem, penulis menggunakan beberapa perangkat dan alat bantu sebagai berikut.

1. Komputer Pentium D 3.0 GHz 2. MemoriUtama 1 GB

3. HDD 350 GB 4. OS Windows 7.

5. MS Visual Studio 2010.

Pada penggunaanya sistem yang dibangun tidak membutuhkan spesifikasi khusus, namun yang perlu diperhatikan adalah sistem membutuhkan memori yang besar untuk memproses citra yang berukuran besar.

4.1.2. Fungsional Sistem

Secara garis besar sistem memiliki dua fungsi utama, yaitu fungsi fitur wajah atau dan fungsi deteksi wajah. Masing–masing fungsi dijalankan pada halaman yang terpisah sehingga memudahkan dalam penggunaan dari sistem yang dikembangkan. Berikut penjabaran dari fungsional sistem secara umum.

1. Fitur Wajah

Fitur Wajah merupakan fungsi yang dimiliki oleh sistem untuk melakukan pembacaan dan pendataan fitur wajah pada citra digital. Informasi fitur wajah diperoleh dari cluster yang diperoleh menggunakan metode K-Means

clustering.

2. Deteksi Wajah

Fungsi deteksi wajah merupakan fungsi yang dimiliki oleh sistem yang dikembangkan untuk melakukan deteksi wajah pada citra uji. Area wajah di ekstraksi menggunakan metode skin color detection, setiap area wajah kemudian dibandingkan fitur cluster nya dengan fitur cluster dari database yang kemudian diperoleh hasil deteksi dari wajah tersebut.


(56)

4.1.3. Implementasi Fungsi Fitur Wajah

Fungsi fitur wajah merupakan komponen sistem yang melakukan ekstraksi fitur wajah dari citra wajah. Pengguna memilih citra digital yang akan digunakan sebagai citra wajah yang kemudian akan digunakan oleh sistem untuk mengekstraksi fitur wajah menggunakan K-Means clustering. Antarmuka fitur wajah dapat dilihat pada gambar 4.2 sebagai berikut.

Gambar 4.2 Antarmuka Fitur Wajah

Fungsi fitur wajah seperti yang terlihat pada gambar 4.2 menerima input citra wajah dan kemudian mengkstraksi fitur wajah terhadap citra tersebut. Jumlah cluster yang akan dibentuk diperoleh dari input pengguna. Sistem kemudian akan membentuk jumlah cluster sesuai dengan input pengguna dan melakukan pengelompokkan piksel wajah kedalam cluster. Informasi cluster kemudian diberikan label nama dan disimpan kedalam database.

Berikut contoh analisis metode K-Means clustering yang digunakan pada penelitian ini :

Pembentukan Cluster Awal :


(57)

Centroid Awal Cluster Ke - 2 = (251,27,78) Centroid Awal Cluster Ke - 3 = (204,113,57)

Perhitungan Jarak Piksel (95,3,50) Jarak Ke Cluster Ke - 1

Jarak = Sqrt((95-196) + (3-103) + (50-42)) Jarak = 142.355189578744

Jarak Ke Cluster Ke - 2

Jarak = Sqrt((95-251) + (3-27) + (50-78)) Jarak = 160.299719276111

Jarak Ke Cluster Ke - 3

Jarak = Sqrt((95-204) + (3-113) + (50-57)) Jarak = 155.016128193166

Cluster Terpilih : Cluster Ke - 1

Perhitungan Jarak Piksel (81,3,43) Jarak Ke Cluster Ke - 1

Jarak = Sqrt((81-196) + (3-103) + (43-42)) Jarak = 152.400787399541

Jarak Ke Cluster Ke - 2

Jarak = Sqrt((81-251) + (3-27) + (43-78)) Jarak = 175.217008306842

Jarak Ke Cluster Ke - 3

Jarak = Sqrt((81-204) + (3-113) + (43-57)) Jarak = 165.604951616792


(58)

Perhitungan Jarak Piksel (63,6,39) Jarak Ke Cluster Ke - 1

Jarak = Sqrt((63-196) + (6-103) + (39-42)) Jarak = 164.642035944652

Jarak Ke Cluster Ke - 2

Jarak = Sqrt((63-251) + (6-27) + (39-78)) Jarak = 193.147611944854

Jarak Ke Cluster Ke - 3

Jarak = Sqrt((63-204) + (6-113) + (39-57)) Jarak = 177.915710379944

Cluster Terpilih : Cluster Ke - 1

Perhitungan Jarak Piksel (36,0,23) Jarak Ke Cluster Ke - 1

Jarak = Sqrt((36-196) + (0-103) + (23-42)) Jarak = 191.232842367623

Jarak Ke Cluster Ke - 2

Jarak = Sqrt((36-251) + (0-27) + (23-78)) Jarak = 223.559835390886

Jarak Ke Cluster Ke - 3

Jarak = Sqrt((36-204) + (0-113) + (23-57)) Jarak = 205.302216256912

Cluster Terpilih : Cluster Ke - 1

Perhitungan Jarak Piksel (22,0,17) Jarak Ke Cluster Ke - 1


(59)

Jarak = 203.740030430939

Jarak Ke Cluster Ke - 2

Jarak = Sqrt((22-251) + (0-27) + (17-78)) Jarak = 238.518343110126

Jarak Ke Cluster Ke - 3

Jarak = Sqrt((22-204) + (0-113) + (17-57)) Jarak = 217.928887483968

Cluster Terpilih : Cluster Ke - 1

Perhitungan Jarak Piksel (20,2,16) Jarak Ke Cluster Ke - 1

Jarak = Sqrt((20-196) + (2-103) + (16-42)) Jarak = 204.580057679139

Jarak Ke Cluster Ke - 2

Jarak = Sqrt((20-251) + (2-27) + (16-78)) Jarak = 240.478689284519

Jarak Ke Cluster Ke - 3

Jarak = Sqrt((20-204) + (2-113) + (16-57)) Jarak = 218.764713790867

Cluster Terpilih : Cluster Ke - 1

Perhitungan Jarak Piksel (15,0,9) Jarak Ke Cluster Ke - 1

Jarak = Sqrt((15-196) + (0-103) + (9-42)) Jarak = 210.853029383028


(60)

Jarak = Sqrt((15-251) + (0-27) + (9-78)) Jarak = 247.358040095728

Jarak Ke Cluster Ke - 3

Jarak = Sqrt((15-204) + (0-113) + (9-57)) Jarak = 225.375242651006

Cluster Terpilih : Cluster Ke - 1

Perhitungan Jarak Piksel (27,7,19) Jarak Ke Cluster Ke - 1

Jarak = Sqrt((27-196) + (7-103) + (19-42)) Jarak = 195.719186591402

Jarak Ke Cluster Ke - 2

Jarak = Sqrt((27-251) + (7-27) + (19-78)) Jarak = 232.501612897631

Jarak Ke Cluster Ke - 3

Jarak = Sqrt((27-204) + (7-113) + (19-57)) Jarak = 209.783221445377

Cluster Terpilih : Cluster Ke - 1

Perhitungan Jarak Piksel (26,11,32) Jarak Ke Cluster Ke - 1

Jarak = Sqrt((26-196) + (11-103) + (32-42)) Jarak = 193.556193390963

Jarak Ke Cluster Ke - 2

Jarak = Sqrt((26-251) + (11-27) + (32-78)) Jarak = 230.210772988581


(61)

Jarak Ke Cluster Ke - 3

Jarak = Sqrt((26-204) + (11-113) + (32-57)) Jarak = 206.671236508615

Cluster Terpilih : Cluster Ke - 1

Perhitungan Jarak Piksel (26,13,30) Jarak Ke Cluster Ke - 1

Jarak = Sqrt((26-196) + (13-103) + (30-42)) Jarak = 192.727787306346

Jarak Ke Cluster Ke - 2

Jarak = Sqrt((26-251) + (13-27) + (30-78)) Jarak = 230.488611432322

Jarak Ke Cluster Ke - 3

Jarak = Sqrt((26-204) + (13-113) + (30-57)) Jarak = 205.944167191013

Cluster Terpilih : Cluster Ke - 1

Perhitungan Jarak Piksel (22,14,25) Jarak Ke Cluster Ke - 1

Jarak = Sqrt((22-196) + (14-103) + (25-42)) Jarak = 196.178490156286

Jarak Ke Cluster Ke - 2

Jarak = Sqrt((22-251) + (14-27) + (25-78)) Jarak = 235.412404091203

Jarak Ke Cluster Ke - 3

Jarak = Sqrt((22-204) + (14-113) + (25-57)) Jarak = 209.640167906821


(1)

ABSTRAK

Deteksi wajah pada citra digital telah menjadi topik penelitian yang populer belakangan ini mengingat penggunaan teknologi citra digital yang luas saat sekarang ini. Metode – metode yang dikembangkan memiliki beberapa kelebihan dan kekurangannya masing-masing. Besarnya area citra digital menyebabkan deteksi wajah secara linier piksel per piksel menjadi tidak efektif. Pada penelitian ini dilakukan analisis dan percobaan yang bertujuan untuk mendeteksi wajah pada citra digital menggunakan metode skin color detection dan kmeans clustering. Skin color detection digunakan untuk mengecilkan area dari citra digital untuk proses pendeteksian. K-means clustering merupakan metode sederhana yang biasa digunakan pada pengenalan pola yang memiliki akurasi yang rendah namun memiliki operasi yang cukup cepat. Hasil penelitian menunjukkan bahwa implementasi kombinasi dari metode skin color detection dan k-means clustering memberikan kinerja yang baik dalam hal kecepatan namun masih memiliki kekurangan dalam hal akurasi yang mana sangat bergantung pada pemilihan jumlah cluster yang digunakan.

Kata Kunci : Deteksi Wajah, Citra Digital, Skin Color Detection, K-Means Clustering.


(2)

IMPLEMENTATION AND FACE DETECTION IN DIGITAL IMAGES USE SKIN COLOR AND K-MEANS CLUSTERING

ABSTRACT

Face detection in digital images has become a popular research topic these days considering the use of comprehensive digital imaging technology today. Methods developed has some advantages and disadvantages of each. The amount of digital image area causes linearly face detection pixels per pixel becomes ineffective. In this research, analysis and experiments imed at detecting faces in a digital image using skin color detection method and k-means clustering. Skin color detection is usedto shrink the area of digital imags for the detection procces. K-means clustering is a simple method that is commonly used in pattern recognition that has low accuracy but has a fairly quick operation. The results showed tht the implementation of a combination of skin color detection method and k-means clustering provide good performance in terms of speed but still has shortcomings in terms of accuracy which is very dependent on the choice of the number of clucters used.


(3)

DAFTAR ISI

Halaman

Persetujuan ii

Pernyataan iii

Penghargaan iv

Abstrak vi

Abstract vii

Daftar Isi viii

Daftar Tabel x

Daftar Gambar xi

Bab 1 Pendahuluan

1.1 Latar Belakang 1

1.2 Perumusan Masalah 2

1.3 Batasan Masalah 2

1.4 Tujuan Penelitian 3

1.5 Manfaat Penelitian 3

1.6 Metodologi Penelitian 3

1.7 Sistematika penulisan 4

Bab 2 Landasan Teori 2.1 Citra digital

2.1.1 Pengertian citra digital 6

2.1.2 Jenis citra 7

2.2 Pengolahan citra digital 8

2.3 Ruang Warna HSV 8

2.4 Ruang Warna YCbCr 10

2.5 Skin Color 11

2.6 Skin Color Detection 12

2.7 KMeans Clustering 14

2.8 Penelitian yang relevan 15

Bab 3 Analisis dan Perancangan Sistem

3.1 Analisis permasalahan 17

3.2 Analisis kebutuhan sistem 17

3.2.1 Analisis kebutuhan fungsional sistem 17 3.2.2 Analisis kebutuhan Non-fungsional sistem 18


(4)

3.3.3 Diagram Ishikawa 22

3.4 Perancang sistem 23

3.4.1 Flowchart sistem 23 3.4.1.1 Flowchart gambaran umum sistem 23 3.4.1.2 Flowchart proses skin color detection 25 3.4.1.3 Flowchart proses kmeans clustering 26 3.4.2 Rancangan database 27

3.4.3 Rancangan Antarmuka 29

3.4.3.1 Antarmuka form cover 29

3.4.3.2 Antarmuka form fitur wajah 29

3.4.3.3 Antarmuka form deteksi 31

3.4.3.4 Antarmuka form about 32 Bab 4 Implementasi dan Pengujian

4.1 Implementasi 33

4.1.1 Implementasi sistem 33

4.1.2 Fungsional sistem 34

4.1.3 Implementasi fungsi fitur wajah 35

4.1.4 Implementasi fungsi deteksi wajah 46

4.2 Pengujian 49

4.3 Pembahasan pengujian 59

Bab 5 Kesimpulan dan Saran

5.1 Kesimpulan 60

5.2 Saran 61

Daftar Pustaka 62

LAMPIRAN A : Listing Program A-1


(5)

DAFTAR TABEL

Halaman

Tabel 3.1 Spesifikasi Use Case Pengenalan Pola Wajah K-means 19

Tabel 3.2 Spesifikasi Use Case Pengenalan (Lanjutan) 20

Tabel 3.3 Spesifikasi Use Case Deteksi Wajah 20

Tabel 3.3 Struktur Tabel Wajah 27

Tabel 3.4 Struktur Tabel Detail Wajah 28

Tabel 3.5 Struktur Tabel Cluster 28


(6)

DAFTAR GAMBAR

Halaman

Gambar 2.1 Sistem Koordinat Citra Berukuran MxN 6

Gambar 2.2 Warna RGB dalam ruang berdimensi tiga 7

Gambar 2.3 Ruang Warna HSV 9

Gambar 2.4 Sebaran Warna Kulit Di Dunia 11

Gambar 2.5 Ekstraksi Warna Kulit 12

Gambar 3.1 Use Case Diagram Yang Akan Dikembangkan 19

Gambar 3.2 Activity Diagram Proses Pengenalan Pola Wajah 21

Gambar 3.3 Activity Diagram Proses Deteksi Wajah 22

Gambar 3.4 Diagram Ishikawa 23

Gambar 3.5 Flowchart Gambaran Umum Sistem Proses Pengenalan Pola Wajah 23 Gambar 3.6 Flowchart Gambaran Sistem Proses Deteksi Wajah 24

Gambar 3.7 Flowchart Proses Skin Color Detection 25

Gambar 3.8 Flowchart Proses K-Means Clustering 26

Gambar 3.9 Rancangan Form Cover 29

Gambar 3.10 Rancangan Form Fitur Wajah 30

Gambar 3.11 Rancangan Form Deteksi 31

Gambar 3.12 Rancangan Form About 32

Gambar 4.1 Sistem Deteksi Wajah Pada Citra Digital 34

Gambar 4.2 Antarmuka Fitur Wajah 35

Gambar 4.3 Antarmuka Deteksi 46

Gambar 4.4 Citra Uji 49

Gambar 4.5 Citra Wajah 49

Gambar 4.6 Pengujian Fitur Wajah 50

Gambar 4.7 Pengujian Deteksi 57

Gambar 4.8 Citra Wajah Jenderal 58