用MATLAB进行中值滤波

怎么用MATLAB对一幅加了噪声的图象进行中值滤波,语句是怎么写的?急用,请大家帮忙!

b=medfilt2(a,[m,n]);
b是中值滤波后的图象矩阵,a是原图矩阵,m和n是处理模版大小,默认3×3。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-09-12
要先变成RGB灰度图像吧
I=rgb2gray(I);

已经跑出来了 你试下
I=imread('C:\image\lena2.jpg');
I=rgb2gray(I);
J=imnoise(I,'salt & pepper' ,0.02);
subplot(231);imshow(I);
subplot(232);imshow(J);
K1=medfilt2(J);
K2=medfilt2(J,[5 5]);
K3=medfilt2(J,[7 7]);
K4=medfilt2(J,[9 9]);
subplot(233);
imshow(K1);
subplot(234);
imshow(K2);
subplot(235);
imshow(K3);
subplot(236);
imshow(K4);