嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
Hough变换可用于检测影像中直线、抛物线、椭圆等形状能够用一定函数关系描述的曲线,它在影像分析、模式识别等很多领域中得到成功的应用。其基本原理是将影像空间中的曲线变换到参数空间中,通过检测参数空间的极值点,确定该曲线的变换参数,从而提取影像中的规则曲线。线特征是数字摄影测量中很重要的工作,本次实验运用霍夫变换提取直线,可以更好的掌握霍夫变换的原理,同时锻炼了编程能力。
clear all;
clc;
I=imread('line.png'); %读入图像
subplot(221), imshow(I), title('original image'); %显示图像
img_gray = rgb2gray(I);
BW = edge(img_gray,'canny'); % the canny edge of image边缘检测
subplot(223), imshow(BW), title('edge image');
% the theta and rho of transformed space转换到ρθ空间
[H,Theta,Rho] = hough(BW);
subplot(222), imshow(H,[],'XData',Theta,'YData',Rho,'InitialMagnification','fit'),...
title('rho\_theta space and peaks');
xlabel('\theta'), ylabel('\rho');
axis on, axis normal, hold on;
% label the top 5 intersections取前五个交点最多处
P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
x = Theta(P(:,2));
y = Rho(P(:,1));
plot(x,y,'*','color','b'); %设置点的颜色
% find lines and plot them
lines = houghlines(BW,Theta,Rho,P,'FillGap',5,'MinLength',7);
figure, imshow(I), hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','g'); %设置提取线的宽度和颜色
end