Beruflich Dokumente
Kultur Dokumente
Dim j As Integer
Private Centroid() As Single ' centroid (X and Y) of clusters; cluster number = column number
Dim x1 As Long
Dim y1 As Long
Dim i, j As Integer
Dim r, g, b As Integer
hWnd = Picture1.Handle.ToInt32()
hDC = GetWindowDC(hWnd)
curx = Picture1.Width
cury = Picture1.Height
For i = 0 To curx - 1
For j = 0 To cury - 1
tcol = GetPixel(hDC, i, j)
Next j
Next i
End Sub
End
End Sub
' ###################################################################
' CONTROLS
' + Form_Load
' + cmdReset_Click
' + txtNumCluster_Change
' + Picture1_MouseDown
' + Picture1_MouseMove
' ###################################################################
Private Sub Form_Load()
Dim i As Integer
lblExplanation.Caption = "Click data in the picture box below. The program will automatically cluster
the data by color code"
numCluster = Int(txtNumCluster)
' lblCentroid(0).Caption = 1
For i = 0 To numCluster - 1
'create label
lblCentroid(i).Caption = i + 1
lblCentroid(i).Visible = False
Next i
End Sub
Dim i As Integer
totalData = 0
For i = 0 To numCluster - 1
Next i
txtNumCluster.Enabled = True
End Sub
cd1.ShowOpen
Picture1.Picture = LoadPicture(cd1.FileName)
End Sub
Dim i As Integer
txtNumCluster.Enabled = False
totalData = totalData + 1
ReDim Preserve Data(0 To 2, 1 To totalData) ' notice: start with 0 for row
Data(1, totalData) = X
Data(2, totalData) = Y
'do k-mean clustering
Picture1.Cls
For i = 1 To totalData
colorCluster = Data(0, i) - 1
X = Data(1, i)
Y = Data(2, i)
Next i
'show centroid
Next i
End Sub
Dim i As Integer
For i = 1 To numCluster - 1
Unload lblCentroid(i)
Next i
numCluster = Int(txtNumCluster)
'Call cmdReset_Click
For i = 0 To numCluster - 1
lblCentroid(i).Caption = i + 1
lblCentroid(i).Visible = False
Next i
End Sub
End Sub
' ###################################################################
' FUNCTIONS
' + kMeanCluster:
' ###################################################################
' input: + Data matrix (0 to 2, 1 to TotalData); Row 0 = cluster, 1 =X, 2= Y; data in columns
Dim i As Integer
Dim j As Integer
Dim X As Single
Dim Y As Single
Dim d As Single
Dim sumXY()
isStillMoving = True
Else
Y = Data(2, totalData)
For i = 1 To numCluster
min = d
cluster = i
End If
Next i
Do While isStillMoving
For i = 1 To totalData
Next i
For i = 1 To numCluster
Next i
'assign all data to the new centroids
isStillMoving = False
For i = 1 To totalData
X = Data(1, i)
Y = Data(2, i)
For j = 1 To numCluster
min = d
cluster = j
End If
Next j
Data(0, i) = cluster
isStillMoving = True
End If
Next i
Loop
End If
End Sub
Function dist(x1 As Single, y1 As Single, X2 As Single, Y2 As Single) As Single
End Function
min2 = num1
Else
min2 = num2
End If
End Function