用MATLAB实现的图像边缘提取的代码:
clear;clc;
I=imread('lena.bmp');
I=rgb2gray(I);
imshow(I,[]);
title('Original Image');
sobelBW=edge(I,'sobel');
figure;
imshow(sobelBW);
title('Sobel Edge');
robertsBW=edge(I,'roberts');
figure;
imshow(robertsBW);
title('Roberts Edge');
prewittBW=edge(I,'prewitt');
figure;
imshow(prewittBW);
title('Prewitt Edge');
logBW=edge(I,'log');
figure;
imshow(logBW);
title('Laplasian of Gaussian Edge');
cannyBW=edge(I,'canny');
figure;
imshow(cannyBW);
title('Canny Edge');
3-6行代码的含义为导入图片,接下来用5种算子对图像边缘进行提取。以文中的封面图片为例演示5种算子的图像边缘提取效果。