提取图像中特定线或线段的通用方法 [英] General approach for extracting specific lines or line segments in an image

查看:137
本文介绍了提取图像中特定线或线段的通用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这张裁剪的样本图像:

I have this sample cropped image:

我需要使黑色粗线(水平和垂直)消失或提取,同时保留所有其他信息.这些特定的行是4像素或5像素厚.我试过了:

I need to make black thick lines (horizontal and vertical) disappear or extracted while leave all other info intact. These specific lines are either 4 or 5 pixels thick. I tried:

  1. 如果将图像读取为NumPy数组,则对具有更多零/一的行进行简单过滤,但是直到单行中留有零或一时,过滤条件才会终止.
  2. 具有简单内核(3,3)的侵蚀,但由于某些符号也为黑色而留下了一些噪音
  3. 与图像宽度宽度的线结构元素相乘,但连接不同符号的线段尺寸存在巨大变化,从而丢失了有关每个小线段的基本信息.

有人可以提供关于什么类型的结构元素,应该考虑哪种类型的形态学操作的见解或指导,或者可以是其他任何巧妙的启发式方法?如果完成了粗黑线的提取的输出,则看起来将像下面这样的随机线段网格:

Can someone give insights or directions about what kind of structuring elements, what type of morphological ops should be considered or may be any other clever heuristics? The output, if extraction of thick black lines is done, will then look like this grid of random line segments:

推荐答案

这是侵蚀图像并提取轮廓线的方法:

This is how you erode the image and extract hough lines:

I=rgb2gray(imread('https://i.stack.imgur.com/cbHFL.jpg'));

Ibw=I>200;

imshow(Ibw)
SE=strel('disk',1)
Ier=imerode(~Ibw,SE);

[H,T,R] = hough(Ier);
P  = houghpeaks(H,100,'threshold',ceil(0.1*max(H(:))));

lines = houghlines(Ier,T,R,P);

%% plot
imshow(I);hold on
max_len = 0;
for k = 1:length(lines)
   xy = [lines(k).point1; lines(k).point2];
   plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');

   % Plot beginnings and ends of lines
   plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','blue');
   plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');

   % Determine the endpoints of the longest line segment
   len = norm(lines(k).point1 - lines(k).point2);
   if ( len > max_len)
      max_len = len;
      xy_long = xy;
   end
end

从这里开始,您可以考虑删除什么.除非您有一个符号字典,例如如何删除具有>-<形状的结构周围的线?删除所有中间像素还是保留整个中间细条?仅当您知道没有粗线的符号应该如何时,您才能知道这一点.

From here, you can start thinking on what to delete. This is not straightforward unless you have a dictionary of symbols, e.g. how do you delete the line around the structures with >-< shape? do you delete all the middle pixels or do you keep the entire middle thin bar? You can only know this if you know how the symbol should be without the thick lines.

这篇关于提取图像中特定线或线段的通用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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