计算不规则间距的累积点的方法

6
我正在尝试做与this相反的事情:给定一张二维图像(连续)强度,生成一组不规则间隔的积累点,即在二维地图上不规则覆盖的点,在强度高的区域彼此更接近(但不重叠!)。
我的第一次尝试是“加权”k-means。由于没有找到可行的加权k-means实现方式,我引入权重的方法是重复具有高强度的点。这是我的代码:
import numpy as np
from sklearn.cluster import KMeans

def accumulation_points_finder(x, y, data, n_points, method, cut_value):
    #computing the rms
    rms = estimate_rms(data)
    #structuring the data
    X,Y = np.meshgrid(x, y, sparse=False)
    if cut_value > 0.:
        mask = data > cut_value
        #applying the mask
        X = X[mask]; Y = Y[mask]; data = data[mask]
        _data = np.array([X, Y, data])
    else:
        X = X.ravel(); Y = Y.ravel(); data = data.ravel()
        _data = np.array([X, Y, data])

    if method=='weighted_kmeans':
        res = []
        for i in range(len(data)):
            w = int(ceil(data[i]/rms))
            res.extend([[X[i],Y[i]]]*w)
        res = np.asarray(res)
        #kmeans object instantiation
        kmeans = KMeans(init='k-means++', n_clusters=n_points, n_init=25, n_jobs=2)
        #performing kmeans clustering
        kmeans.fit(res)
        #returning just (x,y) positions
        return kmeans.cluster_centers_

这里有两个不同的结果:1)利用所有数据像素。2)仅利用高于某个阈值(RMS)的像素。

Without threshold

With threshold

正如您所看到的,这些点似乎比集中在高强度区域更加均匀分布。

因此,我的问题是是否存在一种(如果可能是确定性的)更好的方法来计算这样的积累点。

1个回答

1
使用四叉树(https://en.wikipedia.org/wiki/Quadtree)将数据分区成方差相等的单元(或者也可以利用浓度值?),使用定义好的阈值,然后在每个单元中保留一个点(质心)。在值快速变化的区域会有更多的细分,而在背景区域则会有较少的细分。

谢谢,这是一个好主意!我会学习这种方法,并尝试将其适应到我的需求中。 - mavillan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接