去除图片高斯噪声和椒盐噪声(图像处理)
最小值最大值中值均值滤波去除高斯噪声和椒盐噪声
#代码如下:
clear;clc;
f=imread(‘rice.png’);
f1=imnoise(f,‘gaussian’);
f2=imnoise(f,‘salt & pepper’,0.02);
[m,n]=size(f1);
g1=f1;
g2=f2;
mask=[1 1 1;1 1 1;1 1 1]/9;
for x=2:m-1
for y=2:n-1
subimage=double(f1(x-1:x+1,y-1:y+1));
temp=subimage.*mask;
g1(x,y)=round(sum(sum(temp)));
subimage2=double(f2(x-1:x+1,y-1:y+1));
temp2=subimage2.*mask;
g2(x,y)=round(sum(sum(temp2)));
end
end
g1=uint8(g1);
g2=uint8(g2);
subplot(221),imshow(f1);
subplot(222),imshow(f2);
subplot(223),imshow(g1);
subplot(224),imshow(g2);
clear;clc;
I=imread(‘rice.png’);
f1=imnoise(I,‘gaussian’);
f2=imnoise(I,‘salt & pepper’,0.02);
[m,n]=size(f1);
g1=f1;
g2=f2;
mask=[1 1 1 1 1;1 1 1 1 1;1 1 1 1 1;1 1 1 1 1;1 1 1 1 1]/25;
for x=3:m-2
for y=3:n-2
subimage=double(f1(x-2:x+2,y-2:y+2));
temp=subimage.*mask;
g1(x,y)=round(sum(sum(temp)));
subimage2=double(f2(x-2:x+2,y-2:y+2));
temp2=subimage2.*mask;
g2(x,y)=round(sum(sum(temp2)));
end
end
g1=uint8(g1);
g2=uint8(g2);
subplot(221),imshow(f1);
subplot(222),imshow(f2);
subplot(223),imshow(g1);
subplot(224),imshow(g2);
I = imread(‘pout.tif’);
f1=imnoise(I,‘gaussian’);
f2=imnoise(I,‘salt & pepper’,0.02);
[m,n] = size(I);
g1=f1;
g2=f2;
mask=[1 1 1 1 1;1 1 1 1 1;1 1 1 1 1;1 1 1 1 1;1 1 1 1 1 ]/25;
for x=3:m-2
for y=3:n-
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
