滤波

线性平均滤波:

4邻域:

close all;
clear all;
clc;
I=imread('coins.jpg');
J=imnoise(I,'salt&pepper',0.02);  %添加椒盐噪声
h=ones(3,3)/5;     %建立4邻域模板
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);

8邻域:

close all;
clear all;
clc;
I=imread('coins.png');
I=im2double(I);
J=imnoise(I,'salt&pepper',0.02);  %添加椒盐噪声
h=ones(3,3)/9;     %建立8邻域模板
K=conv2(J,h);  %滤波
figure;
subplot(131);imshow(I);
subplot(132);imshow(J);
subplot(133);imshow(K);
原文地址:https://www.cnblogs.com/sheropan/p/5040303.html