简体   繁体   English

查找形状边界上的点坐标

[英]Finding coordinates of points on the border of a shape

Let's say I have a shape like this: 假设我有这样的形状:

在此输入图像描述

After all the jokes of me wanting to draw beans are exhausted, I want to find the points on the border of the shape. 在我想要画豆子的所有笑话都筋疲力尽之后,我想找到形状边界上的点。 I know there can be many, so a fair distance between them is accepted. 我知道可以有很多,所以它们之间的距离是可以接受的。

Is there an algorithm for such a need? 是否有针对这种需求的算法? Or a software? 还是一个软件? All the solutions I came up with involve a lot of manual work, especially if I want to draw a slightly different shape. 我提出的所有解决方案都涉及大量的手工工作,特别是如果我想绘制略微不同的形状。

Stackoverflow wisdom, please help. Stackoverflow智慧,请帮忙。

You may simply scan the pixels horizontally and vertically to find color frontiers, or, if you want a more sophisticated and general solution, you may for example use the gradient method to detect edges: 您可以简单地水平和垂直扫描像素以找到颜色前沿,或者,如果您想要更复杂和通用的解决方案,您可以使用gradient method来检测边缘:

在此输入图像描述

Edit 编辑

Answering your comment, the image is just a bi-dimensional array, containing pixel values. 回答你的评论,图像只是一个包含像素值的二维数组。 You can test each pixel and select those having a specific color. 您可以测试每个像素并选择具有特定颜色的像素。 Like this: 像这样:

在此输入图像描述

And the result are your edge pixels: 结果是你的边缘像素:

{{35, 107}, {35, 108}, {35, 109}, {35, 110}, {35, 111},
 {35, 112}, {35, 113}, {35, 114}, {35, 115}, {35, 116},
 {35, 117}, {35, 118}, {35, 119}, {35, 120}, {35, 121},
 {36, 103}, {36, 104}, {36, 105}, {36, 106}, {36, 107}, etc....

It sounds like you're looking for "vectorization", or more precisely "bitmap vectorization". 听起来你正在寻找“矢量化”,或者更准确地说是“位图矢量化”。 If you vectorize your bitmap, you'll get vector version of your shape, which will give you all the boundary coordinates. 如果您对位图进行矢量化,您将获得形状的矢量版本,它将为您提供所有边界坐标。

If so, there are a number of solutions available, including AutoTrace: http://autotrace.sourceforge.net/ 如果是这样,有许多解决方案,包括AutoTrace: http//autotrace.sourceforge.net/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM