如何在点集/ 2D形状中找到“中心”锚点?

时间:2014-02-18 23:19:30

标签: algorithm set 2d

Point-Set

2D体素的中心坐标表示2D点集。使用这些坐标,图中的红点指的是(近似的)质心/重心,即所有坐标的平均值。忽略不同的灰度值,尽管它们巧合地提供了2D体素的稍微更好的可见性: - )

绿点(大致)是我想要的,但是如何(?),以原则的方式(?)。所以基本上我们在2D体素空间中有一个连通集,或者一组2D点,如果它有帮助,可以假设整数坐标。我想确定一个关于形状的“中心”点,但肯定是在形状上,即集合的一部分。

Pseudocode和/或C / C ++欢迎: - )

更新:如果结构更厚,我实际上更喜欢绿点而不是轮廓。

1 个答案:

答案 0 :(得分:0)

这里是可以找到O(N)中的绿点的解决方案: -

Find mean (xm,ym)

Suppose (xm+a),(ym+b) is a point in the dataset

E(xi,yi) = sum of squared distances of all points from (xi,yi)

E(xm,ym) = k   because it is the mean.

E(xm+a,ym+b) = summation => (xi-(xm+a))^2 + (yi-(ym+b))^2

             = summation => ((xi-xm)-a)^2 + ((yi-ym)-b)^2

             = summation => (xi-xm)^2 + (yi-ym)^2 + a^2 + b^2 - 2a*(xi-xm) - 2b*(yi-ym)

             = summation => (xi-xm)^2 + (yi-ym)^2 + summation => a^2 + b^2 +.....

   summation => (xi-xm)^2 + (yi-ym)^2 = E(xm,ym) = k

Hence

E(a,b) = summation => a^2 + b^2 - 2a*(xi-xm) - 2b*(yi-ym)

as a,b are constant in summation

E(a,b) = (a^2+b^2)*N - 2a*(summation=>(xi-xm)) - 2b*(summation=>(yi-ym))

summation=>(xi-xm) = 0
summation=>(y1-ym) = 0

E(a,b) = a^2 + b^2

Now to get green point which will minimize E(a,b)

a = xk-xm
b = yk-ym 

find (xp,yp)=>minimum{E(a,b)}  among all (xk,yk)

summation=>(xi-xm) and summation=>(yi-ym) can be found in O(N) after finding mean

hence E(a,b) can be found in O(1) and (xp,yp) in O(N)