当前位置:首页 > 代码 > 正文

matlab均值滤波代码(用matlab中值滤波和均值滤波)

admin 发布:2022-12-19 18:04 143


本篇文章给大家谈谈matlab均值滤波代码,以及用matlab中值滤波和均值滤波对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

用MATLAB编程实现均值滤波算法?

1:smoothingAverageFilterMain.mclc;clear;fid = fopen('lenai.raw');temp= fread(fid, [256,256]);LenaRaw=uint8(temp');subplot(1,2,1) Imshow(LenaRaw);title('原始图像')subplot(1,2,2) Imshow(smoothingAverageFilter(LenaRaw,3));title('自制函数,使用用3*3模板,均值滤波图像')2:smoothingAverageFilter.mfunction returnData=smoothingAverageFilter(arg,arg2)[Iwidth,Ilength]=size(arg);temp=double(arg);returnData=zeros(Iwidth,Ilength);totalLength=arg2*arg2;for i=1:Iwidth-arg2+1 for j=1:Ilength-arg2+1 % temp(i,j)=average(arg(i:i+arg2,j:j+arg2)); sum=0.0; for n=1:arg2 for k=1:arg2 sum=sum+temp(i+n-1,j+k-1); end end returnData(i,j)=sum/totalLength; endendreturnData=uint8(returnData);end

怎样用MATLAB实现中值和均值滤波

中值滤波楼上答了,5*5的均值滤波代码 w2=fspecial('average',[5 5]); %% 先定义一个滤波器 h=imfilter(a,w2,'replicate'); %%让图像通过滤波器 imshow(h); imwrite(h,'8.jpg');

均值滤波是

I=medfilt2(a,[3 3],'symmetric')

可以在matlab中查询medfilt函数的用法,本例是使用3*3的滤波器采用镜像边界法做均值滤波。

编写用均值滤波去噪的matlab程序,用两种方法实现.(重谢)

方法一:filter2

clear all;

I=imread('lena.bmp');

%读入预处理图像

imshow(I)

%显示预处理图像

K1=filter2(fspecial('average',3),I)/255;

%进行3*3均值滤波

K2=filter2(fspecial('average',5),I)/255;

%进行5*5均值滤波

K3=filter2(fspecial('average',7),I)/255;

%进行7*7均值滤波

figure,imshow(K1)

figure,imshow(K2)

figure,imshow(K3)

方法二:双循环语句,移动平均法

%均值滤波

clc,clear;

f=imread('lena.bmp');

subplot(121),imshow(f),title('原图');

f1=imnoise(f,'gaussian',0.002,0.0008);

%subplot(222),imshow(f1),title('添加高斯噪声图');

k1=floor(3/2)+1;

k2=floor(3/2)+1;

X=f1;

[M,N]=size(X);

uint8 Y=zeros(M,N);

funBox=zeros(3,3);

for i=1:M-3

for j=1:N-3

funBox=X(i:i+3,j:j+3);

s=sum(funBox(:));

h=s/9;

Y(i+k1,j+k2)=h;

end;

end;

Y=Y/255;

subplot(122),imshow(Y),title('均值滤波');

实现图:

关于matlab均值滤波代码和用matlab中值滤波和均值滤波的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/16607.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载