【问题标题】:Testing if a point lies within a labeled object with scipys ndi.label()使用 scipys ndi.label() 测试一个点是否位于标记对象内
【发布时间】:2021-03-07 02:44:32
【问题描述】:

上面是一张经过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)

【问题讨论】:

  • 坐标是如何存储的?标记的图像是一个 numpy 数组吗?你能展示生成它的代码吗?
  • @user13044086 图片是一个numpy数组,这是通过skimage默认的。坐标存储在一个列表位置,这样:对于 i 对坐标:x, y = list[i]
  • 你能检查给定坐标的 labelledImage 的所有元素是否相同吗?像这样:[labelledImage[y, x] for x, y in list] 然后检查 ell 元素是否相同

标签: python matplotlib scipy scikit-image ndimage


【解决方案1】:

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

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

注意事项:

  • 坐标数组的形状必须是 (ndim, npoints),而不是有时更直观的 (npoints, ndim),因此需要转置。
  • 理想情况下,最好将您的积分列表重命名为 points_list 之类的名称,这样您就不会覆盖 Python 内置函数 list

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-27
    • 2021-02-16
    • 1970-01-01
    • 2018-09-29
    • 1970-01-01
    相关资源
    最近更新 更多