资源简介
采用小波变换模极大值法检测图像边缘!
代码片段和文件信息
clear all;
close all;
%%%%%%%%%%%%%%载入图像%%%%%%%%%%%%%%
I=imread(‘C:\Users\HP\Desktop\rongchi3.bmp‘);
% I=imnoise(I‘gaussian‘00.01);
X=double(I);
[IxIy]=size(X); %图像长宽
%%%%%%%%%%%%%%二级尺度%%%%%%%%%%%%%%
m=1.0;
delta=2^m;
%%%%%%%%%高斯函数XY方向的偏导%%%%%%%
N=20; %长度和幅度
A=-1/sqrt(2*pi);
phi_x=zeros(NN);
phi_y=zeros(NN);
for i=1:N %偏导
for j=1:N
x=i-(N+1)/2;
y=j-(N+1)/2;
phi_x(ij)=A*(x/delta^2).*exp(-(x*x+y*y)/(2*delta^2));
phi_y(ij)=A*(y/delta^2).*exp(-(x*x+y*y)/(2*delta^2));
end
end
%%%%%%%%%图象行、列卷积%%%%%%%%%%%%%%
W_x=conv2(Xphi_x‘same‘);
W_y=conv2(Xphi_y‘same‘);
%%%%%%%%%%%%求梯度%%%%%%%%%%%%%%%%%%%
Mod_G=zeros(IxIy);
for i2=1:Ix
for j2=1:Iy
Mod_G(i2j2)=sqrt(W_x(i2j2)*W_x(i2j2)+W_y(i2j2)*W_y(i2j2));
end
end
M=fix(Mod_G);
%%%%%%%%%%%%求幅角%%%%%%%%%%%%%%%%%%%
Arg=zeros(IxIy);
for i3=1:Ix
for j3=1:Iy
angle=atan(W_y(i3j3)/W_x(i3j3))*180/pi; %求反正切
if ((W_x(i3j3)>0)&&(W_y(i3j3)>0)) %第一象限
angle=angle+0;
elseif ((W_x(i3j3)<0)&&(W_y(i3j3)>0)) %第二象限
angle=angle+180;
elseif ((W_x(i3j3)<0)&&(W_y(i3j3)<0)) %第三象限
angle=angle+180;
elseif ((W_x(i3j3)>0)&&(W_y(i3j3)<0)) %第四象限
angle=angle+360;
elseif (abs(W_y(i3j3)/W_x(i3j3))>100000000) %大值90度
angle=90;
elseif (abs(W_y(i3j3)/W_x(i3j3))==0) %零值0度
angle=0;
end
if(angle>180) %幅角限制在0-180
angle=angle-180;
end
Arg(i3j3)=angle;
end
end
%%%%%%%%%%%%图像边界%%%%%%%%%%%%%%%%%%%%
%沿着梯度方向检测小波变换系数模的局部极大%
%%%%%%%%值点即可得到图像的边缘点%%%%%%%%%
Edge=zeros(IxIy);
for i4=2:(Ix-1)
for j4=2:(Iy-1)
if ((Arg(i4j4)>=0&&Arg(i4j4)<=22.5))
if (Mod_G(i4j4)>Mod_G(i4+1j4)&&Mod_G(i4j4)>Mod_G(i4-1j4))%水平
Edge(i4j4)=Mod_G(i4j4);
end
elseif ((Arg(i4j4)>=(90-22.5)&&Arg(i4j4)<=(90+22.5)))
if (Mod_G(i4j4)>Mod_G(i4j4+1)&&Mod_G(i4j4)>Mod_G(i4j4-1))%45度
Edge(i4
评论
共有 条评论