利用matlab编写的Butterworth低通滤波程序

来源:互联网 发布:音乐的发展历程知乎 编辑:程序博客网 时间:2024/05/22 12:36

clear all;

close all;

P=input('inputimage data:');

d=size(P);

if(d(3)>1)

    P=rgb2gray(P);

end

subplot(131);imshow(P);

title('原始图像');

P1=imnoise(P,'salt& pepper',0.02);

subplot(132)

imshow (P1);

title('加入椒盐噪声后的图像');

f=double(P1);

g=fft2(f);%傅里叶变换

g=fftshift(g);%转换数据矩阵fftshift是针对频域的,将FFTDC分量移到频谱中心
即对频域的图像,

 [M,N]=size(g);

D0=input('inputnonnegative dhreshold D0=');

n=input('input theorder of filtering n=');

n1=fix(M/2);

n2= fix(N/2);

for i=1:M

    for j=1:N

        d=sqrt((i-n1)^2+(j-n2)^2);

h=1/(1+(d/D0)^(2*n));

        result(i,j)=h*g(i,j);

    end

end

result=ifftshift(result);

X2=ifft2(result);

X3=uint8(real(X2));

subplot(133)

imshow (X3);

title('Butterworth低通滤波所得图像');