%Laplacian微分算子边缘提取
function d=Laplacian(x,n)
d=x;
operator=[0,1,0;1,-4,1;0,1,0];
[width,height]=size(x);
for ii=1:width-(n-1)
for jj=1:height-(n-1)
tmp=x(ii:ii+n-1,jj:jj+n-1).*operator;
p=sum(sum(tmp));
d(ii+(n-1)/2,jj+(n-1)/2)=p;
end
function d=Laplacian(x,n)
d=x;
operator=[0,1,0;1,-4,1;0,1,0];
[width,height]=size(x);
for ii=1:width-(n-1)
for jj=1:height-(n-1)
tmp=x(ii:ii+n-1,jj:jj+n-1).*operator;
p=sum(sum(tmp));
d(ii+(n-1)/2,jj+(n-1)/2)=p;
end
end
%==========================主函数
%author:王同乐
%date:2016/10/30
img=imread('lena.png');
img=rgb2gray(img);
img=im2double(img);%输入图像类型为uint8,将其转换为double类型进行运算
%=====================================laplacian算子
subplot(1,3,1);imshow(img);title('原图');
subplot(1,3,2);imshow(Laplacian(img,3));title('laplacian提取垂直边缘后的图像')
subplot(1,3,3);imshow(sharp_operator(img,3));title('roberts提取边缘后的图像')
%==============================效果图