matlab利用边缘检测,MATLAB边缘检测

clc

close all

clear all

%%%生成高斯平滑滤波模板%%%

%%%%%%%%%%%%%%%%%%%%%%%%%

hg=zeros(3,3); %设定高斯平滑滤波模板的大小为3*3

delta=0.5;

for x=1:1:3

for y=1:1:3

u=x-2;

v=y-2;

hg(x,y)=exp(-(u^2+v^2)/(2*pi*delta^2));

end

end

h=hg/sum(hg(:));

%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%读入图像%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%

f = imread('Image1.bmp'); % 读入图像文件

f=rgb2gray(im2double(f));

subplot(2,3,1),imshow(f)

title('原始图像');

[m,n]=size(f);

ftemp=zeros(m,n);

rowhigh=m-1;

colhigh=n-1;

%%%高斯滤波%%%

for x=2:1:rowhigh-1

for y=2:1:colhigh-1

mod=[f(x-1,y-1) f(x-1,y) f(x-1,y+1); f(x,y-1) f(x,y) f(x,y+1);f(x+1,y-1) f(x+1,y) f(x+1,y+1)];

A=h.*mod;

ftemp(x,y)=sum(A(:));

end

end

f=ftemp

subplot(2,3,2),imshow(f)

title('通过高斯滤波器后的图像');

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% %%%利用roberts算子进行边缘检测%%%

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

sx=[-1 -2 -1;0 0 0;1 2 1];

sy=[-1 0 1;-2 0 2;-1 0 1];

for x=2:1:rowhigh-1

for y=2:1:colhigh-1

mod=[f(x-1,y-1) f(x-1,y) f(x-1,y+1); f(x,y-1) f(x,y) f(x,y+1);f(x+1,y-1) f(x+1,y) f(x+1,y+1)];

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值