计算机视觉实验报告Experiment3
Experiment 3:Edge Detection
Class: 电子1203班 Student ID: 1210910322 Name: 王影
Ⅰ. Aim
The aim of this laboratory session is to learn to deal with image data by Matlab. By the end of this session, you should be able to perform image preprocessing of edge detection in spatial domain and frequency domain.
Ⅱ. Knowledge required in the Experiment
ⅰ.You are supposed to have learned the basic skills of using Matlab;
ⅱ.You need to review Matlab programming language and M-file format.
ⅲ. You should have studied edge detection methods.
Ⅲ. Experiment Contents
Demand: Please show the figure on the left and list the codes on the right respectively bellow each question.(请将运行结果(图片)和程序代码贴在每题下方)
ⅰ.Read “car.jpg” file (to do this by imread function), convert the color image into grayscale image, and then perform edge detection using Roterts, Prewitt, Sobel operator separately in spatial domain and display the results in a Matlab window.
程序:
clear;
im=imread('car.jpg');
I=rgb2gray(im);
subplot(3,2,1);imshow(I);
title('Gray image');
[Y,X]=size(I);
im_edge=zeros(Y,X);
T=30;
for k=2:Y-1
for kk=2:X-1
im_edge(k,kk)=abs(I(k+1,kk+1)-I(k,kk))+abs(I(k,kk+1)-I(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,[]);% []è?êy?Y×??ˉ??·?μ?0~255μ?·??§?ú?£
title('Robert image');
[Y X]=size(I);
imedge=zeros(Y,X);
for k=2:Y-1
for kk=2:X-1
imedge(k,kk)=abs(I(k-1,kk+1)-I(k-1,kk-1))+abs(I(k,kk+1)-im(k,kk-1)) + abs(I(k+1,kk+1)-I(k+1,kk-1))+...
abs(I(k+1,kk -1)-I(k-1,kk-1))+abs(I(k+1, kk)-I(k-1, kk))+abs(I(k+1,kk+1)-I(k-1,kk+1)) ;
end
end
subplot(3,2,3);
imshow(imedge,[]);
title('Prewit image');
[Y X]=size(I);
im_edge=zeros(Y,X);
for k=2:Y-1
for kk=2:X-1
im_edge(k,kk)=abs(I(k-1,kk+1)-I(k-1,kk-1))+2*abs(I(k,kk+1)-I(k,kk-1)) + abs(I(k+1,kk+1)-