一、实验目的及要求:
利用不同算子,对图像边缘进行检测。
二、实验内容:
(1)给定图像,用Sobel、Robert和Laplacian算子进行边缘检测。
(2)不能采用MATLAB中提供的边缘检测函数,要自己编程实现上面三个边缘检测算子。把原始图像、用三种算子进行边缘检测后的图像同时显示出来,以供比较。
三、实验步骤:
1 .创建一个GUI用户界面窗口(如下图所示)
2 .编辑该GUI所对应的m文件,具体程序如下
(1)原始图像部分:
subplot(2,2,1);
imshow(a);
title('原始图像');
(2)Sobel边缘检测图像部分:
| a=im2double(b); |
| for i=2:511
g(i,j)=sqrt(fx(i,j)^2+fy(i,j)^2); end end gmax=max(max(g)); gmin=min(min(g)); step=gmax-gmin; for e=2:511
end end subplot(2,2,2); imshow(g); title('Sobel边缘检测图像'); (3)Robert以及Laplacian边缘检测图像部分: b=im2double(a); for i=2:512 for j=2:512
fy(i,j)=b(i-1,j)-b(i,j-1);
end end gmax=max(max(g)); gmin=min(min(g)); step=gmax-gmin; for e=2:512 for o=2:512
end end subplot(2,2,3); imshow(g); title('Robert边缘检测图像'); subplot(2,2,4); imshow(g); title('Laplacian边缘检测图像'); |
| c 实验运行结果: |