【发布时间】:2016-12-06 12:30:49
【问题描述】:
我正在学习 hough 和 houghlines 如何在 MATLAB 中工作,但即使对于我在 Paint 中绘制的 simple line,我似乎也无法使函数文档中的示例代码正常运行。
这是我正在使用的代码:
clear all; clc; close all
I = imread('lines2.png');
BW = im2bw(I);
[H,T,R] = hough(BW,'Theta',-90:0.1:89.99,'RhoResolution',1);
P = houghpeaks(H,2);
lines = houghlines(H,T,R,P,'FillGap',10,'MinLength',1);
figure, imshow(I), hold on
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');
end
我得到this 结果(线的末端位于图像本身之外)。其他人可以复制吗?
我尝试修改hough 的参数,但我的测试都没有给出预期的结果。实际上,将'Theta' 参数的步长设置为1 会导致无法获取右侧的行。我也尝试过使用BW=~BW; 反转图像,但后来我只得到离框架很远的一条线......
【问题讨论】:
标签: matlab image-processing line hough-transform