如何检测并纠正位图中的断线或形状?
我想找到一种可以在位图中找到断线或形状的算法。考虑这样一种情况,我有一个只有两种颜色的位图,背面和白色(用于着色书的图像),有一些曲线和线条应该相互连接,但由于一些扫描错误,白色位代替黑色的。我应该如何检测它们? (完成这项工作后,我想将位图转换为矢量文件。我想使用 potrace 算法)。
如果您有任何想法,请告诉我。
I want to find an algorithm which can find broken lines or shapes in a bitmap. consider a situation in which I have a bitmap with just two colors, back and white ( Images used in coloring books), there are some curves and lines which should be connected to each other, but due to some scanning errors, white bits sit instead of black ones. How should I detect them? (After this job, I want to convert bitmaps into vector file. I want to work with potrace algorithm).
If you have any Idea, please let me know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个修复小间隙的简单算法:
首先,使用一个过滤器,当其八个邻居中的任何一个为黑色时,该过滤器会创建一个黑色像素。这将扩大你的总体轮廓。
接下来,使用细化滤镜去除多余的轮廓,但保留填充的间隙。
有关一些过滤器和参数,请参阅本文:C# 中的图像处理实验室
Here is a simple algorithm to heal small gaps:
First, use a filter which creates a black pixel when any of its eight neighbors is black. This will grow your general outline.
Next, use a thinning filter which removes the extra outline but leaves the filled gaps alone.
See this article for some filters and parameters: Image Processing Lab in C#
最简单的方法是使用称为闭合的形态学技术。
仅当线条之间的间隙相对于不同线条之间的距离而言非常小时,此方法才有效。
如何选择结构元素来执行结束也会使性能更好或更差。
维基百科的文章非常理论(或数学),因此您可能需要求助于 Google 或任何有关图像处理的书籍,以更好地解释它是如何完成的。
The simplest approach is to use a morphological technique called closing.
This will work only if the gaps in the lines are quite small in relation to how close the different lines are to each other.
How you choose the structuring elemt to perform the closing can also make performance better or worse.
The Wikipedia article is very theoretical (or mathematical) so you might want to turn to Google or any book on Image Processing to get a better explanation on how it is done.
也许霍夫变换可以帮助你。奖励:您可以获得矢量文件的线条参数。
Maybe Hough Transform can help you. Bonus: you get the lines parameters for your vector file.