【问题标题】:How can I automatically identify multiple lines in an image?如何自动识别图像中的多条线?
【发布时间】:2018-03-26 13:22:12
【问题描述】:

给定一个包含斜线的二进制图像,我如何自动识别尽可能多的线?使用 Matlab 中的bwtraceboundary 函数,我已经能够识别其中之一,手动提供识别线的起始坐标。

谁能指出一种循环 1 和 0 矩阵以自动识别尽可能多的方法?

这是一个示例图像:

% Read the image
I = imread('./synthetic.jpg');


figure(1)
BW = im2bw(I, 0.7);
imshow(BW2,[]);
c = 255; % X coordinate of a manually identified line
r = 490; % Y coordinate of a manually identified line
contour = bwtraceboundary(BW,[c r],'NE',8, 1000,'clockwise');
imshow(BW,[]);
hold on;
plot(contour(:,2),contour(:,1),'g','LineWidth',2); 

从上面的代码我们得到:

【问题讨论】:

  • 咳咳咳咳*! (线的霍夫变换)
  • 在我提供的图像中使用霍夫变换是否可以有一个最小的可重现示例?否则,您能否指出任何有用的信息来源?谢谢
  • Hum.... 从字面上看,“Hough tranform for lines”为您提供了一个完整的 Google 教程,由 Mathworks 提供,使用 houghlines 函数....

标签: image matlab image-processing


【解决方案1】:

这是一个关于如何在 MATLAB 中对线条使用 Hough 变换的小示例,并对您的图像进行了一些去噪处理。

此代码不会检测所有行,您可能需要对其进行调整/更改一些,这需要了解发生了什么,这超出了 StackOverflow 的范围。也许有更多知识的人可以找到更好的方法:

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

I = imgaussfilt(I,1);
I=I([90:370],:);
BW = edge(I,'canny');
[H,T,R] = hough(BW);
P  = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
lines = houghlines(BW,T,R,P,'FillGap',5,'MinLength',3);

figure, 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','yellow');
   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

【讨论】:

  • 谢谢。这实际上使我能够完成 Codementor 合同:P +1。
  • @rayryeng 我的MONYZ在哪里:P
猜你喜欢
  • 2011-03-16
  • 2012-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-16
  • 1970-01-01
相关资源
最近更新 更多