如何使图像的不连续轮廓一致? [英] How could I make the discontinuous contour of an image consistant?

查看:96
本文介绍了如何使图像的不连续轮廓一致?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在任务中,我得到了一个不连续的边缘图像,怎么能让它关闭?换句话说,使曲线连续。
形状可以是任何形状,导致这个coutour阴影。



解决方案

以下是一些可能让您入门的想法。我不喜欢在OpenCV中编写和调试大量的C ++ - 通常人们会提出问题而不会再次登录,或者你花费数小时处理某些事情,然后他们告诉你他们提供的单个样本图像根本不具代表性他们的实际图像以及花费25分钟解释的方法是完全不合适的。






一个想法是形态膨胀 - 您可以使用ImageMagick在命令行执行此操作:

 转换gappy.jpg -threshold 50%-morphology dilate disk :5 result.png 






另一个想法可能是找到具有Hit-and-Miss形态的所有line end像素。这在OpenCV中可用,但我使用ImageMagick来保存编码/调试。结构元素如下所示:





希望你可以看到第一个(最左边)结构元素代表东西线的西端,第二个代表南北线的北端,依此类推。如果你还没有得到它,最后一个是东北到西南线的西南端​​。



基本上,我发现线路结束了然后用蓝色像素扩大它们并将其叠加到原始像素上:

 转换gappy.jpg -threshold 50%\ 
\(+ clone -morphology hmt lineends -morphology dilate disk:1 -fill blue -opaque white -t​​ransparent black \)\
-flatten result.png



这是一个关闭 - 之前和之后:





然后你可以找到所有的山峰并用红色像素扩大它们:

 转换gappy.jpg -threshold 50%\ 
\(+ clone -morphology hmt Peaks:1.9 -fill red -morphology dilate disk:2 -opaque white -t​​ransparent black \)\
-flatten result.png



这是一个之前和之后的特写:





取决于你的原始ima ges看,你可以迭代地应用上面的想法直到你的轮廓是完整的 - 也许你可以通过洪水填充检测到你的轮廓保持水没有洪水填充到处都是泄漏



显然你会做红色的山峰而蓝色的线条都是白色的,以完成你的轮廓 - 我只是这样做用颜色来说明我的技巧。


In the task, I got an discontinuous edge image, how could make it closed? in other word make the curve continuous. And the shape could be any kind, cause this the coutour shadow.

解决方案

Here are a few ideas that may get you started. I don't feel like coding and debugging a load of C++ in OpenCV - oftentimes folks ask questions and never log in again, or you spend hours working on something and then they tell you that the single sample image they provided was not at all representative of their actual images and the method that it has taken 25 minutes to explain is completely inappropriate.


One idea is morphological dilation - you can do that at the command line like this with ImageMagick:

convert gappy.jpg -threshold 50% -morphology dilate disk:5 result.png


Another idea might be to locate all the "line end" pixels with Hit-and-Miss morphology. This is available in OpenCV, but I am doing it with ImageMagick to save coding/debugging. The structuring elements are like this:

Hopefully you can see that the first (leftmost) structuring element represents the West end of an East-West line, and that the second one represents the North end of a North-South line and so on. If you still haven't got it, the last one is the South-West end of North-East to South-West line.

Basically, I find the line ends and then dilate them with blue pixels and overlay that onto the original:

convert gappy.jpg -threshold 50%  \
   \( +clone -morphology hmt lineends -morphology dilate disk:1 -fill blue -opaque white -transparent black \) \
   -flatten result.png

Here's a close-up of before and after:

You can also find the singleton pixels with no neighbours, using a "peaks" structuring element like this:

and then you can find all the peaks and dilate them with red pixels like this:

convert gappy.jpg -threshold 50% \
    \( +clone -morphology hmt Peaks:1.9 -fill red -morphology dilate disk:2  -opaque white -transparent black \) \
    -flatten result.png

Here is a close-up of before and after:

Depending on how your original images look, you may be able to apply the above ideas iteratively till your contour is whole - maybe you could detect that by flood filling and seeing if your contour "holds water" without the flood fill "leaking" out everywhere.

Obviously you would do the red peaks and the blue line ends both in white to complete your contour - I am just doing it in colour to illustrate my technique.

这篇关于如何使图像的不连续轮廓一致?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆