『壹』 求均值滤波和中值滤波算法的MATLAB代码
5*5的均值滤波代码
w2=fspecial('average',[5 5]); %% 先定义一个滤波器
h=imfilter(a,w2,'replicate'); %%让图像通过滤波器
imshow(h);
imwrite(h,'8.jpg');
中值的暂时还不会
『贰』 请教高手:我用数据采集卡采集到数据之后,需要在matlab中进行滤波去噪,有哪位知道怎么在matlab中实现
[N,Wc]=buttord()
%估算得到Butterworth低通滤波器的最小阶数N和3dB截止频率Wc
[a,b]=butter(N,Wc); %设计Butterworth低通滤波器
[h,f]=freqz(); %求数字低通滤波器的频率响应
figure(2); % 打开窗口2
subplot(221); %图形显示分割窗口
plot(f,abs(h)); %绘制Butterworth低通滤波器的幅频响应图
title(巴氏低通滤波器'');
grid; %绘制带网格的图像
sf=filter(a,b,s); %叠加函数S经过低通滤波器以后的新函数
subplot(222);
plot(t,sf); %绘制叠加函数S经过低通滤波器以后的时域图形
xlabel('时间 (seconds)');
ylabel('时间按幅度');
SF=fft(sf,256); %对叠加函数S经过低通滤波器以后的新函数进行256点的基—2快速傅立叶变换
w= %新信号角频率
subplot(223);
plot()); %绘制叠加函数S经过低通滤波器以后的频谱图
title('低通滤波后的频谱图');
%设计高通滤波器
[N,Wc]=buttord()
%估算得到Butterworth高通滤波器的最小阶数N和3dB截止频率Wc
[a,b]=butter(N,Wc,'high'); %设计Butterworth高通滤波器
[h,f]=freqz(); %求数字高通滤波器的频率响应
figure(3);
subplot(221);
plot()); %绘制Butterworth高通滤波器的幅频响应图
title('巴氏高通滤波器');
grid; %绘制带网格的图像
sf=filter(); %叠加函数S经过高通滤波器以后的新函数
subplot(222);
plot(t,sf); ;%绘制叠加函数S经过高通滤波器以后的时域图形
xlabel('Time(seconds)');
ylabel('Time waveform');
w; %新信号角频率
subplot(223);
plot()); %绘制叠加函数S经过高通滤波器以后的频谱图
title('高通滤波后的频谱图');
%设计带通滤波器
[N,Wc]=buttord([)
%估算得到Butterworth带通滤波器的最小阶数N和3dB截止频率Wc
[a,b]=butter(N,Wc); %设计Butterworth带通滤波器
[h,f]=freqz(); %求数字带通滤波器的频率响应
figure(4);
subplot(221);
plot(f,abs(h)); %绘制Butterworth带通滤波器的幅频响应图
title('butter bandpass filter');
grid; %绘制带网格的图像
sf=filter(a,b,s); %叠加函数S经过带通滤波器以后的新函数
subplot(222);
plot(t,sf); %绘制叠加函数S经过带通滤波器以后的时域图形
xlabel('Time(seconds)');
ylabel('Time waveform');
SF=fft(); %对叠加函数S经过带通滤波器以后的新函数进行256点的基—2快速傅立叶变换
w=( %新信号角频率
subplot(223);
plot(')); %绘制叠加函数S经过带通滤波器以后的频谱图
title('带通滤波后的频谱图');
『叁』 matlab图像去噪
你是要用什么滤波器呢 ,我这里有一个程序,用均值和中值两种方法:
g=imread('E:\1.jpg'); %读入图像的具体位置,
v=imnoise(g,'salt & pepper',0.1);
subplot(2,2,1);
imshow(g)
title('orginal image');
subplot(2,2,2);
imshow(v)
title('noise image');
[h,w]=size(v);
n=9;
f=double(v);
a=ones(n,n);
y=f;
for i=1:h-n+1
for j=1:w-n+1
a=f(i:i+(n-1),j:j+(n-1));
s=sum(sum(a));
y(i+(n-1)/2,j+(n-1)/2)=s/(n*n);
end
end
subplot(2,2,3);
imshow(uint8(y))
title('noise rection by average filter');
x=f;
for i=1:h-n+1
for j=1:w-n+1
c=f(i:i+(n-1),j:j+(n-1));
e=c(1,:);
for u=2:n
e=[e,c(u,:)];
end
mm=median(e);
x (i+(n-1)/2,j+(n-1)/2)=mm;
end
end
subplot(2,2,4);
imshow(uint8(x))
title('noise rection by median filter');
『肆』 编写用均值滤波去噪的matlab程序,用两种方法实现.(重谢)
方法一:filter2
clearall;
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);
uint8Y=zeros(M,N);
funBox=zeros(3,3);
fori=1:M-3
forj=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('均值滤波');
实现图: