%--------------实验六 图象的边缘检测--------------% http://ocw.guet.edu.cn/dept7/wavelet/ShowArticle.asp?ArticleID=46 %读入canoe.tif图象,并显示图象 clc [A,map]=imread('eight.tif'); imshow(A,map),title('原图象'); figure,imshow(A),title('原图象'); %分别用edge()的六个算子对其进行边缘检测 BW1=edge(A,'roberts'); figure,subplot(3,2,1),imshow(BW1),title('roberts算子'); BW2=edge(A,'sobel'); subplot(3,2,2),imshow(BW2),title('sobel算子'); BW3=edge(A,'log'); subplot(3,2,3),imshow(BW3),title('拉普拉斯高斯算子'); BW4=edge(A,'canny'); subplot(3,2,4),imshow(BW4),title('canny算子'); BW5=edge(A,'prewitt'); subplot(3,2,5),imshow(BW5),title('prewitt算子'); Bw6=edge(A,'zerocross'); subplot(3,2,6),imshow(BW5),title('过零点算子'); %对原图象加入高斯噪声、椒盐噪声、乘性噪声,并用roberts算子sobel算子和拉普拉斯高斯算子进行边缘检测 %加入高斯噪声 B1=imnoise(A,'gaussian'); X1=edge(B1,'roberts'); figure,subplot(3,1,1),imshow(X1),title('高斯噪声后roberts算子'); X2=edge(B1,'sobel'); subplot(3,1,2),imshow(X2),title('高斯噪声后sobel算子'); X3=edge(B1,'log'); subplot(3,1,3),imshow(X3),title('高斯噪声后拉普拉斯高斯算子'); %加入椒盐噪声 B2=imnoise(A,'salt & pepper'); Y1=edge(B2,'roberts'); figure,subplot(3,1,1),imshow(Y1),title('椒盐噪声后roberts算子'); Y2=edge(B2,'sobel'); subplot(3,1,2),imshow(Y2),title('椒盐噪声后sobel算子'); Y3=edge(B2,'log'); subplot(3,1,3),imshow(Y3),title('椒盐噪声后拉普拉斯高斯算子'); %加入乘性噪声 B3=imnoise(A,'speckle'); Z1=edge(B3,'roberts'); figure,subplot(3,1,1),imshow(Z1),title('乘性噪声后roberts算子'); Z2=edge(B3,'sobel'); subplot(3,1,2),imshow(Z2),title('乘性噪声后sobel算子'); Z3=edge(B3,'log'); subplot(3,1,3),imshow(Z3),title('乘性噪声后拉普拉斯高斯算子'); %读入flowers.tif图象文件,利用RGB2GRAY(map)命令把真彩色图象转化为灰度图象,然后做边缘检测 I=imread('flowers.tif'); J=RGB2GRAY(I); figure,imshow(J),title('真彩色图象转化为灰度图象'); BW=edge(J,'roberts'); figure,imshow(BW),title('边缘检测'); |