2.基于3×3的模板,编写均值滤波的处理程序,处理含有加性高斯噪声和椒盐噪声的图像,观察处理结果
3.编写中值滤波程序,处理相同的图像与均值滤波进行比较;改变模板尺寸观察处理结果
4.编程实现利用一阶微分算子和二阶拉普拉斯算子进行图像锐化的程序
5.对比不同的邻域运算结果,体会图像锐化与图像平滑的区别
均值滤波处理含有椒盐噪声图像程序代码
(1):模板运算
f=imread();
f=double(f);
[row,col]=size(f);
r=1;
for i=2:row-1
for j=2:col-1
g(i,j)=(f(i-1,j-1)+f(i-1,j)+f(i-1,j+1)+f(i,j-1)+f(i,j)+f(i,j+1)+f(i+1,j-1)+f(i+1,j)+f(i+1,j+1))/9;
g=uint8(g);
end
end
subplot(121);
imshow(uint8(f));
title('椒盐噪声图像');
subplot(122);
imshow(g);
title('均值滤波处理后的图像')
(2):mean函数均值滤波
f=imread();
f=double(f);
[row,col]=size(f);
g=size(f);
for i=2:row-1
for j=2:col-1
t=f(i-1:i+1,j-1:j+1);
t=double(t);
g(i,j)=mean(mean(t));
g(i,j)=uint8(g(i,j));
end
end
subplot(121);
imshow(uint8(f));
title('椒盐噪声图像');
subplot(122);
imshow(uint8(g));
title('均值滤波处理后的图像')
(3)可变模板处理
f=imread();
f=double(f);
[row,col]=size(f);
r=1;
g=size(f);
for i=2:row-1
for j=2:col-1
s=0;
s=double(s);
for m=-r:r
for n=-r:r
s=s+f(i+m,j+n);
end
end
g(i,j)=s/power((r+2),2);
end
end
subplot(121);
imshow(uint8(f));
title('椒盐噪声图像');
subplot(122);
imshow(uint8(g));
title('均值滤波处理后的图像')
均值滤波处理含有加性高斯噪声图像程序代码
(1):模板运算
f=imread();
f=double(f);
[row,col]=size(f);
r=1;
for i=2:row-1
for j=2:col-1
g(i,j)=(f(i-1,j-1)+f(i-1,j)+f(i-1,j+1)+f(i,j-1)+f(i,j)+f(i,j+1)+f(i+1,j-1)+f(i+1,j)+f(i+1,j+1))/9;
g=uint8(g);
end
end
subplot(121);
imshow(uint8(f));
title('加性高斯噪声图像');
subplot(122);
imshow(g);
title('均值滤波处理后的图像')
(2):mean函数均值滤波
f=imread();
f=double(f);
[row,col]=size(f);
r=1;
g=size(f);
for i=2:row-1
for j=2:col-1
t=f(i-1:i+1,j-1:j+1);
t=double(t);
g(i,j)=mean(mean(t));
g(i,j)=uint8(g(i,j));
end
end
subplot(121);
imshow(uint8(f));
title('加性高斯噪声图像');
subplot(122);
imshow(uint8(g));
title('均值滤波处理后的图像')
(3):可变模板处理
f=imread();
f=double(f);
[row,col]=size(f);
r=1;
g=size(f);
for i=2:row-1
for j=2:col-1
s=0;
s=double(s);
for m=-r:r
for n=-r:r
s=s+f(i+m,j+n);
end
end
g(i,j)=s/power((r+2),2);
end
end
subplot(121);
imshow(uint8(f));
title('加性高斯噪声图像');
subplot(122);
imshow(uint8(g));
title('均值滤波处理后的图像')
中值滤波(椒盐噪声图像处理)
f=imread();
f=double(f);
[row,col]=size(f);
g=size(f);
r=1;
for i=r+1:row-r
for j=r+1:col-r
t=f(i-r:i+r,j-r:j+r);
id=0;
for tm=1:5
m=0;
for k=1:9
if(m id=k; end end t(id)=0; end g(i,j)=m; end end subplot(121); imshow(uint8(f)); title('原图像'); subplot(122); imshow(uint8(g)); title('中值滤波处理后的图像') R=1时的图像 R=5 中值滤波(加性高斯噪声) f=imread(); f=double(f); [row,col]=size(f); g=size(f); r=1; for i=r+1:row-r for j=r+1:col-r t=f(i-r:i+r,j-r:j+r); id=0; for tm=1:5 m=0; for k=1:9 if(m id=k; end end t(id)=0; end g(i,j)=m; end end subplot(121); imshow(uint8(f)); title('原图像'); subplot(122); imshow(uint8(g)); title('中值滤波处理后的图像') R=5 不同领域运算结果比较 r=2 f=imread(); f=double(f); [row,col]=size(f); r=2; g=size(f); for i=r+1:row-r for j=r+1:col-r s=0; s=double(s); for m=-r:r for n=-r:r s=s+f(i+m,j+n); end end g(i,j)=s/power((r+2),2); end end subplot(121); imshow(uint8(f)); title('椒盐噪声图像'); subplot(122); imshow(uint8(g)); title('均值滤波处理后的图像') R=3 R=8下载本文