Median filter

10 15 20
23 90 27
33 31 30
sor-> 10 15 20 23 27 30 31 33 90
replace
10 15 20
23 27 27
33 31 30
Median filter is smooth nicer

pkg load image;

img = imread('moon.png');
imshow(img);

%% Add salt & pepper noise
noisy_img = imnoise(img, 'salt & pepper', 0.02);
imshow(noisy_img);

median_filtered = medfilt2(noisy_img);
imshow(median_filtered);