给定一组点,如何近似其形状的长轴?
给定用户绘制的“形状”,我想对其进行“标准化”,以便它们都具有相似的大小和方向。 我们拥有的是一组点。 我可以使用边界框或圆圈来近似大小,但方向有点棘手。
我认为正确的方法是计算其长轴 ="http://en.wikipedia.org/wiki/Bounding_volume" rel="nofollow noreferrer">边界椭圆。 为此,您需要计算 协方差矩阵。 这样做可能对我的需要来说太复杂了,因为我正在寻找一些足够好的估计。 选择最小、最大和 20 个随机点可能是一些入门。 有没有一种简单的方法可以近似这个?
Given a "shape" drawn by the user, I would like to "normalize" it so they all have similar size and orientation. What we have is a set of points. I can approximate the size using bounding box or circle, but the orientation is a bit more tricky.
The right way to do it, I think, is to calculate the majoraxis of its bounding ellipse. To do that you need to calculate the eigenvector of the covariance matrix. Doing so likely will be way too complicated for my need, since I am looking for some good-enough estimate. Picking min, max, and 20 random points could be some starter. Is there an easy way to approximate this?
Edit:
I found Power method to iteratively approximate eigenvector. Wikipedia article.
So far I am liking David's answer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您将计算 2x2 矩阵的特征向量,这可以通过一些简单的公式来完成,因此并不那么复杂。 在伪代码中:
如果您希望所选的点子集能够代表整个集合,您甚至可以通过仅对某些点求和来获得估计值来实现此目的。
编辑:我认为x和y必须转换为零均值,即首先从所有x、y中减去均值(eed3si9n)。
You'd be calculating the eigenvectors of a 2x2 matrix, which can be done with a few simple formulas, so it's not that complicated. In pseudocode:
You could even do this by summing over only some of the points to get an estimate, if you expect that your chosen subset of points would be representative of the full set.
Edit: I think x and y must be translated to zero-mean, i.e. subtract mean from all x, y first (eed3si9n).
这里有一个想法...如果您对这些点执行线性回归并使用结果线的斜率会怎样? 如果不是所有的点,至少是其中的一个样本。
r^2 值还会为您提供有关一般形状的信息。 越接近 0,形状越圆形/均匀(圆形/方形)。 越接近 1,形状越拉伸(椭圆形/矩形)。
Here's a thought... What if you performed a linear regression on the points and used the slope of the resulting line? If not all of the points, at least a sample of them.
The r^2 value would also give you information about the general shape. The closer to 0, the more circular/uniform the shape is (circle/square). The closer to 1, the more stretched out the shape is (oval/rectangle).
此问题的最终解决方案是运行 PCA
我希望我能找到一个不错的小实现供您参考......
The ultimate solution to this problem is running PCA
I wish I could find a nice little implementation for you to refer to...
干得好! (假设 x 是 nx2 向量)
Here you go! (assuming x is a nx2 vector)