尋找斑點質心(質心)的算法是什麼?查找斑點質心
我發現上面的公式,但我不知道如何把它翻譯成VB 6.0。我在網上查找了一個簡單的質心算法在VB 6.0中,但我沒有找到一個計算X和Y座標的值。
我試圖在VB6.0中做上述算法。然而,它總是給1
爲中心:
Private Sub FindCentroid(bmp As PictureBox)
Dim area As Double
Dim x As Integer, y As Integer
Dim Xc, Yc, Xs, Ys As Integer
area = 0
For y = 0 To bmp.ScaleHeight - 1
For x = 0 To bmp.ScaleWidth - 1
If bmp.Point(x, y) = vbWhite Then area = area + 1
Next x: Next y
Xs = 0
For y = 0 To bmp.ScaleHeight - 1
For x = 0 To bmp.ScaleWidth - 1
If bmp.Point(x, y) = vbWhite Then Xs = Xs + 1
Next x
Next y
Ys = 0
For y = 0 To bmp.ScaleWidth - 1
For x = 0 To bmp.ScaleHeight - 1
If bmp.Point(y, x) = vbWhite Then Ys = Ys + 1
Next x
Next y
Xc = Xs/area
Yc = Xs/area
End Sub
你能解釋一下什麼是困難?這很簡單,只需找到x和y座標的平均值(在blob像素上) –
@OphirGvirtzer我附加了VB6代碼,質心總是1.你能修復代碼 – user3819984