Image=im2double(rgb2gray(imread('lotus.jpg')));
BW=edge(Image,'sobel');
H1=[-1,-2,-1;0,0,0;1,2,1];H2=[-1,0,1;-2,0,2;-1,0,1];
R1=imfilter(Image,H1);
R2=imfilter(Image,H2);
edgeImage=abs(R1)+abs(R2);
sharpImage=Image+edgeImage;
figure;
subplot(2,2,1);imshow(Image);title('原图');
subplot(2,2,2);imshow(edgeImage);title('Sobel梯度图像');
subplot(2,2,3);imshow(BW);title('Sobel边缘检测');
subplot(2,2,4);imshow(sharpImage);title('Sobel锐化图像');
%prewitt
H1=[-1,-1,-1;0,0,0;1,1,1];H2=[-1,0,1;-1,0,1;-1,0,1];
R1=imfilter(Image,H1);
R2=imfilter(Image,H2);
edgeImage=abs(R1)+abs(R2);
sharpImage=Image+edgeImage;
figure;
subplot(1,2,1);imshow(Image);title('原图');
subplot(1,2,2);imshow(sharpImage);title('prewitt锐化图像');
%Roberts
Image=im2double(rgb2gray(imread('lotus.jpg')));
BW=edge(Image,'roberts');
H1=[1,0;0,-1];H2=[0,1;-1,0];
R1=imfilter(Image,H1);
R2=imfilter(Image,H2);
edgeImage=abs(R1)+abs(R2);
sharpImage=Image+edgeImage;
figure;
subplot(2,2,1);imshow(Image);title('原图');
subplot(2,2,2);imshow(edgeImage);title('Roberts梯度图像');
subplot(2,2,3);imshow(BW);title('Roberts边缘检测');
subplot(2,2,4);imshow(sharpImage);title('Roberts锐化图像');
%Laplacian
Image=im2double(rgb2gray(imread('lotus.jpg')));
H=fspecial('laplacian',0);
R=imfilter(Image,H);
edgeImage=abs(R);
H1=[0,-1,0;-1,5,-1;0,-1,0];
sharpImage=imfilter(Image,H1);
figure;
subplot(1,3,1);imshow(Image);title('原图');
subplot(1,3,2);imshow(edgeImage);title('拉普拉斯滤波图像');
subplot(1,3,3);imshow(sharpImage);title('拉普拉斯锐化图像');
运行结果及分析
sobel
核心代码:
读入一张图片,并对该图片进行sobel锐化滤波,运行结果为:
从结果图片可以看到,结果图片的边缘像素部分的会偏亮。
prewitt
核心代码:
对prewitt的两个锐化滤波矩阵进行编码,然后对图片进行prewitt锐化滤波,运行结果为:
可以看到,prewitt可以增强图片的边缘信息,并且相比于sobel来讲,边缘像素没有像sobel那么亮,效果会更好一些。
Robert
核心代码:
先编码robert的滤波矩阵,然后对图片进行robert锐化滤波,运行结果为:
从运行结果可以看出,相比于前面的sobel和prewitt来说,边缘曝光度得到缓解,并且也增强了边缘信息。
Laplacian
核心代码:
编码Laplacian滤波矩阵,并对图片进行Laplacian滤波,运行结果为:
可以看出,边缘像素的曝光度过高的问题再一次得到缓解,并且也增强了图像的边缘信息。