查找blob质心(质心)的算法是什么?
我找到了上面的等式,但我不知道如何将其翻译成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
答案 0 :(得分:3)
如果你查看你的代码,你会重复三次。首先是区域,第二个是Xs,第三个是Ys。其次,您的代码与您提供的等式不符。
尝试这样的事情:
For y = 0 To bmp.ScaleHeight - 1
For x = 0 To bmp.ScaleWidth - 1
If bmp.Point(x, y) = vbWhite
Then
Xs = Xs + x
Ys = Ys + y
area = area + 1
endIF
Next x
Next y
我不懂VB语法所以你必须稍微调整一下。
更新
要完成按区域规范化的算法:
Ys = Ys / area
Xs = Xs / area
答案 1 :(得分:0)
您的代码中有两个错误:
你写了
Xs = Xs + 1
而不是
Xs = Xs + X
2。同样的y
除此之外,代码很好