边缘与锐化滤波(MATLAB)

1,基于梯子算子的图像锐化滤波

%基于梯子算子的图像锐化滤波
clear,clc,close all;
Image = im2double(imread('pic01.bmp'));
[height,width,color] = size(Image);
edgeImage = zeros(height,width,color);
for c =1:color
    for x = 1:width-1
        for y = 1:height-1
            edgeImage(y,x,c) = abs(Image(y,x+1,c)-Image(y,x,c))+abs(Image(y+1,x,c)-Image(y,x,c));
        end
    end
end
sharpImage = Image+edgeImage;
subplot(131),imshow(Image),title('原图');
subplot(132),imshow(edgeImage),title('梯度图像');
subplot(133),imshow(sharpImage),title('锐化图像');

结果:边缘与锐化滤波(MATLAB)_第1张图片

2,基于Roberts算子的图像锐化滤波

%基于Roberts算子的图像锐化滤波
clear,clc,close all;
Image = im2double(imread('pic01.bmp'));
gray = rgb2gray(Image);
BW = edge(gray,'roberts');%利用Roberts算子进行边缘检测
H1 = [1 0; 0 -1];   H2 = [0 1; -1 0];
R1 = imfilter(Image,H1);  R2=imfilter(Image,H2);%利用Roberts算子进行滤波
edgeImage = abs(R1)+abs(R2);
sharpImage = Image+ edgeImage;%Roberts锐化增强
subplot(221),imshow(Image),title('原图');
subplot(222),imshow(edgeImage),title('Roberts梯度图像');
subplot(223),imshow(BW),title('Roberts边缘检测');
subplot(224),imshow(sharpImage),title('Roberts锐化图像');

边缘与锐化滤波(MATLAB)_第2张图片

3,基于Sobel算子的图像锐化滤波

%基于Sobel算子的图像锐化滤波
clear,clc,close all;
Image = im2double(imread('pic01.bmp'));
gray = rgb2gray(Image);
BW = edge(gray,'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;
subplot(221),imshow(Image),title('原图');
subplot(222),imshow(edgeImage),title('Sobel梯度图像');
subplot(223),imshow(BW),title('Sobel边缘检测');
subplot(224),imshow(sharpImage),title('Sobel锐化图像');

结果:
边缘与锐化滤波(MATLAB)_第3张图片

4,基于拉普拉斯算子进行图像锐化滤波

%基于拉普拉斯算子进行图像锐化滤波
clear,clc,close all;
Image = im2double(imread('pic01.bmp'));
gray = rgb2gray(Image);
H=fspecial('laplacian',0);
R = imfilter(Image,H);%Laplacian二阶微分运算
edgeImage = abs(R);
H1 = [0 -1 0;-1 5 -1 ;0 -1 0];
sharpImage = imfilter(Image,H1);%Laplacian锐化滤波
BW = edge(gray,'zerocross',0.05,H);
subplot(221),imshow(Image),title('原图');
subplot(222),imshow(edgeImage),title('Laplacian梯度图像');
subplot(223),imshow(BW),title('Laplacian边缘检测');
subplot(224),imshow(sharpImage),title('Laplacian锐化图像');

结果:
边缘与锐化滤波(MATLAB)_第4张图片

5,利用Canny算子进行图像边缘检测

%利用Canny算子进行图像边缘检测
clc,clear,close all;
Image = im2double(rgb2gray(imread('pic01.bmp')));
BW = edge(Image,'canny');
subplot(131),imshow(Image),title('原图');
subplot(132),imshow(BW),title('Canny边缘检测');

结果:
边缘与锐化滤波(MATLAB)_第5张图片

你可能感兴趣的:(机器视觉,MATLAB,matlab)