为 ndimage.center_of_mass 粒子跟踪创建圆形补丁

问题描述

我正在对多个图像帧(我的代码中的索引 g)进行粒子跟踪。我已将图像格式化为像素值网格(请参阅下面的一帧)。我一直在尝试使用 scipy.ndimage.center_of_mass 编写一个质心算法来获取一帧中所有粒子的中心(在 x,y 中)。我已经在程序的早期确定了每个帧的峰值亮度点,并将这些坐标作为 x_matchy_match 二维数组传递给我的 patches 函数。基本上,我试图用补丁实现的是使用峰值作为猜测坐标,并在给定像素半径值的情况下,环顾这些猜测,然后使用 ndimage.label 创建标签。在我的代码中,unfiltered 是我作为像素网格传递给函数的图像帧

帧示例:https://imgur.com/a/V9H2ZAM

现在,我的代码只是为每个粒子创建一个补丁,但我的问题是我无法弄清楚如何将圆形补丁映射回适当的坐标,以便我可以通过等效形状的 unfiltered[g]以及 labels 函数中的 center_of_masscentroid

# centroiding functions
x_match = col_match # switching the Syntax to cartesian vernacular for ease of comprehension
y_match = row_match

def patches(unfiltered,centers,radius=2): # centers has type (x_match,y_match)
    all_patches = []
    for g in range(np.shape(unfiltered)[0]):
        patches = []
        for i in range(len(centers[0][g])): # iterates over number of matches in frame g
            center = (centers[0][g][i],centers[1][g][i])
            x_lims = (center[0]-radius,center[0]+radius+1)
            y_lims = (center[1]-radius,center[1]+radius+1)
            y,x = np.ogrid[y_lims[0]:y_lims[1],x_lims[0]:x_lims[1]]
            dist_from_center = np.sqrt((x - center[0])**2 + (y-center[1])**2)
            patch = dist_from_center <= radius
            patches.append(patch)
        patches = np.array(patches)
        all_patches.append(patches)
    return all_patches

def centroid(unfiltered,x,y,r):
    all_blobs = blobber(unfiltered,(x,y),radius=r)
    CM_X,CM_Y = [],[]
    for g in range(np.shape(unfiltered)[0]):
        labels,nlabels = label(all_patches[g])
        cm_y,cm_x = np.vstack(center_of_mass(unfiltered[g],labels,np.arange(nlabels) + 1)).T
        CM_X.append(cm_x)
        CM_Y.append(cm_y)
    return CM_X,CM_Y

我想实现的目标与这篇博文 How to locate a particular "region" of values in a 2D numpy array? 非常相似,但我想在每个粒子周围创建圆形补丁,而不是像答案中描述的那样创建斑点。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)