Efficient method of calculating density of irregularly spaced points

后端 未结 6 457
孤街浪徒
孤街浪徒 2020-12-04 05:54

I am attempting to generate map overlay images that would assist in identifying hot-spots, that is areas on the map that have high density of data points. None of the approa

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-04 06:26

    This approach is along the lines of some previous answers: increment a pixel for each spot, then smooth the image with a gaussian filter. A 256x256 image runs in about 350ms on my 6-year-old laptop.

    import numpy as np
    import scipy.ndimage as ndi
    
    data = np.random.rand(30000,2)           ## create random dataset
    inds = (data * 255).astype('uint')       ## convert to indices
    
    img = np.zeros((256,256))                ## blank image
    for i in xrange(data.shape[0]):          ## draw pixels
        img[inds[i,0], inds[i,1]] += 1
    
    img = ndi.gaussian_filter(img, (10,10))
    

提交回复
热议问题