The window size of% is 5*5, please adjust it according to the needs of the screen.
clc
All closed;
Clear all;
win =[5 5];
img = imread(' salt pepper . BMP ');
Figure; imshow(img);
x=img(:,:, 1);
y=img(:,:,2);
z=img(:,:,3);
X = medfilt2(x,win);
Y = medfilt2(y,win);
Z = medfilt2(z,win);
new_img=cat(3,X,Y,Z);
Figure; im show(new _ img);