Matlab實現 霍夫變換直線檢測

2021-09-11 00:01:57 字數 2925 閱讀 1039

霍夫變換實現直線檢測——matlab

網上好多不能用,就重新寫了乙個:

% 入口影象為 bw,出口影象為fclc,closebw=imread('d:\picture\9****605d53eea243812bb29.jpg');bw=rgb2gray(bw);thresh=[0.01,0.17];sigma=2;%定義高斯引數f = edge(double(bw),'canny',thresh,sigma);figure(1),imshow(f,);title('canny 邊緣檢測');[h, theta, rho]= hough(f, 0.5);%imshow(theta,rho,h,,'notruesize'),axis on,axis normal%xlabel('\theta'),ylabel('rho');[r,c]=houghpeaks(h,5);hold onlines=houghlines(f,theta,rho,r,c);figure,imshow(f,),title('hough transform detect result'),hold onfor k=1:length(lines)     xy=[lines(k).point1;lines(k).point2];plot(xy(:,1),xy(:,2),'linewidth',4,'color',[.6

.6.6]);end

matlab2012版本的核心函式有所改變,houghpeaks, houghlines等函式有所改變,感謝cuicd2011的提醒,r2012a版本的直線檢測稍有變化:

clc,close  bw=imread('d:\picture\9****605d53eea243812bb29.jpg');  bw=rgb2gray(bw);  thresh=[0.01,0.17];  sigma=2;%定義高斯引數  f = edge(double(bw),'canny',thresh,sigma);  figure(1),imshow(f,);  title('canny 邊緣檢測');    [h, theta, rho]= hough(f,'rhoresolution', 0.5);  %imshow(theta,rho,h,,'notruesize'),axis on,axis normal  %xlabel('\theta'),ylabel('rho');    peak=houghpeaks(h,5);  hold on    lines=houghlines(f,theta,rho,peak);  figure,imshow(f,),title('hough transform detect result'),hold on  for k=1:length(lines)      xy=[lines(k).point1;lines(k).point2];      plot(xy(:,1),xy(:,2),'linewidth',4,'color',[.6

.6.6]);  end

實驗結果:

再分享一下我老師大神的人工智慧教程吧。零基礎!通俗易懂!風趣幽默!還帶黃段子!希望你也加入到我們人工智慧的隊伍中來!

霍夫變換實現直線檢測——matlab

網上好多不能用,就重新寫了乙個:

% 入口影象為 bw,出口影象為fclc,closebw=imread('d:\picture\9****605d53eea243812bb29.jpg');bw=rgb2gray(bw);thresh=[0.01,0.17];sigma=2;%定義高斯引數f = edge(double(bw),'canny',thresh,sigma);figure(1),imshow(f,);title('canny 邊緣檢測');[h, theta, rho]= hough(f, 0.5);%imshow(theta,rho,h,,'notruesize'),axis on,axis normal%xlabel('\theta'),ylabel('rho');[r,c]=houghpeaks(h,5);hold onlines=houghlines(f,theta,rho,r,c);figure,imshow(f,),title('hough transform detect result'),hold onfor k=1:length(lines)     xy=[lines(k).point1;lines(k).point2];plot(xy(:,1),xy(:,2),'linewidth',4,'color',[.6

.6.6]);end

matlab2012版本的核心函式有所改變,houghpeaks, houghlines等函式有所改變,感謝cuicd2011的提醒,r2012a版本的直線檢測稍有變化:

clc,close  bw=imread('d:\picture\9****605d53eea243812bb29.jpg');  bw=rgb2gray(bw);  thresh=[0.01,0.17];  sigma=2;%定義高斯引數  f = edge(double(bw),'canny',thresh,sigma);  figure(1),imshow(f,);  title('canny 邊緣檢測');    [h, theta, rho]= hough(f,'rhoresolution', 0.5);  %imshow(theta,rho,h,,'notruesize'),axis on,axis normal  %xlabel('\theta'),ylabel('rho');    peak=houghpeaks(h,5);  hold on    lines=houghlines(f,theta,rho,peak);  figure,imshow(f,),title('hough transform detect result'),hold on  for k=1:length(lines)      xy=[lines(k).point1;lines(k).point2];      plot(xy(:,1),xy(:,2),'linewidth',4,'color',[.6

.6.6]);  end

實驗結果:

matlab 霍夫直線變換誤差

影象處理中,常常遇到需要對影象中的特定形狀進行識別的情景,如線條 圓弧等,如何有效地將其識別出來,業界常用演算法是霍夫變換,霍夫變換依賴於二值化邊緣影象提供的座標。直線在二值影象中可由兩個變數顯示,在笛卡爾座標系,由斜率a和截距b進行表示 在極座標系中,可由極徑r和極角 表示。由於直線在垂直狀態時,...

霍夫變換 直線

hough line transform用來做直線檢測 前提條件 邊緣檢測已經完成 平面空間到極座標空間轉換 對於任意一條直線上的所有點來說 變換到極座標中,從 0 360 空間,可以得到r的大小 屬於同一條直線上點在極座標空 r,theta 必然在乙個點上有最強的訊號出現,根據此反算到平面座標中就...

霍夫變換檢測直線 原理和Matlab實現

霍夫變換本質上是座標變換,如下圖1,左半部分表示直線的xy空間,直線方程為y m x cy mx c y mx c 其中斜率為m,截距為c。右半部分表示將直線從xy空間變換到mc空間,取直線在xy空間上的四點1,2,3,4,在mc空間就是不同斜率和截距的四條直線。那麼,在mc空間中四條直線的交點處的...