function gausHighpassFilter
img=imread('lena.bmp');
figure(1);
imshow(img);
title('原始图像');
threshholdValue=80;
% 图像的高度和宽度(不一定为2的整数次幂)
[nHeight nWidth]=size(img);
% 计算进行傅立叶变换的高度(2的整数次幂)
dTmpOne=log(nHeight)/log(2);
nYLev=ceil(dTmpOne);% y(列)方向上的迭代次数
nTransHeight=power(2,nYLev);
% 计算进行傅立叶变换的宽度(2的整数次幂)
dTmpOne=log(nWidth)/log(2);
nXLev=ceil(dTmpOne);% x(行)方向上的迭代次数
nTransWidth=power(2,nXLev);
% 把空余的地方补零
X=img;
if nHeight~=nTransHeight
for i=1:(nTransHeight-nHeight)
X=[X;zeros(1,nWidth)];
end
end
if nWidth~=nTransWidth
for i=1:(nTransWidth-nWidth)
X=[X zeros(nTransHeight,1)];
end
end
% change the transformation center to the center of the picture
for i=1:nTransHeight
for j=1:nTransWidth
X(i,j)=X(i,j)*power(-1,i+j);
end
end
F=fft2(double(X)); % to implement the FFT transformation
F1=fftshift(F);
figure(2);
%imshow (F);
imshow(log(1+abs(F1)),[]);
title('傅立叶变换');
% to implement the gaussLowPassFiltering
tempImag=F;
denominator=2*(threshholdValue.^2);
biM=nTransHeight/2;
biN=nTransWidth/2;
for i=1:nTransHeight
for j=1:nTransWidth
H=1-exp(-((i-biM).^2+(j-biN).^2)/denominator);
tempImag(i,j)=tempImag(i,j)*H;
end
end
Fc=ifft2(tempImag); % to implement the IFFT transformation
% reverse change the center of the transformation center
for i=1:nTransHeight
for j=1:nTransWidth
Fc(i,j)=Fc(i,j)*power(-1,i+j);
end
end
Fc=Fc(1:nHeight,1:nWidth);% to get the initial size of the picture
figure(3)
imshow (uint8(Fc));title('高斯高通滤波后图像');
评论0