Matlab中值滤波代码
来源:互联网 发布:js前端解析excel 编辑:程序博客网 时间:2024/04/30 12:49
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
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
0 0
- Matlab中值滤波代码
- matlab中值滤波--medfilt2
- 中值滤波讲解-Matlab
- 中值滤波 matlab实现
- 中值滤波matlab
- matlab 中值滤波
- [图像]中值滤波(Matlab实现)
- MATLAB实现中值滤波算法
- 最大最小中值滤波 matlab
- MATLAB 图像 均值滤波 中值滤波
- 均值滤波、中值滤波的matlab实现
- 均值滤波、中值滤波的matlab实现
- 均值滤波、中值滤波的matlab实现
- 均值滤波、中值滤波的matlab实现
- 均值滤波、中值滤波【MATLAB】【图像处理】
- 均值滤波、中值滤波的matlab实现
- 均值滤波、中值滤波的matlab实现
- 均值滤波、中值滤波的matlab实现
- mac下安装伪分布hadoop2.6.0和hbase1.0.1.1
- matplotlib中ion()和ioff()的使用
- KMeans——之我见
- PAT:1005. Spell It Right
- 【NOIP2010提高组T4】引水入城-搜索+DP
- Matlab中值滤波代码
- Autocad提示产品许可证错误无法激活的解决办法
- c语言显示比赛的结果
- OpenCV常见算法实现(一)- 椒盐噪声
- hdu 5945 Fxx and game
- POJ 1989 贪心
- hdu5944(Fxx and string)
- poj 3737 UmBasketella(三分)
- 从Java视角理解系统结构(三)伪共享