空域滤波(matlab)

空域滤波是空域图像增强的常用方法,对图像中每个像素为中心的邻域进行一系列的运算。然后将得到的结果替代原来的像素值。

线性空域滤波

线性平均滤波是一种低通滤波,信号的低频部分通过,高频部分通过,由于边缘处于高频部分,因此线性平均滤波后,会造成图像边缘模糊。

平滑滤波:imfilter()
>> I=imread('E:\persional\matlab\images\ad2.tif');
>> J = imnoise(I,'salt & pepper',0.2);%添加噪声
>> h = ones(3,3)/5;%建立模板
>> h(1,1) = 0;
>> h(1,3) = 0;
>> h(3,1) = 0;
>> h(1,3) = 0;
>> K = imfilter(J,h);%图像滤波
>> figure,
>> subplot(131),imshow(I);
>> subplot(132),imshow(J);
>> subplot(133),imshow(K);

在这里插入图片描述

平滑滤波:conv2()
>> I=imread('E:\persional\matlab\images\ba.tif');
>> I = im2double(I);
>> J = imnoise(I,'gaussian',0,0.01);
>> h = ones(3,3)/9;
>> K = conv2(J,h);%通过卷积进行滤波
>> figure,
>> subplot(131),imshow(I);
>> subplot(132),imshow(J);
>> subplot(133),imshow(K);

在这里插入图片描述

二维线性数字滤波:filter2()
>> I=imread('E:\persional\matlab\images\ba.tif');
>> I = im2double(I);
>> J = imnoise(I,'salt & pepper',0.02);%添加噪声
>> h1 = fspecial('average',3);%3x3模板
>> h2 = fspecial('average',5);%5x5模板
>> K1 = filter2(h1,J);%滤波
>> K2 = filter2(h2,J);
>> figure,
>> subplot(131),imshow(J);
>> subplot(132),imshow(K1);
>> subplot(133),imshow(K2);

在这里插入图片描述

非线性空域滤波

非线性空域滤波主要包括中值滤波、顺序统计滤波和自适应滤波

二维中值滤波:medfilt2()

中值滤波可以去除图像中的椒盐噪声,平滑效果优于均值滤波,在抑制噪声的同时还能够保持图像的边缘清晰。

>> I=imread('E:\persional\matlab\images\ba.tif');
>> I = im2double(I);
>> J = imnoise(I,'salt & pepper',0.05);
>> K = medfilt2(J);
>> figure,
>> subplot(131),imshow(I);
>> subplot(132),imshow(J);
>> subplot(133),imshow(K);

在这里插入图片描述

自适应滤波:wiener2()

根据图像的局部方差来调整滤波器的输出,当局部方差大时,滤波器平滑效果弱,当局部方差小时,滤波器平滑效果强。

>> I=imread('E:\persional\matlab\images\ba.tif');
>> I = im2double(I);
>> J = imnoise(I,'gaussian',0,0.01);
>> K = wiener2(J,[5,5]);
>> figure,
>> subplot(131),imshow(I);
>> subplot(132),imshow(J);
>> subplot(133),imshow(K);

在这里插入图片描述

拉普拉斯算子对图像进行锐化滤波
>> I=imread('E:\persional\matlab\images\ba.tif');
>> I = im2double(I);
>> h = [0,1,0;1,-4,1;0,1,1];%拉普拉斯算子
>> J = conv2(I,h,'same');%卷积
>> K = I - J;
>> figure,
>> subplot(121),imshow(I);
>> subplot(122),imshow(K);

在这里插入图片描述

扫描二维码关注公众号,回复: 15368580 查看本文章

猜你喜欢

转载自blog.csdn.net/weixin_56260304/article/details/127345502