图像噪声的抑制18103317.docx
《图像噪声的抑制18103317.docx》由会员分享,可在线阅读,更多相关《图像噪声的抑制18103317.docx(12页珍藏版)》请在冰豆网上搜索。
![图像噪声的抑制18103317.docx](https://file1.bdocx.com/fileroot1/2023-7/2/c2f16e37-0749-4ca9-a4a6-a27969bc3781/c2f16e37-0749-4ca9-a4a6-a27969bc37811.gif)
图像噪声的抑制18103317
实验内容
专业:
电子信息工程
学号:
18103317
实验要求:
1、掌握以上噪声抑制的基本算法。
2、读出图像rice.png,分别加椒盐噪声和高斯噪声,得到两幅带有噪声的图像。
I=imread('rice.png');
figure,imshow(I);
J1=imnoise(I,'gaussian',0,0.02);
figure,imshow(J1);
J2=imnoise(I,'salt&pepper',0.05);
figure,imshow(J2);
3、分别两幅图像进行均值滤波(使用
)和中值滤波,比较实验结果。
《一》对有高斯噪声图像进行滤波
(1)对有高斯噪声的图像进行均值滤波:
I=imread('rice.png');
J1=imnoise(I,'gaussian',0,0.02);
K=double(J1);
[mn]=size(K);
b=K;
forx=2:
m-1
fory=2:
n-1
s=0;
Xin=[K(x-1,y-1),K(x,y-1),K(x+1,y-1),K(x-1,y),K(x,y),K(x+1,y),K(x-1,y+1),K(x,y+1),K(x+1,y+1)];
forz=1:
9
s=s+xin(z);
end
b(x,y)=s/9;
end
end
figure,imshow(J1);title('滤波之前(加高斯噪声)');
figure,imshow(uint8(b));title('采用均值滤波后');
(2)对有高斯噪声的图像进行中值滤波:
clear,clc;
I=imread('rice.png');
J1=imnoise(I,'gaussian',0,0.02);
K=double(J1);
[mn]=size(K);
f=K;
forx=2:
m-1
fory=2:
n-1
a=0;
a=[K(x-1,y-1),K(x,y-1),K(x+1,y-1),K(x-1,y),K(x,y),K(x+1,y),K(x-1,y+1),K(x,y+1),K(x+1,y+1)];
b=0;
c=0;
forz=1:
8;
b=a(z);
c=z;
forzz=z+1:
9
ifa(zz)
b=a(zz);
c=zz;
end
end
a(c)=a(z);
a(z)=b;
end
f(x,y)=a(5);
end
end
figure,imshow(J1);title('中值滤波之前');
figure,imshow(uint8(f));title('中值滤波之后');
《二》对有椒盐噪声图像进行滤波
(1)对有椒盐噪声的图像进行均值滤波
I=imread('rice.png');
J1=imnoise(I,'salt&pepper',0.02);
K=double(J1);
[mn]=size(K);
b=K;
forx=2:
m-1
fory=2:
n-1
s=0;
xin=[K(x-1,y-1),K(x,y-1),K(x+1,y-1),K(x-1,y),K(x,y),K(x+1,y),K(x-1,y+1),K(x,y+1),K(x+1,y+1)];
forz=1:
9
s=s+xin(z);
end
b(x,y)=s/9;
end
end
figure,imshow(J1);title('滤波之前(加高斯噪声)');
figure,imshow(uint8(b));title('采用均值滤波后');
(2) 对有椒盐噪声的图像进行种植滤波
I=imread('rice.png');
J1=imnoise(I,'salt&pepper',0.02);
K=double(J1);
[mn]=size(K);
f=K;
forx=2:
m-1
fory=2:
n-1
a=0;
a=[K(x-1,y-1),K(x,y-1),K(x+1,y-1),K(x-1,y),K(x,y),K(x+1,y),K(x-1,y+1),K(x,y+1),K(x+1,y+1)];
b=0;
c=0;
forz=1:
8;
b=a(z);
c=z;
forzz=z+1:
9
ifa(zz)
b=a(zz);
c=zz;
end
end
a(c)=a(z);
a(z)=b;
end
f(x,y)=a(5);
end
end
figure,imshow(J1);title('中值滤波之前');
figure,imshow(uint8(f));title('中值滤波之后');