资源简介
利用Matlab实现霍夫变换对于正弦曲线的自动识别
代码片段和文件信息
clc;
clear;
close all;
%% 模拟裂缝
n=200;
m=200;
x=ones(nm);
h=1;
A1=40;
phi1=180;
baseline1=100;
for i=1:200;
y1=A1*(sin(i*2*pi/200-phi1*pi/180))+baseline1;
x(round(y1)i)=0;
for j=round(y1)-h:round(y1)+h;
x(ji)=0;
end
end
% 加入椒盐噪声
gray = x;
gray = imnoise(x‘salt & pepper‘0.1);
figure;
imshow(gray);
axis on;
ylabel(‘y/像素点‘);
xlabel(‘x/像素点‘);
set(gcf‘Units‘‘centimeters‘‘Position‘[2 2 15 18]);
set(gca‘FontName‘‘Times New Roman‘‘FontSize‘8)
set(gca‘Units‘‘centimeters‘‘Position‘[3 3 3 8]);%设置xy轴在图片中占的比例,起始位置
set(get(gca‘XLabel‘)‘FontSize‘8);%图上文字为8 point
set(get(gca‘YLabel‘)‘FontSize‘8);
%% 参数设置
range = 100;
img = ones(n+2*rangem);
[nn mm] = size(img);
img(range+1:range+n1:m) = gray;
W = 2*pi/m;
figure;
imshow(img);
num = 0;
for ii = 1:nn;
for jj = 1:mm;
if(img(iijj) == 0);
num = num+1;
end
end
end
%% 传统霍夫变换
tic;
counter = zeros(range360n);
for i = 1:n;
for j = 1:m;
if(gray(ij) == 0);
for baseline = 1:n;
for fy = 1:360;
if(sin(j*2*pi/m-fy*pi/180)==0);
A=0;
else
A=(i-baseline)/(sin(j*2*pi/m-fy*pi/180));
end
if(A>0 && A+baseline<=n && baseline-A>=1 && A AA=uint8(round(A));
counter(AAfybaseline)=counte
- 上一篇:matlab代码实现分形维数计算
- 下一篇:改进的花朵授粉算法程序Matlab
评论
共有 条评论