1.
进入
Matlab 7.3
集成开发环境,并打开脚本编辑器。
2.
在脚本编辑器中编写一段程序,要求:
(1)
读入存放在
alumgrns.tif
中的原始图像;
(2)
用函数
imfilter
,分别用
Roberts
、
Sobel
和
Laplacian
算子对该图像进行
边缘增强处理;
(3)
用函数
edge
,分别对该图像进行进行
Roberts
、
Sobel
、
Laplacian-Gaussian
和
Canny
方法的边缘检测;
(4)
在同一窗口中显示原始图像和结果图像。
3.
将编写的程序保存为
Example3_4_1EdgeDetect.m
。
4.
运行该程序,并比较各种方法的边缘增强和边缘检测的效果。
%%Example3_4_1EdgeDetect
clear;
clc;
TIF=imread('alumgrns.tif');%%读入TIF图像
H.color=[1 1 1];%%设置背景为白色,打开原图像
figure(H);
subplot(221);
imshow(TIF);
title('原图');
%%Roberts算子
h1=[1,0;0,-1];
h2=[0,1;-1,0];
S1=imfilter(TIF,h1);
S2=imfilter(TIF,h2);
S=abs(S1)+abs(S2);
subplot(222);
imshow(S);
title('Roberts算子图');
%%Sobel算子
sobel_x = [-1,0,1;-2,0,2;-1,0,1];
sobel_y = [-1,-2,-1;0,0,0;1,2,1];
S1=imfilter(TIF,sobel_x);
S2=imfilter(TIF,sobel_y);
S=abs(S1)+abs(S2);
subplot(223);
imshow(S);
title('Sobel算子图');
%%Laplacian算子
laplace=[0,1,0;1,-4,1;0,1,0];
S1=imfilter(TIF,laplace);
S=abs(S1);
subplot(224);
imshow(S);
title('Laplacian算子图');