打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Matlab实现——霍夫变换直线检测(1)

霍夫变换实现直线检测——MATLAB

网上好多不能用,就重新写了一个:


  1. % 入口图像为 BW,出口图像为f  
  2. clc,close  
  3. BW=imread('D:\picture\9dafa605d53eea243812bb29.jpg');  
  4. BW=rgb2gray(BW);  
  5. thresh=[0.01,0.17];  
  6. sigma=2;%定义高斯参数  
  7. f = edge(double(BW),'canny',thresh,sigma);  
  8. figure(1),imshow(f,[]);title('canny 边缘检测');  
  9. [H, theta, rho]= hough(f, 0.5);  
  10. %imshow(theta,rho,H,[],'notruesize'),  
  11. axis on,  
  12. axis normal  
  13. %xlabel('\theta'),ylabel('rho');  
  14. [r,c]=houghpeaks(H,5);  
  15. hold on  
  16. lines=houghlines(f,theta,rho,r,c);  
  17. figure,imshow(f,[]),title('Hough Transform Detect Result'),  
  18. hold on  
  19. for k=1:length(lines)   
  20.     xy=[lines(k).point1;lines(k).point2];  
  21. plot(xy(:,1),xy(:,2),'LineWidth',4,'Color',[.6 .6 .6]);  
  22. end  



Matlab2012版本的内核函数有所改变,houghpeaks, houghlines等函数有所改变,感谢cuicd2011的提醒,R2012a版本的直线检测稍有变化:

  1. clc,close    
  2. BW=imread('D:\picture\9dafa605d53eea243812bb29.jpg');  
  3.     
  4. BW=rgb2gray(BW);    
  5. thresh=[0.01,0.17];    
  6. sigma=2;%定义高斯参数    
  7. f = edge(double(BW),'canny',thresh,sigma);    
  8. figure(1),imshow(f,[]);    
  9. title('canny 边缘检测');    
  10.     
  11. [H, theta, rho]= hough(f,'RhoResolution', 0.5);    
  12. %imshow(theta,rho,H,[],'notruesize'),axis on,axis normal    
  13. %xlabel('\theta'),ylabel('rho');    
  14.     
  15. peak=houghpeaks(H,5);    
  16. hold on    
  17.     
  18. lines=houghlines(f,theta,rho,peak);    
  19. figure,imshow(f,[]),title('Hough Transform Detect Result'),hold on    
  20. for k=1:length(lines)    
  21.     xy=[lines(k).point1;lines(k).point2];    
  22.     plot(xy(:,1),xy(:,2),'LineWidth',4,'Color',[.6 .6 .6]);    
  23. end    



实验结果:




本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Opencv学习笔记(四)霍夫变换
【从零学习OpenCV 4】霍夫变换原理及直线检测
【图像处理算法】Hough变换
OpenCV-标准霍夫变换cv::HoughLines
霍夫变换(Hough)
一文解读经典霍夫变换(Hough Transform)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服