📄 y2fft.m
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%% 二维的Lena图像的傅立叶变换,并显示出变换后的Lena图像 %%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function Y2FFT()
f=imread('Lena.bmp');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%% 显示初始的图像 %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
imshow(f);
title '原始的Lena图像';
[wideth,height]=size(f);
y=zeros(wideth,height);
q=zeros(wideth,height);
for i=1:wideth
for j=1:height
y(i,j)=f(i,j);
end;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%% 进行行的傅立叶变换 %%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
temp=zeros(1,height);
for i=1:wideth
for j=1:height
temp(j)=y(i,j);
end;
temp=Y1FFT(temp,height);
for j=1:height
y(i,j)=temp(j);
end;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%% 进行列的傅立叶变换 %%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
temp=zeros(1,height);
for j=1:height
for i=1:wideth
temp(i)=y(i,j);
end;
temp=Y1FFT(temp,wideth);
for i=1:wideth
y(i,j)=temp(i);
end;
end;
% % % %% % % % % % % %% % % % % % % %% % % % % % % %% % % % % % % %% % % % % % % %% % % % % % % %% % % %
%%%%%%%%%%%%%%%%%% 将进行完傅立叶变换后的数值求其模,进行实数的转换 %%%%%%%%%%%%%%%%%%%%%%%
% % % %% % % % % % % %% % % % % % % %% % % % % % % %% % % % % % % %% % % % % % % %% % % % % % % %% % % %
[wideth,height]=size(f);
for i=1:1:wideth
for j=1:1:height
q(i,j)=abs((sqrt(real(y(i,j))*real(y(i,j))+imag(y(i,j))*imag(y(i,j))))/100);
if q(i,j)>255
q(i,j)=255;
end;
end;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% 调整图像的显示的中心 %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:1:height
for j=1:1:wideth
if(i>height/2)
i1=i-height/2;
else
i1=i+height/2;
end;
if(j>wideth/2)
j1=j-wideth/2;
else
j1=j+wideth/2;
end;
y1(i1,j1)=uint8(q(i,j)); %%%%%取整操作
end;
end;
figure,imshow(y1);
title '傅立叶变换后的Lena图像';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% 傅立叶反变换 %%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:wideth
for j=1:height
uu(i,j)=conj(y(i,j));
end;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%% 进行行的傅立叶反变换 %%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
temp2=zeros(1,height);
for i=1:wideth
for j=1:height
temp2(j)=uu(i,j);
end;
temp2=Y1FFT(temp2,height)/height;
for j=1:height
uu(i,j)=temp2(j);
end;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%% 进行列的傅立叶反变换 %%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
temp2=zeros(1,height);
for j=1:height
for i=1:wideth
temp2(i)=uu(i,j);
end;
temp2=Y1FFT(temp2,wideth)/wideth;
for i=1:wideth
uu(i,j)=conj(temp2(i));
end;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% for i=1:1:wideth
% for j=1:1:height
% uu(i,j)=abs((sqrt(real(uu(i,j))*real(uu(i,j))+imag(uu(i,j))*imag(uu(i,j))))/100);
% if uu(i,j)>255
% uu(i,j)=255;
% end;
% end;
% end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure, imshow(real(uint8(uu)));
title '进行反变换后的图像';
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -