• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

matlab霍夫变换(hough)检测直线

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

  霍夫变换是一种特征检测(feature extraction),被广泛应用在图像分析(image analysis)、电脑视觉 (computer vision)以及数位影像处理 (digital image processing)。 霍夫变换是用来辨别找出物件中的特征,例如:线条。他的算法流程大致如下,给定一个物件、要辨别的形状的种类,算法会在参数空间(parameter space)中执行投票来决定物体的形状, 而这是由累加空间(accumulator space)里的局部最大值(local maximum)来决定。  

  Hough变换的基本原理在于,利用点与线的对偶性,将图像空间的线条变为参数空间的聚集点,从而检测给定图像是否存在给定性质的曲线。

clc;clear ; close 
set(0,'defaultfigurecolor',[1,1,1]) 
load DATA2.mat
data = D1;
BW = data;

figure(1)
imshow(BW)
title('原图像');
figure(2) subplot 211; %%进行霍夫变换 [H, theta , rho] = hough (BW); %%绘制霍夫空间 imshow(imadjust(mat2gray(H)),[],'XData',theta,'YData',rho,... 'InitialMagnification','fit'); xlabel('\theta (degrees)'), ylabel('\rho'); axis on, axis normal, hold on; colormap(hot); title('霍夫空间') %%峰值 P = houghpeaks(H,5,'threshold',0.5*max(H(:))); x = theta(P(:,2)); y = rho(P(:,1)); plot(x,y,'s','color','black'); %lines = houghlines(BW,theta,rho,P,'FillGap',10,'MinLength',10); lines = houghlines(BW,theta,rho,P,'FillGap',10,'MinLength',10); subplot 212 imshow(BW) ,hold on max_len = 0; count = 1; points = zeros(2,2); for k = 1:length(lines) points(count,1) = lines(k).point1(1); points(count,2) = lines(k).point1(2); count =count +1; points(count,1) = lines(k).point2(1); points(count,2) = lines(k).point2(2); count =count +1; 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 title('直线检测');

  效果如下:

 


 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Delphi消息处理机制发布时间:2022-07-18
下一篇:
delphi单例模式实现发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap