【发布时间】:2022-01-20 05:27:53
【问题描述】:
我有一个 1000x1000 的 2D numpy 数组,可以将其视为图像的像素。没有形状的单元格为 0,形状为某个值,表示强度的值。可以这样绘制:
plt.matshow(data, origin='lower')
当只考虑超过某个阈值的数据时,可以将数据视为形状,如下所示:
fig, ax = plt.subplots()
cluster_contour_threshold = 60
y,x = np.argwhere(data > cluster_contour_threshold).T
ax.scatter(x, y)
ax.set_xlim((0, 1000))
ax.set_ylim((0, 1000))
我想要的是获取代表此形状轮廓的坐标列表。像这样的:
[
[x0,y0],
[x1,y1],
[x2,y2]
]
到目前为止,我最好的尝试是使用 canny,但这并不完全正确:
from skimage import feature
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
c = feature.canny(data)
y,x = np.argwhere(c).T
ax.scatter(x, y)
ax.set_xlim((0, 1000))
ax.set_ylim((0, 1000))
【问题讨论】:
-
我想只是
points = np.argwhere(c)? -
这会给你所有有数据的点,而不是轮廓。