img=imread('lena.png');
img=rgb2gray(img)
img=im2double(img)%输入图像类型为uint8,将其转换为double类型进行运算
gau=imnoise(img,'gaussian');
subplot(2,2,1);imshow(gau);title('添加高斯噪声的图像');%imshow()函数在显示图像时会自动将类型转换为uint8
subplot(2,2,2);imshow(median_filter(gau,3));title('滤除高斯噪声后的图像');
salt=imnoise(img,'salt & pepper');
subplot(2,2,3);imshow(salt);title('添加椒盐噪声的图像');
subplot(2,2,4);imshow(median_filter(salt,3));title('滤除椒盐噪声后的图像');
%中值滤波,接受两个参数,一个参数是原图像x,另一个参数是滤波器大小n
function d=median_filter(x,n)
d=x;
[width,height]=size(x);%得到图像的长和宽
for ii=1:width-(n-1)
for jj=1:height-(n-1)%height表示的个数为可完整滤波的格子数
tmp1=d(ii:ii+(n-1),jj:jj+(n-1));%取出要滤波的n*n的方阵
tmp2=tmp1(1,:);
for kk=2:n
tmp2=[tmp2,tmp1(kk,:)];%把所有的行排成一行方便后面求中值
end
y= median(tmp2);
d(ii+(n-1)/2,jj+(n-1)/2)=y;
end
end
图像滤波代码_中值滤波matlab代码_源码.zip
版权申诉
93 浏览量
2021-12-31
19:16:29
上传
评论
收藏 567KB ZIP 举报
mYlEaVeiSmVp
- 粉丝: 1889
- 资源: 19万+
最新资源
- 一种改进的Goldstei...-InSAR干涉图滤波算法-于晓歆.pdf
- 陈慧琳 - 今生你作伴 [mqms2].mp3
- The Experiment 2 of Engineering Electromagnetics.pdf
- Engineering-Electromagnetic-Theory-Lab-4.pdf
- Engineering electromagnetic theory-1.docx
- The Experiment 4 of Engineering Electromagnetics.pdf
- Engineering-Electromagnetic-Theory-Lab-3.pdf
- The Experiment 3 of Engineering Electromagnetics.pdf
- Engineering electromagnetic theory-2.docx
- tensorflow-gpu-2.7.0-cp37-cp37m-manylinux2010-x86-64.whl
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈