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

mav*_*lan 5 python numpy scikit-learn

我试图做相反的事情:给定(连续)强度的2D图像,生成一组不规则间隔的累积点,即不规则地覆盖2D地图的点,在高强度区域彼此更接近(但没有重叠!).

我的第一次尝试是"加权"k-means.由于我没有找到加权k均值的工作实现,我引入权重的方式包括重复高强度的点.这是我的代码:

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_
Run Code Online (Sandbox Code Playgroud)

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

没有门槛

有门槛

正如您所看到的那样,点的间隔似乎比高强度区域更集中.

所以我的问题是,是否存在(确定性的,如果可能的话)更好的方法来计算这样的积累点.

Ben*_*min 1

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