聚类像素凝块
计算科学
聚类
2021-12-17 08:37:30
1个回答
如果集群的数量是已知的(像这里)
您可以使用 Lloyd 的聚类 [1]
思路如下:优化一组聚类中心:
Initialize the p_i's with an initial guess, or randomly
For each iteration:
Compute the cluster associated with each p_i,
(the cluster is the set of points nearer to p_i than to the other p_j's)
Move each p_i to the weighted centroid of its cluster
对于图像,迭代可以如下实现,计算每个簇的质量 m_i 和质心 g_i:
For each i
m_i = 0
g_i = (0,0)
For each pixel (x,y) of the image
let i denote the index of the center p_i nearest to (x,y)
m_i = m_i + pixel_intensity(x,y)
g_i = g_i + pixel_intensity(x,y) * (x,y)
For each i
p_i = (1/m_i)*g_i
由于集群的数量很少,您可以使用简单的循环找到最近的 p_i。如果您有更多的站点,您可以使用 kd-tree,或者计算站点的 Voronoi 图并迭代每个 Voronoi 单元的像素。
我使用该算法对由乐高颜色传感器获取的 rubics 立方体的颜色进行聚类,它工作得相当好,同时非常容易实现 [3]
如果集群的数量未知 ,那么问题就困难得多。
您可以使用“均值偏移聚类”[2],它将对图像应用类似过滤器的操作,并使“模式”出现。它的作用类似于平滑滤波器的逆。
[1] https://en.wikipedia.org/wiki/Lloyd%27s_algorithm
其它你可能感兴趣的问题

