Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 如何删除水平线和垂直线_Matlab_Image Processing - Fatal编程技术网

Matlab 如何删除水平线和垂直线

Matlab 如何删除水平线和垂直线,matlab,image-processing,Matlab,Image Processing,我需要删除二进制图像中的水平线和垂直线。有没有过滤这些行的方法bwareaopen()不是移除这些线的好方法,而且膨胀和侵蚀对这些情况也不好。 有人知道解决办法吗 示例图像: 编辑:(添加了更多示例图像: 图像的源文件: www.directexe.com/9cg/pics.rar您可以首先找到水平线和垂直线。因为,边缘映射也是二进制的,所以您可以在图像之间执行逻辑减法运算。要找到垂直线,可以使用(在MATLAB中) 对于水平线,可以使用 % Generate horizontal edg

我需要删除二进制图像中的水平线和垂直线。有没有过滤这些行的方法
bwareaopen()
不是移除这些线的好方法,而且膨胀和侵蚀对这些情况也不好。 有人知道解决办法吗

示例图像:

编辑:(添加了更多示例图像:

图像的源文件:


www.directexe.com/9cg/pics.rar

您可以首先找到水平线和垂直线。因为,边缘映射也是二进制的,所以您可以在图像之间执行逻辑减法运算。要找到垂直线,可以使用(在MATLAB中)

对于水平线,可以使用

% Generate horizontal edge emphasis kernel
h = fspecial('sobel');

% invert kernel to detect vertical edges
h = h';

J = imfilter(I,h);

使用
regionprops
删除偏心率高(表示该区域又长又薄)且方向接近0度或90度(垂直或水平区域)的区域

代码:

img = im2double(rgb2gray(imread('removelines.jpg')));

mask = ~im2bw(img);

rp = regionprops(mask, 'PixelIdxList', 'Eccentricity', 'Orientation');

% Get high eccentricity and orientations at 90 and 0 degrees
rp = rp([rp.Eccentricity] > 0.95 & (abs([rp.Orientation]) < 2 | abs([rp.Orientation]) > 88));

mask(vertcat(rp.PixelIdxList)) = false;

imshow(mask);
img=im2double(rgb2gray(imread('removelines.jpg'));
掩码=~im2bw(img);
rp=区域属性(遮罩、“像素idxlist”、“偏心率”、“方向”);
%在90度和0度时获得较高的偏心率和方向
rp=rp([rp.偏心率]>0.95&(abs([rp.方向])<2 | abs([rp.方向]>88));
遮罩(vertcat(rp.PixelIdxList))=假;
imshow(mask);
输出:


如果所有图像的水平线和垂直线接触边框的位置相同,只需调用即可完成此操作。
imclearborder
将删除任何接触图像边框的对象像素。您需要反转图像,使字符为白色,背景为黑色,然后重新输入返回,但我假设这不是问题。但是,为了确保没有任何实际字符被删除,因为它们可能也会接触到边框,可能需要谨慎地使用单像素厚度人为填充图像的上边框,清除边框,然后重新操作

im = imread('http://i.stack.imgur.com/L1hUa.jpg'); %// Read image directly from StackOverflow

im = ~im2bw(im); %// Convert to black and white and invert
im_pad = zeros(size(im,1)+1, size(im,2)) == 1; %// Pad the image too with a single pixel border
im_pad(2:end,:) = im;

out = ~imclearborder(im_pad); %// Clear border pixels then reinvert
out = out(2:end,:); %// Crop out padded pixels

imshow(out); %// Show image
我们得到这个:


你试过了吗?我怀疑这对粗线条有效,因为边缘检测器不是线条检测器。它们可以找到不同灰度之间的过渡。因此,你不会删除整条线条,因为线条内部不会改变颜色。此外,你还可以检测到沿字母的任何垂直或水平渐变,而这些渐变不会改变颜色想要触摸。这只会发现边缘,而不是线条。但是,如果线条是单像素厚,这可能会起作用,但对于可变厚度的线条,这只会检测线条的周长。在这种情况下,我看不出这对这个问题有何作用。我采用了相同的方法。比形态学方法更有效。亲爱的@jucestain,我真的很感谢你为我所做的一切。我如何更改你的代码以消除我添加到问题中的这些示例的噪音?请看示例并帮助我更多。非常感谢。@KaroAmini提供了这些数据集,你能始终将字母周围的边框完全去掉吗?如果是,你应该能够确定通过使用非常大的
边界框
凸面
数量来删除区域,以去除边界。另外,仅供参考,但有一种很酷的方法描述了直接检测字母的方法。这可能也有帮助。@karoamin基本上,您需要确定是要检测并删除非字母,还是要检测let直接删除并删除所有其他内容。亲爱的@jucestain,由于各种图片,我无法裁剪字母或边框。在这一步中,我想消除噪音,下一步通过OCR提取和读取字母,实际上主要目标是检测和提取字母。这可能会给你一些想法。请注意,霍夫变换不是必需的我想让这个想法起作用。这个想法是一般性的。谢谢亲爱的@kkuilla的建议,但是hough transform对我的工作来说太慢了。是的,但是你不需要hough transform来实现这个想法。这个想法是,你在你的所有片段上都拟合一条直线,并删除那些不是直线的。谢谢你,先生@rayryeng你总是帮助我解决我的问题s、 我添加了更多的示例图像,如何更改您的代码以消除这些图像的二进制噪声?我非常感谢您为我所做的一切。@KaroAmini-这些图像与您原来的问题大不相同。首先,存在大量噪声。我必须重新制定我的问题,以适应您上传的ose图像。我在这个链接中单独上传了这些图像:,我真的很感谢您。@KaroAmini-不幸的是,这不是当前的优先事项。当我开始讨论时,我会尝试重新处理这个问题,以便更适合您的数据。谢谢您。真的谢谢您亲爱的先生@rayryeng
im = imread('http://i.stack.imgur.com/L1hUa.jpg'); %// Read image directly from StackOverflow

im = ~im2bw(im); %// Convert to black and white and invert
im_pad = zeros(size(im,1)+1, size(im,2)) == 1; %// Pad the image too with a single pixel border
im_pad(2:end,:) = im;

out = ~imclearborder(im_pad); %// Clear border pixels then reinvert
out = out(2:end,:); %// Crop out padded pixels

imshow(out); %// Show image