收藏 分销(赏)

MATLAB边缘检测.pdf

上传人:二*** 文档编号:4594479 上传时间:2024-09-30 格式:PDF 页数:5 大小:8.19KB
下载 相关 举报
MATLAB边缘检测.pdf_第1页
第1页 / 共5页
本文档共5页,全文阅读请下载到手机保存,查看更方便
资源描述

1、clcclose allclear all%生成高斯平滑滤波模板%hg=zeros(3,3);%设定高斯平滑滤波模板的大小为3*3delta=0.5;for x=1:1:3for y=1:1:3 u=x-2;v=y-2;hg(x,y)=exp(-(u2+v2)/(2*pi*delta2);endendh=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-

2、1;colhigh=n-1;%高斯滤波%for x=2:1:rowhigh-1for 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(:);endendf=ftempsubplot(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

3、2:1:rowhigh-1for 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);fsx=sx.*mod;fsy=sy.*mod;ftemp(x,y)=sqrt(sum(fsx(:)2+(sum(fsy(:)2);endendfr=im2uint8(ftemp);subplot(2,3,3),imshow(fr)title(用roberts算子边缘检测的原始图像);%域值分割%TH1=60;%设定阈值for x=2:1:rowhigh-1f

4、or y=2:1:colhigh-1if (fr(x,y)=TH1)&(fr(x,y-1)fr(x,y+1)fr(x,y)=200;elseif(fr(x,y)=TH1)&(fr(x-1,y)fr(x+1,y)fr(x,y)=200;else fr(x,y)=50;endendendsubplot(2,3,4),imshow(fr)title(用roberts算子边缘检测并细化后的图像);%利用第一种近似算法进行边缘检测%3*3的sobel 算子%sx=-1-2-1;0 0 0;1 2 1;sy=-1 0 1;-2 0 2;-1 0 1;%sx=0 1 2;-1 0 1;-2-1 0;%sy=

5、2-1 0;-1 0 1;0 1 2;for x=2:1:rowhigh-1for 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);fsx=sx.*mod;fsy=sy.*mod;ftemp(x,y)=abs(sum(fsx(:)+abs(sum(fsy(:);endendfs=im2uint8(ftemp);subplot(2,3,5),imshow(fs)title(进行边缘检测的原始图像);%域值分割%TH2=200;%设定阈值for

6、 x=2:1:rowhigh-1for y=2:1:colhigh-1if (fs(x,y)=TH2)&(fs(x,y-1)fs(x,y+1)fs(x,y)=200;elseif(fs(x,y)=TH2)&(fs(x-1,y)fs(x+1,y)fs(x,y)=200;else fs(x,y)=50;endendendsubplot(2,3,6),imshow(fs)title(进行边缘检测后的图像);clcclose allclear all%生成高斯平滑滤波模板%hg=zeros(3,3);%设定高斯平滑滤波模板的大小为3*3%delta=0.5;%for x=1:1:3%for y=1:1

7、3%u=x-2;%v=y-2;%hg(x,y)=exp(-(u2+v2)/(2*pi*delta2);%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;%salt%f=imnoise(f,salt&pepper,0.005);subplot(2,3,2),imshow(f)title(salt);%利用

8、 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-1for 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);fsx=sx.*mod;fsy=sy.*mod;ftemp(x,y)=sqrt(sum(fsx(:)2+(sum(fsy(:)2);endendfr=im2uint8(ftemp);subplot(2,3,3),imshow(

9、fr)title(用roberts算子边缘检测的原始图像);%域值分割%TH1=60;%设定阈值for x=2:1:rowhigh-1for y=2:1:colhigh-1if (fr(x,y)=TH1)&(fr(x,y-1)fr(x,y+1)fr(x,y)=200;elseif(fr(x,y)=TH1)&(fr(x-1,y)fr(x+1,y)fr(x,y)=200;else fr(x,y)=50;endendendsubplot(2,3,4),imshow(fr)title(用roberts算子边缘检测并细化后的图像);%3*3的sobel 算子%sx=-1-2-1;0 0 0;1 2 1;

10、sy=-1 0 1;-2 0 2;-1 0 1;%sx=0 1 2;-1 0 1;-2-1 0;%sy=-2-1 0;-1 0 1;0 1 2;for x=2:1:rowhigh-1for 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);fsx=sx.*mod;fsy=sy.*mod;ftemp(x,y)=max(abs(sum(fsx(:),abs(sum(fsy(:);endendfs=im2uint8(ftemp);subplot(2,3,5),imshow(fs)title(进行边缘检测的原始图像);%域值分割%TH2=200;%设定阈值for x=2:1:rowhigh-1for y=2:1:colhigh-1if (fs(x,y)=TH2)&(fs(x,y-1)fs(x,y+1)fs(x,y)=200;elseif(fs(x,y)=TH2)&(fs(x-1,y)fs(x+1,y)fs(x,y)=200;else fs(x,y)=50;endendendsubplot(2,3,6),imshow(fs)title(进行边缘检测后的图像);

展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传
相似文档                                   自信AI助手自信AI助手
搜索标签

当前位置:首页 > 教育专区 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服