专业
专业word可编辑
Experiment 3 : Edge Detection
Class:电子 1203 班Student ID:1210910322 Name:王影
I . Aim
The aim of this laboratory sessi on is to lear n to deal with image data by Matlab. By the
end of this session, you should be able to perform image preprocessing of edge detect ion in spatial doma in and freque ncy doma in.
n . Knowledge required in the Experiment
.You are supposed to have learned the basic skills of using Matlab;
.You need to review Matlab programming Ianguage and M-file format.
iii. You should have studied edge detect ion methods.
川.Experiment Contents
Dema nd: Please show the figure on the left and list the codes on the right respectively
bellow each question.(请将运行结果(图片)和程序代码贴在每题下方)
i .Read “ar.jpg ” file (to do this by imread function), convert the color image into grayscale image, and the n perform edge detect ion using Roterts, Prewitt, Sobel operator separately in spatial doma in and display the results in a Matlab win dow.
程序:
clear;
im=imread( 'car.jpg');
I=rgb2gray(im);
subplot(3,2,1);imshow(l);
title( 'Gray image');
[Y,X]=size(l);
im_edge=zeros(Y,X);
T=30;
for k=2:Y-1
for kk=2:X-1
im_edge(k,kk)=abs(l(k+1,kk+1)-l(k,kk))+abs(l(k,kk+1)-l(k+1,kk));
if (im_edge(k,kk)>T)
im_edge(k,kk)=1;
else
im_edge(k,kk)=0;
end
end
end
subplot(3,2,2);
imshow(im_edge,[]); %[] e ? e y?Y x ?? - ?? ? ?卩?0~255 卩? ? ?? § ? u ? £
title( 'Robert image');
-Y xHsN'e (三
imedgeHzeros(Y-x「
for k"2Y—1
for kk"2x—1
imedge(k-kkHabs(-?1 -kk+1)'(k?kk—1))+abs(-(Kkk+1)」m(Kkk—1)) abs (一 (k+1 - kk+1 )'(k+1 - kka)+ ■■- abs (一 (k+1-kka'?1-kka)+abs (一 (k+1- kk)'(k?
kk))+abs (一 (k+1 - kk+1 )'?1 - kk+1)二
end
end subp_2.(3-2-3)- imshow(imedge-s s-e( -prewifimage-=
-Y xHsN'e (三 imledgeHzeros(Y-x=
for k"2Y—1
for kk"2x—1
-4妄 word 凹>#
专业
专业word可编辑
im_edge(k,kk)=abs(l(k-1,kk+1)-l(k-1,kk-1))+2*abs(l(k,kk+1)-l(k,kk-1)) +
abs(l(k+1,kk+1)-l(k+1,kk-1))+...
abs(l(k+1,kk -1)-l(k-1,kk-1))+2*abs(l(k+1, kk)-l(k-1,
kk))+abs(l(k+1,kk+1)-l(k-1,kk+1));
end end subplot(3,2,4);
imshow(im_edge,[]);
title( 'S