MATLAB 霍夫变换 连接斜率相同的直线

       基于matlab的霍夫变换的应用,传统的霍夫变换可以检测图像中的直线,但是生活中一般都会出现遮挡物,导致一条直线发生中断,于是在传统霍夫变换的基础上做了修改,进而保证了检测直线的整体性。

matlab 代码实现如下:

% 入口图像为 BW,出口图像为f
%optimize from main_optimize, merely select 2 lines, one has positive
%slope,the other has negative slope
clear all,close all
BW=imread('p.jpg');
figure,imshow(BW);

BW=rgb2gray(BW);
%thresh=[0.01,0.17];
thresh=[0.01,0.10];
sigma=2;%定义高斯参数
f = edge(double(BW),'canny',thresh,sigma);
figure,subplot(121);
imshow(f,[]);
title('canny Edge Detect Result');

[H, theta, rho]= hough(f);

peaks=houghpeaks(H,10);
hold on

lines=houghlines(f,theta,rho,peaks);

subplot(122);
imshow(f,[]),title('Hough Transform Detect Result'),hold on
nlind=0;%new line index
st=1;
%%%%%%%%%求斜率%%%%%%%%%%%%
for k=1:length(lines)
    %xy=[lines(k).point1;lines(k).point2];
    xielv(k)=(lines(k).point2(1)-lines(k).point1(1
  • 2
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值