本文介绍了寻找斑点质心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是算法找到一个blob的质心(重心)?

我发现上面的公式,但我不知道如何把它翻译成VB 6.0。我看了网上的VB 6.0一个简单的心算法,但我没有找到一个计算X的值和Y坐标。

我试图做上述算法中的VB6.0。然而,它总是给 1 为中心的:

 私人小组FindCentroid(BMP作为图片框)

昏暗的区域作为双
昏暗x As中整数,y为整数
朦胧XC,YC,两个X,伊苏作为整数

面积= 0
对于Y = 0要bmp.ScaleHeight  -  1
    对于x = 0到bmp.ScaleWidth  -  1
如果bmp.Point(X,Y​​)= vbWhite然后面积=面积+ 1

下一页X:下一步ÿ

XS = 0
对于Y = 0要bmp.ScaleHeight  -  1
    对于x = 0到bmp.ScaleWidth  -  1
        如果bmp.Point(X,Y​​)= vbWhite然后两个X =两个X + 1个
 下一个x
接下来ÿ

伊苏= 0

对于Y = 0要bmp.ScaleWidth  -  1
    对于x = 0到bmp.ScaleHeight  -  1

        如果bmp.Point(Y,X)= vbWhite然后伊苏=伊苏+1

下一个x
接下来ÿ

XC = XS /地区
YC = XS /地区

结束小组
 

解决方案

如果你看看你的code你重复自己的三倍。首先对区域,第二个为两个X和第三的伊苏。第二你code没有您提供的公式匹配。

尝试是这样的:

 对于Y = 0要bmp.ScaleHeight  -  1
  对于x = 0到bmp.ScaleWidth  -  1
    如果bmp.Point(X,Y​​)= vbWhite
      然后
        XS = XS + X
        伊苏=伊苏+ Y
        面积=面积+ 1
    ENDIF
  下一个x
接下来ÿ
 

我不知道VB的语法,所以你必须来调整一下。

更新

要完成该算法通过标准化领域:

 伊苏= YS /地区
XS = XS /地区
 

What is the algorithm for finding a blob's centroid (center of mass)?

I found the above equation but I don't know how to translate it into VB 6.0. I looked online for a simple centroid algorithm in VB 6.0, but I did not find one that calculates the value of X and Y coordinates.

I tried to do the above algo in VB6.0. However, it always gives 1 as the center.:

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
解决方案

If you look at your code you repeat yourself three times. First for area, second for Xs, and third for Ys. Secondly your code does not match the equation you provided.

Try something like this:

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

I don't know VB syntax so you'll have to adjust that a bit.

UPDATE

To complete the algorithm normalize by area:

Ys = Ys / area
Xs = Xs / area

这篇关于寻找斑点质心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 03:07