问题描述
请看下面的图片A。
我的问题的一些介绍:
我的目标是获得图示 DNA 分子的准确坐标轨迹。轨迹的坐标由图像中的蓝点表示,并在 Python 中表示为二维 numpy 数组,即:trace: nd-array; shape (N,2)
其中 N 是轨迹点的数量。绘图是使用 plt.scatter(trace[:,1],trace[:,0])
完成的。
现在,请仔细看看以下函数:
def rel_coords_to_trace(trace,distance_limit=5.0):
"""
Finds the pixels in the image that are within the 'distance_limit' of the 'trace' points. For those pixels the
relative coordinates to the closest trace point is calculated.
Args:
trace ([N,2] array): Initial trace of the DNA strand
distance_limit (float): Maximum distance a pixel can have from the trace to be taken into account
Returns:
pixels: Array with row/column coordinates of the pixels within the distance limit from the trace
trace_id: Int relating each pixel from the 'pixels' array to the point in the 'trace' it is closest to
relative_coords ([N,2] array): Relative x and y distances of all pixels from the closest point of the trace
heights([N,] array): Height of the image at the position of the pixel
"""
min_r,min_c = np.floor(trace.min(axis=0) - distance_limit).astype(int).clip(min=0)
max_r,max_c = np.ceil(trace.max(axis=0) + distance_limit).astype(int).clip(max=mol_filtered.shape)
pixels_pos = np.mgrid[min_r:max_r,min_c:max_c].reshape([2,-1]).T # all potential pixels
# kdTree finds the nearest neighbour between a specific pixel and all trace points
# Returns distances between pixels and nn and the id of the nn. distances are inf if bigger than distance_limit
kdtree = cKDTree(trace)
distances,trace_id = kdtree.query(pixels_pos,k=1,distance_upper_bound=distance_limit)
pixels = pixels_pos[distances != np.inf]
trace_id = trace_id[distances != np.inf]
rel_coords = pixels - trace[trace_id]
return rel_coords,pixels,trace_id
它的执行如图 B 我的问题: 现在,当我在坐标轨迹中急转 时,我会得到相对较多的白色箭头,这些箭头或多或少指向一个方向的特定轨迹点。我的目标是量化与轨迹的另一侧相比,从轨迹的一侧(在与轨迹垂直的方向上)指向的白色箭头有多少。这种量化不一定是精确的,我只是想以某种方式在混合中添加相应的权重。
我怎样才能实现这种量化?