【问题标题】:Filtering Hough transform to only find horizontal and vertical lines in Matlab过滤霍夫变换以仅在 Matlab 中找到水平线和垂直线
【发布时间】:2016-04-12 23:50:53
【问题描述】:

我正在尝试编写一些代码来查找图像中的线条并在找到的线条上绘制一条红线。我已经设法使用霍夫变换来做到这一点,但我的问题是我需要它只找到水平和垂直线并忽略所有其他斜坡的线。

我想我可以通过找到代码找到的线的斜率来解决这个问题,并且只使用 if 语句在水平和垂直线上显示红线,但我无法弄清楚如何提取 x和我找到的点的 y 值。

有人对如何解决这个问题有任何建议吗?

下面是我的代码:

function findlineshv(I)

% Read Image
img = imread(I);

% Convert to black and white because
% edge function only works with BW imgs
bwImage = rgb2gray(img);

% figure(1),imshow(bwImage);

% find edges using edge function
b=edge(bwImage,'sobel');

% show edges
% figure(1),imshow(b);


% compute the Hough transform of the edges found
% by the edge function
[hou,theta,rho] = hough(b);

% define peaks, x and y
peaks = houghpeaks(hou,5,'threshold',ceil(0.3*max(hou(:))));

x = theta(peaks(:,2));
y = rho(peaks(:,1));


lines = houghlines(bwImage,theta,rho,peaks,'FillGap',5,'MinLength',7);

figure, imshow(bwImage), hold on

for k = 1:length(lines)
    xy = [lines(k).point1; lines(k).point2];
    plot(xy(:,1),xy(:,2),'LineWidth',3,'Color','red');
end

【问题讨论】:

  • 提示:如果您也分享您的图片,您可能会得到更快的回复。

标签: matlab image-processing


【解决方案1】:

您只需在霍夫函数中设置所需的 theta 值即可。

start_angle = 80;
end_angle = 100;
theta_resolution = 0.5:

[H,T,R] = hough(b, 'Theta', start_angle:theta_resolution:end_angle);

【讨论】:

  • 这不起作用,因为 'Theta' 必须在 [-90, (90-ThetaResolution)] 范围内。
猜你喜欢
  • 1970-01-01
  • 2013-03-09
  • 1970-01-01
  • 1970-01-01
  • 2017-06-30
  • 1970-01-01
  • 2015-04-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多