I have a 2D Numpy array of the following form (up to 5000 rows):
我有一个以下形式的2D Numpy数组(最多5000行):
[ 247.68512 182.67136]
[ 248.71936 182.67136]
[ 249.74336 182.67136]
[ 253.85984 269.1072 ]
[ 254.89408 269.1072 ]
[ 255.91808 269.1072 ]
[ 249.74336 182.67136]
[ 250.7776 182.67136]
[ 251.8016 182.67136]
...
Where column 0 corresponds to x, and column 1 to y.
其中第0列对应x,第1列对应y。
When plotted the data should resemble a blob shape.
绘制时,数据应类似于blob形状。
How can I reduce this data to just have the edge or contour around the blob?
如何将这些数据减少到只有blob周围的边缘或轮廓?
I have looked at some of the skimage edge detection functions but I think there is a pure numpy solution out there.
我已经看过一些skimage边缘检测功能,但我认为那里有一个纯粹的numpy解决方案。
Any help? If edge detection is the way to go what's the best tool?
有帮助吗?如果边缘检测是最好的工具吗?
Thanks
谢谢
--- Edit ---- The data is also unsorted, but I can sort around the orgin of the blob with some existing code I have. Not sure if that helps.
---编辑----数据也是未分类的,但我可以用我现有的一些代码对blob的orgin进行排序。不确定这是否有帮助。
--- Edit 2 --- Stumbled upon this beautiful solution by K.D.
---编辑2 ---偶然发现K.D.的这个美丽的解决方案。
I think this should work perfectly for this application. Will try this.
我认为这应该适合这个应用程序。会尝试这个。
1 个解决方案
#1
2
It depends on the topology of the blob. If the blob is smooth and has no voids inside you can do this: approach blob from far. Scan across blob location. When you hit a point - check neighboring grid. If you have high enough point density set isOnBorder = true
. Now, for each neighboring point check if it is such that it has both empty and filled neighbors. If yes - this is a border point - add it to list. Repeat procedure until you get full border. If you have voids you would have to do grid inside and check for inner borders as well.
它取决于blob的拓扑结构。如果blob是光滑的并且内部没有空隙,你可以这样做:从远处接近blob。扫描blob位置。当你到达一个点 - 检查相邻的网格。如果你有足够高的点密度,则设置isOnBorder = true。现在,对于每个相邻点,检查它是否具有空的和填充的邻居。如果是 - 这是边界点 - 将其添加到列表中。重复此过程,直到获得完整边框。如果你有空洞,你必须在里面做网格并检查内部边界。
#1
2
It depends on the topology of the blob. If the blob is smooth and has no voids inside you can do this: approach blob from far. Scan across blob location. When you hit a point - check neighboring grid. If you have high enough point density set isOnBorder = true
. Now, for each neighboring point check if it is such that it has both empty and filled neighbors. If yes - this is a border point - add it to list. Repeat procedure until you get full border. If you have voids you would have to do grid inside and check for inner borders as well.
它取决于blob的拓扑结构。如果blob是光滑的并且内部没有空隙,你可以这样做:从远处接近blob。扫描blob位置。当你到达一个点 - 检查相邻的网格。如果你有足够高的点密度,则设置isOnBorder = true。现在,对于每个相邻点,检查它是否具有空的和填充的邻居。如果是 - 这是边界点 - 将其添加到列表中。重复此过程,直到获得完整边框。如果你有空洞,你必须在里面做网格并检查内部边界。