A list,
Neighborhood averaging and median filtering belong to the category of spatial image smoothing.
Neighborhood averaging method is to take a neighborhood S for each pixel point of the original image F (x,y) containing noise and calculate the average of the gray level of all pixels in S as the pixel value of the processed image G (x,y), namely:
Median filtering is a kind of nonlinear processing technology. In fact, it is to determine a sliding window and take the median value of the window pixels as the pixel value of the processed image.
Ii. Source code
% neighborhood average method close all; clear all; clc; a=imread('lena.jpg');
subplot(231); imshow(a); title('original');
b1=imnoise(a,'salt & pepper');
subplot(232); imshow(b1); title('Add salt and pepper noise');
% b1=imnoise(a,'gaussian');
% subplot(232); imshow(b1); %title('Add gaussian noise');
[m1,n1]=size(a);
c1=b1;
for i=2:m1- 1
for j=2:n1- 1
s=b1(i- 1:i+1,j- 1:j+1);
end
end
subplot(234); imshow(c1); title('4 Neighborhood Filtering ');
c2=b1;
for i=2:m1- 1
for j=2:n1- 1
end
end
subplot(235); imshow(c2); title('8 Neighborhood Filtering ');
c3=b1;
for i=3:m1- 3
for j=3:n1- 3
s=b1(i2 -:i+2,j2 -:j+2);
end
end
subplot(236); imshow(c3); title('12 Neighborhood Filtering '); % median filter close all; clear all; clc a=imread('lena.jpg');
subplot(221); imshow(a); title('original');
b1=imnoise(a,'salt & pepper');
%b1=imnoise(a,'gaussian'); title('Add gaussian noise');
subplot(222); imshow(b1); title('Add salt and pepper noise');
[m1,n1]=size(a);
d1=b1;
for i=2:m1- 1
for j=2:n1- 1
s=b1(i- 1:i+1,j- 1:j+1);
s1=s(:);
Copy the code
3. Operation results
Fourth, note
Version: 2014 a