General approach for extracting specific lines or line segments in an image

你。 提交于 2020-01-02 08:13:08

问题


I have this sample cropped image:

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. Simple filtering of rows having more zeros/ones if image is read as NumPy array but the filtering condition doesn't terminate till a single row is left with zero or one.
  2. Erosion with simple kernel (3,3) but it leaves some noise because some symbols are also thick black
  3. Dilation with line structuring element of the width of image width but there are overwhelming variations on line segments' sizes connecting different symbols that the basic info about each small line segment is lost.

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:


回答1:


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.



来源:https://stackoverflow.com/questions/53294066/general-approach-for-extracting-specific-lines-or-line-segments-in-an-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!