删除图像中的所有水平和垂直线 [英] Remove all horizontal and vertical lines from an image

查看:100
本文介绍了删除图像中的所有水平和垂直线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除所有水平线和垂直线,但一些小垂直线没有被删除. 添加输入和输出图像以及下面的代码.

I want to remove all horizontal and vertical lines but some small vertical lines are not getting removed. Adding the input and output images and the code below.

            string ImageUrl = @"C:\Users\Jayant\Desktop\test images\rtaImage.tiff";
            Image<Bgr, Byte> image = new Image<Bgr, byte>(ImageUrl);
            Image<Bgr, byte> res = image.Copy();

            LineSegment2D[] lines =
                image
                    .Convert<Gray, byte>()
                    .Canny(16, 16)
                    .HoughLinesBinary(1, Math.PI / 16, 10, 50, 1)[0];

            foreach (LineSegment2D line in lines)
            {
                res.Draw(line, new Bgr(System.Drawing.Color.White), 2);
            }

            res.Save(ImageUrl);

我想删除所有水平线和垂直线,但一些小垂直线没有被删除. 添加以上代码的输入和输出.

I want to remove all horizontal and vertical lines but some small vertical lines are not getting removed. Adding the input and output of above code.

输入图片:

输入图片:

如果您发现某些垂直线没有被去除.我在Visual Studio中使用emgu.cv库,代码为C#.不使用emgu的任何解决方案也将不胜感激

If you notice some vertical lines did not get removed. I an using emgu.cv library in Visual Studio and the code is C# . Any solution without using emgu will also be appreciated

推荐答案

在Imagemagick中,您可以使用形态学关闭,但是必须将结果与原始组合起来才能删除线条.形态闭合使短的水平或垂直部分变成白色,而留下长的黑线.因此,结果必须取反并添加到原始结果中.重要的是使形态学线比最短的线段小,但比文本的任何部分长.因此,在下面,我将图像处理为垂直线并取反.然后对白色的水平线重复并取反.然后,我将两组线结合起来并将它们加在一起.最后,我将合并后的行添加到原始图像中.

In Imagemagick, you can use morphology close, but the result must be combined back with the original to remove the lines. The morphology close makes short horizontal or vertical segments white and leaves the long black lines. So the result must be negated and added to the original. It is important to make the morphology lines smaller than the shortest line segment, but longer than any parts of the text. So below, I process the image for the vertical lines and negate. Then repeat for the horizontal lines white and negate. Then I combine the two sets of lines and add them together. Finally I add the combined lines to the original image.

输入:

Imagemagick 6,Unix语法:

Imagemagick 6, Unix Syntax:

convert \( image.png -alpha off \) \
\( -clone 0 -morphology close rectangle:1x50 -negate +write tmp1.png \) \
\( -clone 0 -morphology close rectangle:50x1 -negate +write tmp2.png \) \
\( -clone 1 -clone 2 -evaluate-sequence add +write tmp3.png \) \
-delete 1,2 \
-compose plus -composite \
result.png


Imagemagick 6 Windows语法:


Imagemagick 6 Windows Syntax:

convert ( image.png -alpha off ) ^
( -clone 0 -morphology close rectangle:1x50 -negate +write tmp1.png ) ^
( -clone 0 -morphology close rectangle:50x1 -negate +write tmp2.png ) ^
( -clone 1 -clone 2 -evaluate-sequence add +write tmp3.png ) ^
-delete 1,2 ^
-compose plus -composite ^
result.png


tmp1(垂直线):


tmp1 (vertical lines):

tmp2(水平行):

tmp2 (horizontal lines):

tmp3(组合和取反的行):

tmp3 (combined and negated lines):

结果:

对于Imagemagick 7,请转换为magick.

For Imagemagick 7, change convert to magick.

您应该可以使用Magick.NET在Windows Imagemagick中执行此操作.参见 https://github.com/dlemstra/Magick.NET .但是我怀疑您的emgu.cv工具具有相同的形态学工具.

You should be able to do this in Windows Imagemagick with Magick.NET. See https://github.com/dlemstra/Magick.NET. But I suspect your emgu.cv tool has the same morphology tools.

这篇关于删除图像中的所有水平和垂直线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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