程序目的:对有噪声的图片进行中值滤波去噪
输入:一张没有噪声的图像,进行加噪,得到一张有噪声的图像
输出:去除有噪声的图像
可直接调用中值滤波函数medfilt2,中值滤波对去椒盐噪声效果更好
a=imread('E:\matlab\other.program\PP.bmp');
% a=imnoise(a,'gaussian',0.02); %加高斯噪声
a=imnoise(a,'salt & pepper',0.02); %加椒盐噪声
g=medfilt2(a); %对有躁声的图像进行中值滤波
figure,
subplot(1,2,1),imshow(uint8(a));
subplot(1,2,2),imshow(uint8(g));
中值滤波原理性程序:
a=imread('E:\matlab\other.program\PP.bmp');
a=double(a);
[dep,wide]=size(a);
new_image=ones(size(a));
for i=3:dep-2
for j=3:wide-2
new_image(i,j)=median([a(i-2,j-2) a(i-2,j-1) a(i-2,j) a(i