MATLAB 霍夫直线检测

版权声明:本博主原创文章,欢迎转载。 https://blog.csdn.net/qq_24915933/article/details/78481508

初学图像处理,采用霍夫变换进行直线检测,调试参数调试了很久。

代码如下:

image = imread('image.jpg');
gray = rgb2gray(image);
gray = medfilt2(gray,[5,5]);
figure
imshow(gray);
title('原图滤波后的灰度图');
%imhist(gray);
BW = edge(double(gray),'canny');
[H,theta,rho] = hough(BW);
figure
imshow(H,[],'XData',theta,'YData',rho,'InitialMagnification','fit');
axis on, axis normal;
xlabel('\theta');ylabel('\rho');
Peaks = houghpeaks(H,10,'NHoodSize',[5 5],'Threshold',ceil(0.1*max(H(:))));
lines= houghlines(BW,theta,rho,Peaks);
figure
imshow(BW);
title('canny边缘检测');
hold on
for k=1:length(lines)
    xy=[lines(k).point1;lines(k).point2];   
    plot(xy(:,1),xy(:,2),'LineWidth',2);
end

猜你喜欢

转载自blog.csdn.net/qq_24915933/article/details/78481508