0

标记图像

上图是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)
4

1 回答 1

1

您可以使用ndi.map_coordinates来查找图像中特定坐标(或坐标组)的值:

labels_at_coords = ndi.map_coordinates(
        labelledImage, np.transpose(list), order=0
        )

笔记:

  • 坐标数组需要是 shape (ndim, npoints),而不是有时更直观的(npoints, ndim),因此是转置。
  • 理想情况下,最好将您的点列表重命名为points_list,这样您就不会覆盖 Python 内置函数list
于 2020-11-25T02:15:06.443 回答