Laplacian边缘检测原理


Laplacian边缘检测原理_第1张图片



clear;
sourcePic=rgb2gray(imread('lena.jpg'));%读取原图像
grayPic=mat2gray(sourcePic);%转换成灰度图像
subplot(121);imshow(grayPic);title('原图');
[m,n]=size(grayPic);
newGrayPic=grayPic;%为保留图像的边缘一个像素
LaplacianNum=0;%经Laplacian算子计算得到的每个像素的值
LaplacianThreshold=0.21;%设定阈值
for j=2:m-1 %进行边界提取
for k=2:n-1
LaplacianNum=abs(4*grayPic(j,k)-grayPic(j-1,k)-grayPic(j+1,k)-grayPic(j,k+1)-grayPic(j,k-1));
%newGrayPic(j,k)=LaplacianNum;
if(LaplacianNum > LaplacianThreshold)
newGrayPic(j,k)=255;
else
newGrayPic(j,k)=0;
end
end
end
subplot(122),imshow(newGrayPic);title('Laplacian算子的处理结果')
Laplacian边缘检测原理_第2张图片 Laplacian边缘检测原理_第3张图片

你可能感兴趣的:(数字图像处理,数字图像处理)