
上图是一个已经通过ndi.label()并用matplotlib显示的图像,每个彩色区域代表一个不同的特征。在图像顶部绘制的是红色的点,每个点代表一对坐标。所有坐标都会存储,ndi.label会返回要素的数量。skimage、scipy或ndimage是否有一个函数可以测试给定的一组坐标是否位于标记的特征中?
最初,我打算使用每个功能的绑定框(左、右、上、下),但由于区域并不都是四边形的,这将不起作用。
生成图像的代码:
image = io.import("image path")
labelledImage, featureNumber = ndi.label(image)
plt.imshow(labelledImage)
for i in range(len(list))
y, x = list[i]
plt.scatter(y,x, c='r', s=40)发布于 2020-11-25 10:15:06
您可以使用ndi.map_coordinates查找图像中特定坐标(或坐标组)处的值:
labels_at_coords = ndi.map_coordinates(
labelledImage, np.transpose(list), order=0
)备注:
Python坐标数组的形状需要为(ndim, npoints),而不是有时更直观的(npoints, ndim),因此,最好将点列表重命名为类似于points_list的名称,这样就不会覆盖Python内置函数list.
https://stackoverflow.com/questions/64984444
复制相似问题