⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hough_line_own.m

📁 这个是MATLAB实现Hough变换的程序。有基本的Hough变换的理解程序
💻 M
字号:
%addpath D:\MATLAB704\toolbox\tftb2002
% Hough 变换detect line
%%    %%%%%%也可以用tftb中的函数  htl  %%%%%%%5
% i=imread('C:\Documents and Settings\zhwei\桌面\line.bmp');
% figure(1)
% i_long =size(i,1);
% i_width=size(i,2);
%%%%在无噪声情况下,和噪声为6DB的情况下%%%%%%%%%%
%%%%利用Hough变换检测运动轨迹为直线的目标%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a=zeros(300,300);
for i=1:100
    a(i*3,i)=1;
end
b=a;  %产生待检测的数据:300*300的矩阵,对前150行赋值使产生一条直线
x=1:300;
y=1:300;
figure(1)
surf(x,y,b); 
shading interp;
colormap(jet);
%colormap(hot);
%colormap(autumn)
xlabel('像素单元数/个');
ylabel('像素单元数/个');
axis([1,300,1,300]);
b_long=size(b,1);
b_width=size(b,2);
b_edge=edge(b,'robert');
b_hough=zeros(300,300);   %创造一个300*300的矩阵
theta_step=3.14*2/299;
theta=0:theta_step:2*3.14; 
x_max=1;    
x_min=1;
y_max=1;
y_min=1; 

for x=1:b_long
   for y=1:b_width
     if b_edge(x,y)==1
     x_max=max(x_max,x);   
     x_min=min(x_min,x);
     y_max=max(y_max,y);
     y_min=min(y_min,y);
     end
   end
end 

p_min=sqrt(x_min^2+y_min^2);        %开平方 
p_max=sqrt(x_max^2+y_max^2);
p_step=2*p_max/299;
p=-p_max:p_step:p_max; 
for x=1:b_long
    for y=1:b_width
        if b_edge(x,y)==1     %对于边缘点进行累加
           rou=x.*cos(theta)+y.*sin(theta);
            w=fix(rou./p_step)+151;
            l=fix(1+theta./theta_step);%l是1~300
            n=300.*(l-1)+w;
            b_hough(n)=b_hough(n)+1;
        end
    end
end 

m=max(max(b_hough));
b_hough=(b_hough./m);
figure(2)
mesh(b_hough);
% figure(3)
% imshow(b_hough);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -